Seqanswers Leaderboard Ad

Collapse

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
            Recent Advances in Sequencing Analysis Tools
            by seqadmin


            The sequencing world is rapidly changing due to declining costs, enhanced accuracies, and the advent of newer, cutting-edge instruments. Equally important to these developments are improvements in sequencing analysis, a process that converts vast amounts of raw data into a comprehensible and meaningful form. This complex task requires expertise and the right analysis tools. In this article, we highlight the progress and innovation in sequencing analysis by reviewing several of the...
            05-06-2024, 07:48 AM
          • seqadmin
            Essential Discoveries and Tools in Epitranscriptomics
            by seqadmin




            The field of epigenetics has traditionally concentrated more on DNA and how changes like methylation and phosphorylation of histones impact gene expression and regulation. However, our increased understanding of RNA modifications and their importance in cellular processes has led to a rise in epitranscriptomics research. “Epitranscriptomics brings together the concepts of epigenetics and gene expression,” explained Adrien Leger, PhD, Principal Research Scientist...
            04-22-2024, 07:01 AM

          ad_right_rmr

          Collapse

          News

          Collapse

          Topics Statistics Last Post
          Started by seqadmin, 05-14-2024, 07:03 AM
          0 responses
          15 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 05-10-2024, 06:35 AM
          0 responses
          37 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 05-09-2024, 02:46 PM
          0 responses
          46 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 05-07-2024, 06:57 AM
          0 responses
          39 views
          0 likes
          Last Post seqadmin  
          Working...
          X