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
            Best Practices for Single-Cell Sequencing Analysis
            by seqadmin



            While isolating and preparing single cells for sequencing was historically the bottleneck, recent technological advancements have shifted the challenge to data analysis. This highlights the rapidly evolving nature of single-cell sequencing. The inherent complexity of single-cell analysis has intensified with the surge in data volume and the incorporation of diverse and more complex datasets. This article explores the challenges in analysis, examines common pitfalls, offers...
            06-06-2024, 07:15 AM
          • seqadmin
            Latest Developments in Precision Medicine
            by seqadmin



            Technological advances have led to drastic improvements in the field of precision medicine, enabling more personalized approaches to treatment. This article explores four leading groups that are overcoming many of the challenges of genomic profiling and precision medicine through their innovative platforms and technologies.

            Somatic Genomics
            “We have such a tremendous amount of genetic diversity that exists within each of us, and not just between us as individuals,”...
            05-24-2024, 01:16 PM

          ad_right_rmr

          Collapse

          News

          Collapse

          Topics Statistics Last Post
          Started by seqadmin, Today, 08:58 AM
          0 responses
          8 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, Yesterday, 02:20 PM
          0 responses
          14 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 06-07-2024, 06:58 AM
          0 responses
          181 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 06-06-2024, 08:18 AM
          0 responses
          231 views
          0 likes
          Last Post seqadmin  
          Working...
          X