go ahead... be a heretic PerlMonks

### Re^3: Perl regular expression for amino acid sequence

by !1 (Hermit)
 on Dec 01, 2004 at 20:37 UTC ( #411557=note: print w/replies, xml ) Need Help??

This solution is actually fairly wrong since it first attempts to take from the front instead of trying to shorten the match. Of course, this is if QGNNNG would be considered series of two valid amino acids, being QGN and NNG.

```my \$cur;
while (\$seq{\$k} =~ /([QGYN]{3,6})/g) {
\$cur = \$1;
pos(\$seq{\$k}) -= length(\$cur) - 1 and next if \$cur =~ /(.)\1\1/;
print "\n\$k";
print \$cur." begins at position ", (pos(\$seq{\$k})-length(\$s)) , "\n
+";
}

Replies are listed 'Best First'.
Re^4: Perl regular expression for amino acid sequence
by Roy Johnson (Monsignor) on Dec 01, 2004 at 20:53 UTC
The fix is something like:
```my \$cur;
while (\$seq{\$k} =~ /([QGYN]{3,6})/g) {
\$cur = \$1;
pos(\$seq{\$k}) -= length(\$cur);
\$cur =~ s/(.)\1\1.*/\$1\$1/;
if (length(\$cur) >= 3) {
pos(\$seq{\$k}) += length(\$cur);
}
else { ++pos(\$seq{\$k}); next }
print "\n\$k";
print \$cur." begins at position ", (pos(\$seq{\$k})-length(\$s)) , "\n
+";
}

Caution: Contents may have been coded under pressure.

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://411557]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2021-07-26 00:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?

No recent polls found

Notices?