Skip to content

Instantly share code, notes, and snippets.

@moritz
Created October 19, 2012 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moritz/3919636 to your computer and use it in GitHub Desktop.
Save moritz/3919636 to your computer and use it in GitHub Desktop.
Finding a Most Likely Common Ancestor (Perl 6)
# 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