I noticed that if your regular expression has an OR condition (for example, /(K..K)|(V.AK)/gi ), then the created array may contain undefined elements, which are included in the number at the end.
For example:
my $seq = "TSYCSKSNKRCRRKYGDDDDWWRSQYTTYCSCYTGKSGKTKGGDSCDAYYEAYGKSGKTKGGRNNR"; my $regex = '(K..K)|(V.AK)'; my $count = () = $seq =~ /$regex/gi; print "$count\n";
Gives a counter value of 6.
I found a solution in this post. How do I remove all undefs from an array?
my $seq = "TSYCSKSNKRCRRKYGDDDDWWRSQYTTYCSCYTGKSGKTKGGDSCDAYYEAYGKSGKTKGGRNNR"; my $regex = '(K..K)|(V.AK)'; my @count = $seq =~ /$regex/gi; @count = grep defined, @count; my $count = scalar @count; print "$count\n";
Which then gives the correct answer of the three.
Alastair Skeffington Apr 02 '19 at 14:41 2019-04-02 14:41
source share