Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Filter multi-fasta by length

    Hi everyone,

    I'd like to filter a multi-fasta file by length, for example, keep length <300bp and filter out longer ones. I knew there is tool in Galaxy doing this, but it takes so long to upload the file. Can anyone share a script or tool to me?

    Thank you very much.

  • #2
    See this thread for script examples: http://seqanswers.com/forums/showthread.php?t=13966

    Comment


    • #3
      Originally posted by hchang10 View Post
      Hi everyone,

      I'd like to filter a multi-fasta file by length, for example, keep length <300bp and filter out longer ones. I knew there is tool in Galaxy doing this, but it takes so long to upload the file. Can anyone share a script or tool to me?

      Thank you very much.
      Hi- This strategy should be quite fast (untested):

      Code:
      samtools faidx myfasta.fa
      awk '{if($2 < 300) print $1 "\t0\t" $2 "\t" $1}' myfasta.fa.fai > selectSeq.bed
      fastaFromBed -fi myfasta.fa -bed selectSeq.bed -name -fo  selectSeq.fa
      fastaFromBed is part of bedtools

      Dario

      Comment


      • #4
        Awesome!!!

        Dario, I appreciate it!!!!

        Thank you so much!!!!

        Comment


        • #5
          Also, a BioPython solution. In this case filtering my length 200nt

          Code:
          #!/usr/bin/python
          from Bio import SeqIO
          import sys
          import os
          
          #usage: python long.seq.py in.fasta out.fasta 200
          
          input_seq_iterator = SeqIO.parse(open(sys.argv[1], "rU"), "fasta")
          short_seq_iterator = (record for record in input_seq_iterator \
                                if len(record.seq) > int(sys.argv[3]))
          
          output_handle = open(sys.argv[2], "w")
          SeqIO.write(short_seq_iterator, output_handle, "fasta")
          output_handle.close()

          Comment

          Latest Articles

          Collapse

          • seqadmin
            Advanced Methods for the Detection of Infectious Disease
            by seqadmin




            The recent pandemic caused worldwide health, economic, and social disruptions with its reverberations still felt today. A key takeaway from this event is the need for accurate and accessible tools for detecting and tracking infectious diseases. Timely identification is essential for early intervention, managing outbreaks, and preventing their spread. This article reviews several valuable tools employed in the detection and surveillance of infectious diseases.
            ...
            Yesterday, 01:15 PM
          • seqadmin
            Strategies for Investigating the Microbiome
            by seqadmin




            Microbiome research has led to the discovery of important connections to human and environmental health. Sequencing has become a core investigational tool in microbiome research, a subject that we covered during a recent webinar. Our expert speakers shared a number of advancements including improved experimental workflows, research involving transmission dynamics, and invaluable analysis resources. This article recaps their informative presentations, offering insights...
            11-09-2023, 07:02 AM

          ad_right_rmr

          Collapse

          News

          Collapse

          Topics Statistics Last Post
          Started by seqadmin, Yesterday, 08:12 AM
          0 responses
          15 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 11-22-2023, 09:29 AM
          1 response
          51 views
          0 likes
          Last Post VilliamPast  
          Started by seqadmin, 11-22-2023, 08:53 AM
          0 responses
          57 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 11-21-2023, 08:24 AM
          0 responses
          31 views
          0 likes
          Last Post seqadmin  
          Working...
          X