I'm confused about what you want (update: please remember this is PerlMonks and not BioMonks), but a part of it seems to be a permutation of all the other middle, single-base possibilities given the one that is actually present. If so, maybe something like this:

c:\@Work\Perl\monks>perl -wMstrict -le "my $ppi_pm_seq = 'ACTGCCT'; ;; my $n = 3; ;; my $extraction = my ($before, $mid, $after) = $ppi_pm_seq =~ m{ \A (.{$n}) (.) (.{$n}) \z }xms; ;; die qq{no extraction from '$ppi_pm_seq'} unless $extraction; ;; my ($ppi_pm_id, $ppi_mm_id, $mpi_pm_id, $mpi_mm_id) = map qq{$before$_$after}, $mid, grep $_ ne $mid, qw(A T C G) ; ;; print qq{'$_'} for $ppi_pm_id, $ppi_mm_id, $mpi_pm_id, $mpi_mm_id; " 'ACTGCCT' 'ACTACCT' 'ACTTCCT' 'ACTCCCT'
Note that the  $ppi_pm_id permuted sequence is the same as the "input"  $ppi_pm_seq sequence (if that's what you want).

Update 1: Note also that the simpler  (.{$n}) (.) or  (.{n}) (.) expressions suffice if you can guarantee, as an initial step, that your input strings are only  A T C G characters. This can be as simple as (tested):

my $s = 'ATCGxTGAC'; my $foreign = $s =~ tr/ATCG//c; print qq{foreign character in '$s'} if $foreign;

Update 2: An interesting side note: If you have Perl version 5.10+ available, you can use the  (?-PARNO) relative recursive subpattern regex extension to (perhaps) simplify things a bit (tested):
    m{ \A (.{$n}) (.) ((?-3)) \z }xms;
in place of
    m{ \A (.{$n}) (.) (.{$n}) \z }xms;
(I rather doubt this alteration would speed things up significantly, but I've not done any testing; it's just a thought.)


Give a man a fish:  <%-{-{-{-<


In reply to Re: DNA Pattern Matching by AnomalousMonk
in thread DNA Pattern Matching by Speed_Freak

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.