Created
October 19, 2012 17:56
-
-
Save moritz/3919636 to your computer and use it in GitHub Desktop.
Finding a Most Likely Common Ancestor (Perl 6)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# solution to http://rosalind.info/problems/cons/ | |
use v6; | |
my @dna = < | |
ATCCAGCT | |
GGGCAACT | |
ATGGATCT | |
AAGCAACC | |
TTGGAACT | |
ATGCCATT | |
ATGGCACT | |
>; | |
my $n = @dna[0].chars; | |
my %char_to_idx = <A C G T> Z=> 0..*; | |
my @m = [0 xx $n] xx 4; | |
for ^$n X @dna -> $i, $s { | |
@m[%char_to_idx{$s.substr($i, 1)}][$i]++; | |
} | |
for ^$n -> $idx { | |
print <A C G T>[@m.pairs.map({; .key => .value.[$idx] }).max(*.value).key]; | |
} | |
print "\n"; | |
for <A C G T> { | |
say join ' ', "$_:", @m[%char_to_idx{$_}].list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment