Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • lran2008
    Member
    • Apr 2013
    • 35

    how to split a fasta file according to a list of gene ID

    Hi ALL,

    I have a fasta file and I want to split it in two two fasta files according to a list of sequence names in a text file (one seq name per line). So those seqs which have a match with the sequences names can be output to one fasta file and the others in another file.

    Could anybody provide me a script or some programs to perform this work? There are some online tools, but it would take a large amount of time to upload my file.

    Thanks.
  • rhinoceros
    Senior Member
    • Apr 2013
    • 372

    #2
    If your sequences aren't split to multiple lines you can do this with grep. I think:

    grep -A 1 -f yourSeqIDFile.txt yourFastaFile.fasta > SeqsFromIDList.fasta
    grep -A 1 -v -f yourSeqIDFile.txt yourFastaFile.fasta > TheOtherSeqs.fasta

    might remember wrong..


    If you have QIIME, you can do this with filter_fasta.py..
    Last edited by rhinoceros; 08-13-2013, 08:56 AM.
    savetherhino.org

    Comment

    • kmcarr
      Senior Member
      • May 2008
      • 1181

      #3
      Here is a script I wrote a while back to almost do what you want. It takes as input a FASTA file, a text file with a list of sequence IDs (one per line) and a mode argument to include or exclude the IDs in your list from the output. You could simply run the script twice, once in each mode to get the two complementary outputs, or if you feel like it modify the code to generate two output files. As it works now output is written to STDOUT so you can only capture one output by redirecting STDOUT to a file.

      Code:
      Usage:
      
      % subSetFasta.pl -f <fastaFileName> -l <listFileName> -m [i or e]
      
      Example:
      
      % subSetFasta.pl -f mySeqs.fasta -l myList.txt -m i > inList.fasta
      % subSetFasta.pl -f mySeqs.fasta -l myList.txt -m e > notInList.fasta
      If you do not specify a -mode argument the script defaults to the 'include' mode.

      A note about ID matching: the script bases a match on the first non-white space delimited text on the defline. If your defline is:

      Code:
      >sequenceID sequence description follows
      The script will only attempt to match 'sequenceID' so make sure that is the text in list file.
      Attached Files
      Last edited by kmcarr; 08-13-2013, 10:16 AM. Reason: Add note about default mode.

      Comment

      • JohnN
        Member
        • Jan 2011
        • 31

        #4
        Originally posted by lran2008 View Post
        Hi ALL,

        I have a fasta file and I want to split it in two two fasta files according to a list of sequence names in a text file (one seq name per line). So those seqs which have a match with the sequences names can be output to one fasta file and the others in another file.

        Could anybody provide me a script or some programs to perform this work? There are some online tools, but it would take a large amount of time to upload my file.

        Thanks.
        Try this: https://code.google.com/p/nash-bioin...ta.pl&can=2&q=

        Hopefully it will do the job you need.

        J
        Last edited by JohnN; 08-13-2013, 10:19 AM. Reason: Wrong URL

        Comment

        • lran2008
          Member
          • Apr 2013
          • 35

          #5
          Originally posted by rhinoceros View Post
          If your sequences aren't split to multiple lines you can do this with grep. I think:

          grep -A 1 -f yourSeqIDFile.txt yourFastaFile.fasta > SeqsFromIDList.fasta
          grep -A 1 -v -f yourSeqIDFile.txt yourFastaFile.fasta > TheOtherSeqs.fasta

          might remember wrong..


          If you have QIIME, you can do this with filter_fasta.py..
          Thanks. The second command didn't work.

          Comment

          • lran2008
            Member
            • Apr 2013
            • 35

            #6
            Originally posted by kmcarr View Post
            Here is a script I wrote a while back to almost do what you want. It takes as input a FASTA file, a text file with a list of sequence IDs (one per line) and a mode argument to include or exclude the IDs in your list from the output. You could simply run the script twice, once in each mode to get the two complementary outputs, or if you feel like it modify the code to generate two output files. As it works now output is written to STDOUT so you can only capture one output by redirecting STDOUT to a file.

            Code:
            Usage:
            
            % subSetFasta.pl -f <fastaFileName> -l <listFileName> -m [i or e]
            
            Example:
            
            % subSetFasta.pl -f mySeqs.fasta -l myList.txt -m i > inList.fasta
            % subSetFasta.pl -f mySeqs.fasta -l myList.txt -m e > notInList.fasta
            If you do not specify a -mode argument the script defaults to the 'include' mode.

            A note about ID matching: the script bases a match on the first non-white space delimited text on the defline. If your defline is:

            Code:
            >sequenceID sequence description follows
            The script will only attempt to match 'sequenceID' so make sure that is the text in list file.
            Thanks very much. The script works perfectly!

            Comment

            • JamieHeather
              @jamimmunology
              • Nov 2012
              • 96

              #7
              In case anyone needed more alternatives, you can also use fastq_select.tcl which is bundled in with mira. This also got discussed in an earlier thread, which might be useful.

              Comment

              • maubp
                Peter (Biopython etc)
                • Jul 2009
                • 1544

                #8
                If you want a Galaxy solution, try this:


                Or this related but subtly different tool which pulls out the reads in the ID order given

                Comment

                • lran2008
                  Member
                  • Apr 2013
                  • 35

                  #9
                  Originally posted by maubp View Post
                  If you want a Galaxy solution, try this:


                  Or this related but subtly different tool which pulls out the reads in the ID order given
                  http://toolshed.g2.bx.psu.edu/view/p...q_select_by_id
                  This should work. I didn't try it,so I don't know whether it can output a fasta file for unmatched seq.

                  Comment

                  • maubp
                    Peter (Biopython etc)
                    • Jul 2009
                    • 1544

                    #10
                    Originally posted by lran2008 View Post
                    This should work. I didn't try it,so I don't know whether it can output a fasta file for unmatched seq.
                    Yes, my sequence filter tool can produce a FASTA file with matched IDs, a FASTA file with non-matching IDs, or both (two FASTA files):


                    There is a preview/mockup of the tool available to view within the Tool Shed which should help explain this.

                    Comment

                    Latest Articles

                    Collapse

                    • SEQadmin2
                      Proteomic Platforms: How to Choose the Right Analytical Strategy to Improve Detection and Clinical Applications
                      by SEQadmin2


                      Proteomics platforms are evolving rapidly, with advances in mass spectrometry and affinity-based approaches expanding what researchers can detect and at what scale. As the field moves toward deeper proteome coverage and clinical applications, scientists face an increasingly complex landscape of tools. This article will explore how researchers are navigating these choices to find the right platform for their work.

                      The systematic characterization of the human proteome has
                      ...
                      07-20-2026, 11:48 AM
                    • SEQadmin2
                      Advanced Sequencing Platforms Tackle Neuroscience’s Toughest Genomics Problems
                      by SEQadmin2



                      Genomics studies in neuroscience face a special challenge due to the brain’s complexity and scarcity of samples. Mapping changes in cell type and state using conventional next-generation sequencing methods remains challenging. Advances in technologies like single-cell sequencing, spatial transcriptomics, and long-read sequencing have opened the door to deeper studies of the brain and diseases like Alzheimer’s, amyotrophic lateral sclerosis (ALS), and schizophrenia.
                      ...
                      07-09-2026, 11:10 AM
                    • SEQadmin2
                      Cancer Drug Resistance: The Lingering Barrier to Rising Survival
                      by SEQadmin2



                      Cancer survival rates have significantly increased in the last few decades in the United States, reaching a combined 70% 5-year survival rate by 2021. Behind this number, there are years of research to find new therapies, drug targets, and early detection methods. But there is one core challenge that keeps slowing down these advances, and it’s about drug resistance.

                      There is no single reason why many patients don’t respond to treatment as expected. Cancer is...
                      07-08-2026, 05:17 AM

                    ad_right_rmr

                    Collapse

                    News

                    Collapse

                    Topics Statistics Last Post
                    Started by SEQadmin2, 07-24-2026, 12:17 PM
                    0 responses
                    16 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, 07-23-2026, 11:41 AM
                    0 responses
                    18 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, 07-20-2026, 11:10 AM
                    0 responses
                    24 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, 07-13-2026, 10:26 AM
                    0 responses
                    37 views
                    0 reactions
                    Last Post SEQadmin2  
                    Working...