Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7811841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:18:48+00:00 2026-06-02T04:18:48+00:00

I got a large sequence of genome and I need to split it into

  • 0

I got a large sequence of genome and I need to split it into small .txt files.

Sequence looks like this

>supercont1.1 of Geomyces destructans 20631-21
AGATTTTCTTAATAACTTGTTCAATGTGTGTTCAAATGATATGCCGTGATGTATGTAGCA
TAAACAGATGTAGTAGAAGAGTTTGCAGCAATCGTTGAGTAGTATTGCTTCTGTTGTTGG
>supercont1.2 of Geomyces destructans 20631-21
AGATTTTCTTAATAACTTGTTCAATGTGTGTTCAAATGATATGCCGTGATGTATGTAGCA
TAAACAGATGTAGTAGAAGAGTTTGCAGCAATCGTTGAGTAGTATTGCTTCTGTTGTTGG
TAAACAGATGTAGTAGAAGAGTTTGCAGCAATCGTTGAGTAGTATTGCTTCTGTTGTTGG
>supercont1.3 of Geomyces destructans 20631-21
AGATTTT (...)

And it should be splitted into small files with names: “1.1-Geomyces-destructans–20631-21”, “1.2-Geomyces…” fulfilled with genome data.

My code after @JimMischel help looks like:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace genom1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        string filter = "Textové soubory|*.txt|Soubory FASTA|*.fasta|Všechny soubory|*.*";

        private void doit_Click(object sender, EventArgs e)
        {
            bar.Value = 0;

            OpenFileDialog opf = new OpenFileDialog();

            // filter for choosing file types
            opf.Filter = filter;

            string lineo = "error"; // test

            if (opf.ShowDialog() == DialogResult.OK)
            {
                var lineCount = 0;
                using (var reader = File.OpenText(opf.FileName))
                {
                    while (reader.ReadLine() != null)
                    {
                        lineCount++;
                    }
                }

                bar.Maximum = lineCount;
                bar.Step = 1;

                FolderBrowserDialog fbd = new FolderBrowserDialog();

                fbd.Description = "Vyber složku, do které chceš rozdělit načtený soubor: \n\n" + opf.FileName; // dialog desc
                if (fbd.ShowDialog() == DialogResult.OK)
                {
                    List<string> lines = new List<string>();
                    foreach (var line in File.ReadLines(opf.FileName))
                    {
                        bar.PerformStep();

                        if (line[0] == '>')
                        {
                           if (lines.Count >= 0)
                            {
                                // write contents of lines list to file

                                //quicker replace for better file name
                                StringBuilder prep = new StringBuilder(line);
                                prep.Replace(">supercont", "");
                                prep.Replace("of", "");
                                prep.Replace(" ", "-");
                                lineo = prep.ToString();

                                // append or writeall? how to writeall lines without append?
                                //System.IO.File.WriteAllText(fbd.SelectedPath + "\\" + lineo + ".txt", lineo);
                                StreamWriter SW;
                                SW = File.AppendText(fbd.SelectedPath + "\\" + lineo + ".txt");

                                foreach (string s in lines)
                                    {
                                        SW.WriteLine(s);
                                    }

                                SW.Close();

                                // and clear the list.
                                lines.Clear();
                            }
                        }
                        lines.Add(line);
                    }
                    // here, do the last part
                    if (lines.Count >= 0)
                    {
                        // write contents of lines list to file.

                        /* starts being little buggy here...

                        StreamWriter SW;
                        SW = File.AppendText(fbd.SelectedPath + "\\" + lineo + ".txt");
                        foreach (string s in lines)
                        {
                            SW.WriteLine(s);
                        }
                        SW.Close();

                        */
                    }
                }

            }
        }

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T04:18:50+00:00Added an answer on June 2, 2026 at 4:18 am

    If the file is large enough to fit into memory, you can call File.ReadAllText to get it into a string. Then you go through and extract text between > characters. Something like:

    string s = File.ReadAllText("filename");
    int pos = s.IndexOf('>');
    while (pos != -1)
    {
        int newpos = s.IndexOf('>', pos+1);
        string text = s.Substring(pos+1, newpos - pos);
        // now write text to a file
    
        // update current position
        pos = newpos;
    }
    // here you'll have to handle the last part of the file specially.
    

    I assume you can figure out how to name the files correctly.

    If you can’t fit the entire file into memory, then you can read the file character-by-character or do some kind of buffering. The problem is easier if you know that the > is always at the start of a line. Then you can write:

    List<string> lines = new List<string>();
    foreach (var line in File.ReadLines("filename"))
    {
        if (line[0] == '>')
        {
            if (lines.Count > 0)
            {
                // write contents of lines list to file.
                // and clear the list.
                lines.Clear();
            }
        }
        lines.Add(line);
    }
    // here, do the last part
    if (lines.Count > 0)
    {
        // write contents of lines list to file.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got some large csv files that I need to import into IEnumerable (prob
So I've got a large amount of SQL data that looks basically like this:
I got a pretty large DB-Table that I need to split into smaller tables
I've got a large number of PHP files and lines that need to be
I've got a large table in a SQL Server 2005 database and I'd like
We've got this large application written in Delphi 5, and development is ongoing to
At work, we just got a large number exotic cellular devices that need to
So this one is a doozie; I've got a pretty large OpenGL solution, written
Ive got a large bunch of objects (potentially 1000's) which I need to store
I've got a large table (~10,000) and I need one column to take up

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.