Unconfigured Ad

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

    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
                  Proteomic Platforms: How to Choose the Right Analytical Strategy to Improve Detection and Clinical Applications
                  by SEQadmin2


                  Proteomics platforms are evolving rapidly, with advances in mass spectrometry and affinity-based approaches expanding what researchers can detect and at what scale. As the field moves toward deeper proteome coverage and clinical applications, scientists face an increasingly complex landscape of tools. This article will explore how researchers are navigating these choices to find the right platform for their work.

                  The systematic characterization of the human proteome has
                  ...
                  07-20-2026, 11:48 AM
                • SEQadmin2
                  Advanced Sequencing Platforms Tackle Neuroscience’s Toughest Genomics Problems
                  by SEQadmin2



                  Genomics studies in neuroscience face a special challenge due to the brain’s complexity and scarcity of samples. Mapping changes in cell type and state using conventional next-generation sequencing methods remains challenging. Advances in technologies like single-cell sequencing, spatial transcriptomics, and long-read sequencing have opened the door to deeper studies of the brain and diseases like Alzheimer’s, amyotrophic lateral sclerosis (ALS), and schizophrenia.
                  ...
                  07-09-2026, 11:10 AM
                • SEQadmin2
                  Cancer Drug Resistance: The Lingering Barrier to Rising Survival
                  by SEQadmin2



                  Cancer survival rates have significantly increased in the last few decades in the United States, reaching a combined 70% 5-year survival rate by 2021. Behind this number, there are years of research to find new therapies, drug targets, and early detection methods. But there is one core challenge that keeps slowing down these advances, and it’s about drug resistance.

                  There is no single reason why many patients don’t respond to treatment as expected. Cancer is...
                  07-08-2026, 05:17 AM

                ad_right_rmr

                Collapse

                News

                Collapse

                Topics Statistics Last Post
                Started by SEQadmin2, Yesterday, 12:17 PM
                0 responses
                13 views
                0 reactions
                Last Post SEQadmin2  
                Started by SEQadmin2, 07-23-2026, 11:41 AM
                0 responses
                14 views
                0 reactions
                Last Post SEQadmin2  
                Started by SEQadmin2, 07-20-2026, 11:10 AM
                0 responses
                23 views
                0 reactions
                Last Post SEQadmin2  
                Started by SEQadmin2, 07-13-2026, 10:26 AM
                0 responses
                37 views
                0 reactions
                Last Post SEQadmin2  
                Working...