I would recommend to use BioPerl for reading sequences. Even a simple format like FASTA has a few caveats and you make your life easier in the long run if you use those libraries.
This is the canonical way of readin sequences from a FASTA file:
use Bio::SeqIO; my $seqio_obj = Bio::SeqIO->new(-file => "sequence.fasta", -format => +"fasta" ); while (my $seq_obj = $seqio_obj->next_seq){ print "Sequence id: ".$seq_obj->display_id."\n"; print "Sequence: "$seq_obj->seq."\n"; }
An important question is whether you need both primer/adapters (forward and reverse) to match (presumably either side of a sequenced insert)? If so, you will also need to reverse-complement one of the primers or you have to check both in both orientations unless you are sequencing from the forward primer. To match and remove a string you can use s//. Here is a Perl one-liner that illsutrates how you can test if something matches and remove it at the same time:
perl -e '$s="get_rid_of_some_string";print "remaining string: $s\n" if + $s=~s/^get_rid_//;'
Just run the above line in a terminal to see it in action. It will reduce "get_rid_of_some_string" to "of_some_string" if "get_rid_" can be found (and removed) from teh beginning.
To remove anything before the pattern as well (e.g. any sequence before a primer), you can do it like this:
perl -e '$s="get_rid_of_some_string";print "remaining string: $s\n" if + $s=~s/^.*rid_//;'
This will have the same result as above but the pattern was just "rid_" and the regular expression says: remove everything from teh beginning of the string, optionally followed by some characters, then followed by "rid_", with nothing (i.e. just strip it off). Hope this helps to get you started.

In reply to Re: remove part of string (DNA) by tospo
in thread remove part of string (DNA) by Furor

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.