Dear Masters,

Given a set of align sequences I want to compute the minimum number of substitution for each column. The example is below:
CGGCGGAAAACTGTCCTCCGTGC mouse CGACGGAACATTCTCCTCCGCGC rat CGACGGAATATTCCCCTCCGTGC human CGACGGAAGACTCTCCTCCGTGC chimp 00100000302011000000100 -> number of subst per site (max parsimony)
Is there a way to compute the value above? My current code does not do the job:
use Data::Dumper; use List::MoreUtils qw(uniq); # The related phylogenetic in Newick format tree is: my $tree = '(mouse,rat,(human,chimp))'; my $sites = [ 'CGGCGGAAAACTGTCCTCCGTGC', # mouse 'CGACGGAACATTCTCCTCCGCGC', # rat 'CGACGGAATATTCCCCTCCGTGC', # human 'CGACGGAAGACTCTCCTCCGTGC', # chimp ]; my @val = my_parsimony($sites); print Dumper \@val; sub my_parsimony { my $tfbs = shift; my $mlen = length($tfbs->[0]); my $sum_min = 0; my @mincol; foreach my $pos ( 0 .. $mlen-1 ) { my @colbp = (); foreach my $site ( @{$tfbs} ) { my $bp = substr($site,$pos,1); push @colbp, $bp; } # this heuristic seems to be faulty # Column 11 it predicts 1 instead of 2 my $min_mm = scalar( uniq(@colbp) ) - 1; push @mincol, $min_mm; } return @mincol; }
Actually I want to mimic Fitch's classical parsimony algorithm. But cannot fathom how to implement it.


Update:Problem resolved. Thanks everybody. psini+++.

---
neversaint and everlastingly indebted.......

In reply to Maximal Parsimony Problem by neversaint

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.