Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • baika
    Member
    • Apr 2012
    • 12

    #1

    trimming FASTA file

    Hi All
    I have a multi-fasta file with approximately 2000 sequences of varying length that have different start and end regions. I need to trim all my sequences in a way that all the sequences start with “ATAGCCGGCACCCTGGT” and ends with “GGCCATATGAGTGGGCC”. Any script would be really helpful to remove bases upstream of ATAGCCGGCACCCTGGT and downstream of GGCCATATGAGTGGGCC so that all the sequences become of equal length, and have the same start and end.

    Thanks for your help

    Baika
  • krobison
    Senior Member
    • Nov 2007
    • 734

    #2
    Code:
    #!/usr/bin/perl
    use strict;
    use Bio::SeqIO;
    
    ## debugging/tuning left as exercise for student :-)
    
    my $reader=new Bio::SeqIO(-format=>'fasta',-file=>$ARGV[0]);
    my $writer=new Bio::SeqIO(-format=>'fasta',-file=>$ARGV[0]."trimmed");
    while (my $rec=$reader->next_seq)
    {
      ## works only on forward strand & 0 mismatches!!!!
       if ($seq->seq=~/(ATAGCCGGCACCCTGGT.*GGCCATATGAGTGGGCC)/i)
       {
       $rec->seq($1);  
       $writer->write_seq($rec);
      } 
      else
      {
         print STDERR "Could not find head and/or tail sequences for ",$seq->id,"\n";
       }
    }

    Comment

    • baika
      Member
      • Apr 2012
      • 12

      #3
      Thanks Krobison for the perl script. It gives an error-
      Global symbol "$seq" requires explicit package name at ../../Scripts/trim_fastaseq.pl line 12.
      Global symbol "$seq" requires explicit package name at ../../Scripts/trim_fastaseq.pl line 19.

      Baika
      Last edited by baika; 03-04-2013, 02:35 PM. Reason: wrong ID

      Comment

      • kmcarr
        Senior Member
        • May 2008
        • 1181

        #4
        Sorry baika; I was going to answer until I saw this line in Keith's code:

        ## debugging/tuning left as exercise for student :-)
        Keith, did you stick the bug in there on purpose?

        Comment

        • A_Morozov
          Member
          • Feb 2011
          • 40

          #5
          No fun, guys. Baika might be (and claims to be in introduction section) a non-bioniformatitian stuck with what is not his/her area of expertise. If you went to genomics/bioinformatics lab, you should at least learn some Perl/Python, but for now - seems like it should be $rec, not $seq under regexp (the scary thingy with // and lots of uppercase).

          Comment

          • kmcarr
            Senior Member
            • May 2008
            • 1181

            #6
            Originally posted by A_Morozov View Post
            No fun, guys. Baika might be (and claims to be in introduction section) a non-bioniformatitian stuck with what is not his/her area of expertise. If you went to genomics/bioinformatics lab, you should at least learn some Perl/Python, but for now - seems like it should be $rec, not $seq under regexp (the scary thingy with // and lots of uppercase).
            Oh, it was late and I was feeling a tad impish; I wasn't going to leave baika hanging long. Anyway the better solution is to change line #9, naming the first object $seq.

            Code:
            Change
            
            while (my $[COLOR="Red"]rec[/COLOR]=$reader->next_seq)
            
            to
            
            while (my $[COLOR="red"]seq[/COLOR]=$reader->next_seq)

            Comment

            • d1antho
              Member
              • Mar 2012
              • 15

              #7
              Not that it should make a difference, because it is unlikely to match in the middle of a sequence, but the the match operator should be bounded to the start and the end of the sequence read. But honestly I doubt it should make any difference at all

              So this
              Code:
              if ($seq->seq=~/(ATAGCCGGCACCCTGGT.*GGCCATATGAGTGGGCC)/i)
                 {
                 $rec->seq($1);  
                 $writer->write_seq($rec);
                }
              Should then be
              Code:
              if ($seq->seq=~/(^ATAGCCGGCACCCTGGT.*GGCCATATGAGTGGGCC$)/i)
                 {
                 $rec->seq($1);  
                 $writer->write_seq($rec);
                }

              Comment

              • baika
                Member
                • Apr 2012
                • 12

                #8
                finally working

                Thanks krobison for writing this script, and kmcarr for pointing out the error. After incorporating all your suggestions and help from my friend Robert, finally it is working.

                Thank you all

                baika

                Code:
                #!/usr/bin/perl -w
                
                #Usage: trim_fasta.pl YOUR_FASTA_FILE.fasta OUT_FILE_TRIMMED.FASTA
                
                use strict;
                use Bio::SeqIO;
                
                my $reader=new Bio::SeqIO(-format=>'fasta',-file=>$ARGV[0]);
                my $writer=new Bio::SeqIO(-format=>'fasta',-file=>">$ARGV[1]");
                while (my $seq=$reader->next_seq)
                {
                  ## works only on forward strand & 0 mismatches!!!!
                   if ($seq->seq=~/(CCAGTATTTGGTA.*AGTTGATAACTGGGAA)/i)
                   {
                   $seq->seq($1);  
                   $writer->write_seq($seq);
                  } 
                  else
                  {
                     print STDERR "Could not find head and/or tail sequences for ",$seq->id,"\n";
                   }
                }
                Last edited by baika; 03-05-2013, 11:04 AM. Reason: spelling mistake

                Comment

                Latest Articles

                Collapse

                • kinpict.com
                  Reply to 16S/ITS Profiling vs. Shotgun Metagenomics: What Changes in Your Workflow?
                  by kinpict.com
                  The part about this topic feels surprisingly grounded, and the details on the page is the bit that made me slow down. I’d keep <a href="https://kinpict.com/">ai family photo generator</a> bookmarked for later.
                  Today, 06:37 PM
                • SEQadmin2
                  16S/ITS Profiling vs. Shotgun Metagenomics: What Changes in Your Workflow?
                  by SEQadmin2





                  NGS has revolutionized clinical microbiology by offering new ways to identify and surveil pathogens without prior knowledge of the target. One popular approach is 16S rRNA and ITS amplicon sequencing, which targets specific microbial markers. But studies are increasingly incorporating shotgun metagenomics, a technique that sequences all DNA from a sample without targeting specific microbial markers. This approach allows more detailed taxonomic classification,...
                  10-30-2026, 06:46 AM

                ad_right_rmr

                Collapse

                News

                Collapse

                Topics Statistics Last Post
                Started by SEQadmin2, 11-12-2026, 07:59 AM
                0 responses
                27 views
                0 reactions
                Last Post SEQadmin2  
                Started by SEQadmin2, 11-05-2026, 09:25 AM
                0 responses
                35 views
                0 reactions
                Last Post SEQadmin2  
                Started by SEQadmin2, 11-03-2026, 11:54 AM
                2 responses
                56 views
                0 reactions
                Last Post kinpict.com  
                Started by SEQadmin2, 10-28-2026, 09:57 AM
                0 responses
                175 views
                0 reactions
                Last Post SEQadmin2  
                Working...