$syb =~ s/(at{3,6})/\U$1/gi;
$syb =~ s/(aat{2,5})/\U$1/gi;
$syb =~ s/(aaat{1,4})/\U$1/gi;
$syb =~ s/(aaaat{0,3})/\U$1/gi;
$syb =~ s/(aaaaat{0,2})/\U$1/gi;
$syb =~ s/(a{4,7})/\U$1/gi;
$syb =~ s/(aaaaaat)/\U$1/gi;
$syb =~ s/(t{4,7})/\U$1/gi;
Is there any way I could get all these regexps into one? Is it bad practice to use this many regexps on the same string? the end result should if $syb is aaatcgacgatcgatcaatttcgaaaaaggattttttatgcacgcacggggattaaaa
the regexp should make it
AAATcgacgatcgatcAATTTcgAAAAAggATTTTTTatgcacgcacggggattAAAA
one problem with my regexps is that they match aaaatttt
as two separate matches and output AAAATTTT
. i need to fix this as well.
i have a string of A's C's T's and G's stored in $syb. i want to capitalize any part of the string that has a set of A's followed by T's, just A's or just T's (T's followed by A's should not) and the capitalized section may be no shorter than 4 and no longer than 7
This is a tough one. I think this might work:
s/((?<!a)a|(?<!a|t)t)((?<!t)\1|t){3,6}(?!\2|t)/\U$&/gi
Essentially, what I'm doing is:
a
not preceded by an a
. Or a t
not preceded by an a
or t
.
((?<!a)a|(?<!a|t)t)
t's
not preceded by a t
((?<!t)\1|t){3,6}
t
.
(?!\2|t)/
And the perl code:
$syb = "aaatcgacgatcgatcaatttcgaaaaaggattttttatgcacgcacggggattaaaaactgaaaattttactgaaaaaaaasttttttts";
$syb =~ s/((?<!a)a|(?<!a|t)t)((?<!t)\1|t){3,6}(?!\2|t)/\U$&/gi;
print $syb;
Edit taking a queue from qtax I've removed capturing groups from mine and chars from his:
s/(?:(?<!a)a|(?<!a|t)t)(?:(?<!t)a|t){3,6}(?!(?<=a)a|t)/\U$&/gi
Edit: reducing the regex by 5 chars.
s/(?<!a|t(?=t))(?:a|t(?!a)){3,6}(?:a(?!a)|t)(?!t)/\U$&/gi
with commments
s/
# Look behind for a char not an 'a' nor a 't' followed by a 't'
(?<!a|t(?=t))
# Capture 3-6 'a's or 't's not followed by 'a's
(?:a|t(?!a)){3,6}
# Capture an 'a' not followed by an 'a', or a 't'
(?:a(?!a)|t)
#make sure none of this is followed by a 't'.
(?!t)
/\U$&/gix;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With