Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Trying to use substring to find a reverse complement in DNA,

by johngg (Canon)
on Dec 06, 2015 at 00:16 UTC ( [id://1149486]=note: print w/replies, xml ) Need Help??


in reply to Trying to use substring to find a reverse complement in DNA,

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1149486]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-23 07:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found