Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lac302
    Member
    • Dec 2012
    • 64

    #1

    looking for a simple script to pull a subset of contigs from an assembly

    i'm sure this is a simple enough task but i'm just an end user no scripting experience at all.

    looking for a script to pull contigs listed in a .txt file from assembly.fa and output the results to a new .fa file

    any help would be much appreciated. thanks.
  • Monika_bioinf
    Junior Member
    • Sep 2011
    • 7

    #2
    Use seqtk subseq, https://github.com/lh3/seqtk

    Comment

    • GenoMax
      Senior Member
      • Feb 2008
      • 7142

      #3
      Just in case subseq does not work with fasta files here are other alternatives:

      http://www.biostars.org/p/2822/

      A perl one liner:

      Comment

      • JackieBadger
        Senior Member
        • Mar 2009
        • 385

        #4
        Out of curiosity, GenoMax, how does second perl function handle the searching of the sample name file?
        I wrote something similar under linux bash and it went bonkers with the RAM. I think the issue was that when ever it found an ID in the fasta file, it would then not remove this ID from the file containing the query IDs, and then start the search again from the start. Either way, my scripting abilities produced something that seemed unfeasible to execute on a large query ID file and large fasta file.

        Cheers,

        J

        Comment

        • lac302
          Member
          • Dec 2012
          • 64

          #5
          Thanks all!

          Comment

          • JohnN
            Member
            • Jan 2011
            • 31

            #6
            I wrote this a few years back.

            Comment

            • Richard Finney
              Senior Member
              • Feb 2009
              • 701

              #7
              awk 'BEGIN{while((getline x<ARGV[1])>0){a[i++]=x;}while((getline y<ARGV[2])>0){if(substr(y,0,1)==">"){m=0;for(j=0;j<i;j++){if(y==a[j])m=1;}}if(m==1)print y;}}' $1 $2


              $1 is match file
              $2 is fasta file

              Comment

              • GenoMax
                Senior Member
                • Feb 2008
                • 7142

                #8
                Originally posted by JackieBadger View Post
                Out of curiosity, GenoMax, how does second perl function handle the searching of the sample name file?
                I wrote something similar under linux bash and it went bonkers with the RAM. I think the issue was that when ever it found an ID in the fasta file, it would then not remove this ID from the file containing the query IDs, and then start the search again from the start. Either way, my scripting abilities produced something that seemed unfeasible to execute on a large query ID file and large fasta file.

                Cheers,

                J
                @JackieBadger: Second perl function is using -n and -e switches. -n wraps a while loop around the program while -p feeds the program value of $_ each time.

                A nice example that illustrates this (equivalent to unix 'cat' command)

                Code:
                $ perl -ne 'print $_' filename
                or
                Code:
                $ perl -ne 'print' filename
                Last edited by GenoMax; 02-08-2014, 06:05 PM.

                Comment

                • Birdman
                  Member
                  • Jan 2014
                  • 21

                  #9
                  This little BioPython script will nicely do the job:

                  Code:
                  from Bio import SeqIO
                  import sys
                  
                  #Usage: filter_fasta_per_ids.py input.fasta filter_ids.txt output.fasta
                  
                  input_file =sys.argv[1]
                  id_file =sys.argv[2]
                  output_file =sys.argv[3]
                  wanted = set(line.rstrip("\n").split(None,1)[0] for line in open(id_file))
                  print("Found %i unique identifiers in %s" % (len(wanted), id_file))
                  records = (r for r in SeqIO.parse(input_file, "fasta") if r.id in wanted)
                  count = SeqIO.write(records, output_file, "fasta")
                  print("Saved %i records from %s to %s" % (count, input_file, output_file))
                  if count < len(wanted):
                      print("Warning %i IDs not found in %s" % (len(wanted)-count, input_file))

                  Comment

                  Latest Articles

                  Collapse

                  • SEQadmin2
                    Multiomic Liquid Biopsy: What DNA/RNA Panels Reveal That DNA Alone Can’t
                    by SEQadmin2



                    Tumors contain complex mixtures of cell populations that evolve in response to treatment and host-specific factors. Tissue biopsies provide only static snapshots of a tumor’s state. But what if we could follow that evolution over time using a minimally invasive technique?

                    Liquid biopsies can detect tumor-derived material circulating in the bloodstream, providing a way to study treatment response, detect emerging resistance, and discover new biomarkers. Circulating
                    ...
                    10-14-2026, 09:55 AM
                  • SEQadmin2
                    New Genomics Technologies Take Aim at Long-Standing Limits
                    by SEQadmin2


                    Researchers using sequencing and genomics tools often have to make trade-offs. They can choose between speed or scale, short reads or long-range information, or targeted panels or a view of the whole transcriptome. New technologies that have been released this year are built to address those tough choices.

                    We asked six companies the same four questions to learn about their latest products. The new technologies bring a lot to the table, including rethinking sequencing
                    ...
                    09-28-2026, 10:25 AM

                  ad_right_rmr

                  Collapse

                  News

                  Collapse

                  Topics Statistics Last Post
                  Started by SEQadmin2, 10-22-2026, 11:13 AM
                  0 responses
                  31 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, 10-22-2026, 10:48 AM
                  0 responses
                  22 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, 10-15-2026, 10:52 AM
                  0 responses
                  39 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, 10-14-2026, 05:39 AM
                  0 responses
                  45 views
                  0 reactions
                  Last Post SEQadmin2  
                  Working...