in reply to Finding Start/End Position of the Uppercase Substring
use strict; use warnings; my @strings = qw{ ccaatTTTGACACACACAGAAgggca --aatTTTGACACACACAGAAgggca --aatTTTGACACACACAGAA ---aagctaagattca TTTGACACACACAGAAgggca ---TTTGACACACACAGAAgggca }; foreach my $string ( @strings ) { my ($sp, $ep) = ucRange($string); print qq{ String - $string\n}, qq{Start position - $sp\n}, qq{ End position - $ep\n\n}; } sub ucRange { local our $str = shift; $str =~ s{\A-*}{_}; local our $startPos = 0; $str =~ m{(?<=[a-z_])(?=[A-Z])(?{$startPos = pos $str})}; local our $endPos = 0; $str =~ m{(?<=[A-Z])(?=[A-Z](?:[a-z]|\z))(?{$endPos = pos $str})}; return ($startPos, $endPos); }
The output.
String - ccaatTTTGACACACACAGAAgggca Start position - 6 End position - 21 String - --aatTTTGACACACACAGAAgggca Start position - 4 End position - 19 String - --aatTTTGACACACACAGAA Start position - 4 End position - 19 String - ---aagctaagattca Start position - 0 End position - 0 String - TTTGACACACACAGAAgggca Start position - 1 End position - 16 String - ---TTTGACACACACAGAAgggca Start position - 1 End position - 16
I hope this is of interest.
Cheers,
JohnGG
Update: Added string with no uppercase to check that script handled that.
|
|---|