Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^2: merging dna sequences

by garyboyd (Acolyte)
on Nov 10, 2011 at 12:29 UTC ( [id://937362]=note: print w/replies, xml ) Need Help??


in reply to Re: merging dna sequences
in thread merging dna sequences

Thank you both for your solutions - would this still work for more than 2 strings?

Replies are listed 'Best First'.
Re^3: merging dna sequences
by MidLifeXis (Monsignor) on Nov 10, 2011 at 14:09 UTC

    Is f'(f'(A,B),C)) the same as F(A,B,C)? If so, then just run a loop on your array of strings, replacing the first two with the results if f'(A,B). By the time you are down to a single string left, you will have the same results as F(A,B,C,....).

    List::Util's reduce function can be helpful in implementing this.

    --MidLifeXis

      would this still work for more than 2 strings

      As long as the ambiguous bases are in distinct positions, yes.

      In the general case, you can then write:

      my @s = ( "AYGTACTAGACTACAGACTACAGACATCTACAGACTCATCAGCAGCATATTTA", "ACGTACTAGACTACAGACTACAGACATCTACAGACTCATCAGCAGCATATTKA", "ACGTACTAGWCTACAGACTACAGACATCTACAGACTCATCAGCAGCATATTTA", "ACGTACTAGACTACAGACTACAGMCATCTACAGACTCATCAGCAGCATATTTA", "ACGTACTAGACTACAGACTACAGACATCTACAGACTCATRAGCAGCATATTTA", # ... ); my $m = shift @s; for my $s (@s) { my $m_ = $m; $m_ =~ tr/ACGT/\0/c; my $s_ = $s; $s_ =~ tr/ACGT/\0/c; $m = $m ^ $m_ ^ $s ^ $s_ | $m_ & $s_; } say $m; # AYGTACTAGWCTACAGACTACAGMCATCTACAGACTCATRAGCAGCATATTKA ^ ^ ^ ^ ^

      (P.S., sorry — meant to reply to garyboyd... )

        Thanks Eliya that is now working perfectly!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-25 17:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found