Rather than the series of if { ... } elsif { ... } ... tests you could use a hash table to look up the base and use it as the fourth argument to substr to replace the original.
$ perl -Mstrict -Mwarnings -E ' my $dna = q{AAGGTTCC}; my %compLU = ( A => q{T}, T => q{U}, G => q{C}, C => q{G}, ); my $complement = $dna; for my $idx ( 0 .. length( $complement ) - 1 ) { substr $complement, $idx, 1, $compLU{ substr $complement, $idx, 1 +}; } say $dna; say $complement;' AAGGTTCC TTCCUUGG $
I hope this is of interest.
Cheers,
JohnGG
In reply to Re: Trying to use substring to find a reverse complement in DNA,
by johngg
in thread Trying to use substring to find a reverse complement in DNA,
by tryingnottofailmytes
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |