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

                • 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-15-2026, 10:52 AM
                0 responses
                21 views
                0 reactions
                Last Post SEQadmin2  
                Started by SEQadmin2, 10-14-2026, 05:39 AM
                0 responses
                26 views
                0 reactions
                Last Post SEQadmin2  
                Started by SEQadmin2, 10-13-2026, 09:56 AM
                0 responses
                22 views
                0 reactions
                Last Post SEQadmin2  
                Started by SEQadmin2, 10-09-2026, 11:14 AM
                0 responses
                28 views
                0 reactions
                Last Post SEQadmin2  
                Working...