    001    package calhoun.analysis.crf.features.supporting.phylogenetic;
    002    import java.io.IOException;
    003    import java.io.Serializable;
    004
    005    import org.apache.commons.logging.Log;
    006    import org.apache.commons.logging.LogFactory;
    007
    008    import calhoun.util.Assert;
    009
    010    public class PhylogeneticTreeFelsensteinOrder implements Serializable {
    011            private static final long serialVersionUID = -2394371116379001213L;
    012            private static final Log log = LogFactory.getLog(PhylogeneticTreeFelsensteinOrder.class);
    013    /* For now, hardcoded for the phylogeny and relative branch lengths of the
    014     * aligned cryptococcus serotypes.  However, all that is needed to make this
    015     * general is a parser for NSF formatted descriptions of trees and a comparison
    016     * to the order of species in the multiple alignment.
    017     */
    018
    019            int[]     ileft,iright;
    020            double[]  bleft,bright;
    021            int nSpecies,nSteps,nNodes;
    022
    023            public PhylogeneticTreeFelsensteinOrder() {
    024                    // Below is a representation of the crypto tree which I got from Dan:
    025                    // ((cnBB: 0.034084, cnBV: 0.034065): 0.186256, cnA: 0.081165, cnDT: 0.071992):0.0;
    026                    // Below is the one I'll be using since it has all 5 species:
    027                    // (((cnDT:0.0025,cnDS:0.0025):0.0475,cnAB:0.05):0.02,(cnBB:0.02,cnBV:0.02):0.05):0;
    028
    029                    // the order of species in the multiple alignment is cnDT,cnDS,cnA,cnBB,cnBV
    030
    031                    // Would be nice to figure out the sequence of four steps below given the string
    032                    // representing the phylogenetic tree (NSF format) and the order of species in the multiple alignment column
    033                    // 5 = (0,0.0025 ; 1,0.0025)
    034                    // 6 = (5,0.0475 ; 2,0.05)
    035                    // 7 = (3,0.02 ; 4,0.02)
    036                    // 8 = (6,0.02 ; 7,0.05)
    037
    038                    ileft = new int[]{0,5,3,6};
    039                    iright = new int[]{1,2,4,7};
    040                    bleft = new double[]{0.0025,0.0475,0.02,0.02};
    041                    bright = new double[]{0.0025,0.05,0.02,0.05};
    042
    043                    setup();
    044            }
    045
    046            public PhylogeneticTreeFelsensteinOrder(int[] ileft, int[] iright, double[] bleft, double[] bright) {
    047                    this.ileft = ileft;
    048                    this.iright = iright;
    049                    this.bleft = bleft;
    050                    this.bright = bright;
    051
    052                    setup();
    053            }
    054
    055            public void summarize() throws IOException {
    056                    log.debug("Summary of an order-of-computations object for Felsenstein recursion");
    057                    log.debug("Number of species: " + nSpecies);
    058                    log.debug("Number of steps:   " + nSteps);
    059                    log.debug("Number of nodes:   " + nNodes);
    060                    log.debug("  Nodes 0 to " + (nSpecies-1) + " are given.");
    061                    //for (int j=0; j<nSpecies; j++) {
    062                    //      stream.println("  Node " + j + " is given");
    063                    //}
    064                    for (int step=0; step<nSteps; step++) {
    065                            log.debug("  Node " + (nSpecies + step) + " combines nodes " + ileft[step] + " and " + iright[step] +
    066                                            " with branchlengths " + bleft[step] + " and " + bright[step]);
    067                    }
    068            }
    069
    070            private void setup() {
    071                    nSteps = ileft.length;
    072                    Assert.a(iright.length == nSteps);
    073                    Assert.a(bleft.length == nSteps);
    074                    Assert.a(bright.length == nSteps);
    075
    076                    nSpecies = nSteps+1;
    077                    nNodes = nSpecies + nSteps;
    078            }
    079
    080            public int numSpecies() {
    081                    return nSpecies;
    082            }
    083
    084            public int numSteps() {
    085                    return nSteps;
    086            }
    087
    088            public int numNodes() {
    089                    return nNodes;
    090            }
    091
    092            public int[] getileft() {
    093                    return ileft;
    094            }
    095
    096            public int[] getiright() {
    097                    return iright;
    098            }
    099
    100            public double[] getbleft() {
    101                    return bleft;
    102            }
    103
    104            public double[] getbright() {
    105                    return bright;
    106            }
    107
    108    }
    109