Search in sources :

Example 1 with MarginalTree

use of bacter.MarginalTree in project bacter by tgvaughan.

the class ACGLikelihoodSlow method calculateLogP.

@Override
public double calculateLogP() {
    logP = 0.0;
    for (Region region : acg.getRegions(locus)) {
        Alignment margAlign = createMarginalAlignment(alignment, acg, region);
        Tree margTree = new Tree(new MarginalTree(acg, region).getRoot());
        TreeLikelihood treeLikelihood = new TreeLikelihood();
        treeLikelihood.initByName("data", margAlign, "tree", margTree, "siteModel", siteModel, "useAmbiguities", useAmbiguitiesInput.get());
        logP += treeLikelihood.calculateLogP();
    }
    return logP;
}
Also used : Alignment(beast.evolution.alignment.Alignment) TreeLikelihood(beast.evolution.likelihood.TreeLikelihood) GenericTreeLikelihood(beast.evolution.likelihood.GenericTreeLikelihood) Region(bacter.Region) Tree(beast.evolution.tree.Tree) MarginalTree(bacter.MarginalTree) MarginalTree(bacter.MarginalTree)

Example 2 with MarginalTree

use of bacter.MarginalTree in project bacter by tgvaughan.

the class SimulatedAlignment method simulate.

/**
 * Perform actual sequence simulation.
 */
private void simulate(Locus locus) {
    Node cfRoot = acg.getRoot();
    int nTaxa = acg.getLeafNodeCount();
    double[] categoryProbs = siteModel.getCategoryProportions(cfRoot);
    int nCategories = siteModel.getCategoryCount();
    int nStates = dataType.getStateCount();
    double[][] transitionProbs = new double[nCategories][nStates * nStates];
    int[][] alignment = new int[nTaxa][locus.getSiteCount()];
    for (Region region : acg.getRegions(locus)) {
        int thisLength = region.getRegionLength();
        MarginalTree marginalTree = new MarginalTree(acg, region);
        int[] categories = new int[thisLength];
        for (int i = 0; i < thisLength; i++) categories[i] = Randomizer.randomChoicePDF(categoryProbs);
        int[][] regionAlignment = new int[nTaxa][thisLength];
        Node thisRoot = marginalTree.getRoot();
        int[] parentSequence = new int[region.getRegionLength()];
        double[] frequencies = siteModel.getSubstitutionModel().getFrequencies();
        for (int i = 0; i < parentSequence.length; i++) parentSequence[i] = Randomizer.randomChoicePDF(frequencies);
        traverse(thisRoot, parentSequence, categories, transitionProbs, regionAlignment);
        // DEBUG: Count differences
        int segsites = 0;
        for (int s = 0; s < regionAlignment[0].length; s++) {
            int state = regionAlignment[0][s];
            for (int l = 1; l < nTaxa; l++) {
                if (state != regionAlignment[l][s]) {
                    segsites += 1;
                    break;
                }
            }
        }
        System.out.println(segsites + " segregating sites in region " + region);
        copyToAlignment(alignment, regionAlignment, region);
    }
    for (int leafIdx = 0; leafIdx < nTaxa; leafIdx++) {
        String sSeq = dataType.encodingToString(alignment[leafIdx]);
        String sTaxon = acg.getNode(leafIdx).getID();
        sequenceInput.setValue(new Sequence(sTaxon, sSeq), this);
    }
}
Also used : Node(beast.evolution.tree.Node) Region(bacter.Region) MarginalTree(bacter.MarginalTree) Sequence(beast.evolution.alignment.Sequence)

Aggregations

MarginalTree (bacter.MarginalTree)2 Region (bacter.Region)2 Alignment (beast.evolution.alignment.Alignment)1 Sequence (beast.evolution.alignment.Sequence)1 GenericTreeLikelihood (beast.evolution.likelihood.GenericTreeLikelihood)1 TreeLikelihood (beast.evolution.likelihood.TreeLikelihood)1 Node (beast.evolution.tree.Node)1 Tree (beast.evolution.tree.Tree)1