Search in sources :

Example 76 with Alignment

use of beast.evolution.alignment.Alignment in project beast2 by CompEvol.

the class TreeLikelihood method initAndValidate.

@Override
public void initAndValidate() {
    // sanity check: alignment should have same #taxa as tree
    if (dataInput.get().getTaxonCount() != treeInput.get().getLeafNodeCount()) {
        throw new IllegalArgumentException("The number of nodes in the tree does not match the number of sequences");
    }
    beagle = null;
    beagle = new BeagleTreeLikelihood();
    try {
        beagle.initByName("data", dataInput.get(), "tree", treeInput.get(), "siteModel", siteModelInput.get(), "branchRateModel", branchRateModelInput.get(), "useAmbiguities", m_useAmbiguities.get(), "useTipLikelihoods", m_useTipLikelihoods.get(), "scaling", scaling.get().toString());
        if (beagle.beagle != null) {
            // a Beagle instance was found, so we use it
            return;
        }
    } catch (Exception e) {
    // ignore
    }
    // No Beagle instance was found, so we use the good old java likelihood core
    beagle = null;
    int nodeCount = treeInput.get().getNodeCount();
    if (!(siteModelInput.get() instanceof SiteModel.Base)) {
        throw new IllegalArgumentException("siteModel input should be of type SiteModel.Base");
    }
    m_siteModel = (SiteModel.Base) siteModelInput.get();
    m_siteModel.setDataType(dataInput.get().getDataType());
    substitutionModel = m_siteModel.substModelInput.get();
    if (branchRateModelInput.get() != null) {
        branchRateModel = branchRateModelInput.get();
    } else {
        branchRateModel = new StrictClockModel();
    }
    m_branchLengths = new double[nodeCount];
    storedBranchLengths = new double[nodeCount];
    int stateCount = dataInput.get().getMaxStateCount();
    int patterns = dataInput.get().getPatternCount();
    if (stateCount == 4) {
        likelihoodCore = new BeerLikelihoodCore4();
    } else {
        likelihoodCore = new BeerLikelihoodCore(stateCount);
    }
    String className = getClass().getSimpleName();
    Alignment alignment = dataInput.get();
    Log.info.println(className + "(" + getID() + ") uses " + likelihoodCore.getClass().getSimpleName());
    Log.info.println("  " + alignment.toString(true));
    // print startup messages via Log.print*
    proportionInvariant = m_siteModel.getProportionInvariant();
    m_siteModel.setPropInvariantIsCategory(false);
    if (proportionInvariant > 0) {
        calcConstantPatternIndices(patterns, stateCount);
    }
    initCore();
    patternLogLikelihoods = new double[patterns];
    m_fRootPartials = new double[patterns * stateCount];
    matrixSize = (stateCount + 1) * (stateCount + 1);
    probabilities = new double[(stateCount + 1) * (stateCount + 1)];
    Arrays.fill(probabilities, 1.0);
    if (dataInput.get().isAscertained) {
        useAscertainedSitePatterns = true;
    }
}
Also used : StrictClockModel(beast.evolution.branchratemodel.StrictClockModel) Alignment(beast.evolution.alignment.Alignment) SiteModel(beast.evolution.sitemodel.SiteModel)

Example 77 with Alignment

use of beast.evolution.alignment.Alignment in project beast2 by CompEvol.

the class TreeLikelihood method setStates.

/**
 * set leaf states in likelihood core *
 */
protected void setStates(Node node, int patternCount) {
    if (node.isLeaf()) {
        Alignment data = dataInput.get();
        int i;
        int[] states = new int[patternCount];
        int taxonIndex = getTaxonIndex(node.getID(), data);
        for (i = 0; i < patternCount; i++) {
            int code = data.getPattern(taxonIndex, i);
            int[] statesForCode = data.getDataType().getStatesForCode(code);
            if (statesForCode.length == 1)
                states[i] = statesForCode[0];
            else
                // Causes ambiguous states to be ignored.
                states[i] = code;
        }
        likelihoodCore.setNodeStates(node.getNr(), states);
    } else {
        setStates(node.getLeft(), patternCount);
        setStates(node.getRight(), patternCount);
    }
}
Also used : Alignment(beast.evolution.alignment.Alignment)

Example 78 with Alignment

use of beast.evolution.alignment.Alignment in project beast2 by CompEvol.

the class BeautiDoc method getPartition.

Alignment getPartition(BEASTInterface beastObject) {
    String partition = beastObject.getID();
    partition = parsePartition(partition);
    for (Alignment data : alignments) {
        if (data.getID().equals(partition)) {
            return data;
        }
    }
    return null;
}
Also used : FilteredAlignment(beast.evolution.alignment.FilteredAlignment) Alignment(beast.evolution.alignment.Alignment)

Example 79 with Alignment

use of beast.evolution.alignment.Alignment in project beast2 by CompEvol.

the class BeautiDoc method importNexus.

public void importNexus(File file) throws IOException {
    NexusParser parser = new NexusParser();
    parser.parseFile(file);
    if (parser.filteredAlignments.size() > 0) {
        for (Alignment data : parser.filteredAlignments) {
            addAlignmentWithSubnet(data, beautiConfig.partitionTemplate.get());
        }
    } else {
        addAlignmentWithSubnet(parser.m_alignment, beautiConfig.partitionTemplate.get());
    }
    // connectModel();
    addTraitSet(parser.traitSet);
// fireDocHasChanged();
}
Also used : FilteredAlignment(beast.evolution.alignment.FilteredAlignment) Alignment(beast.evolution.alignment.Alignment) NexusParser(beast.util.NexusParser)

Example 80 with Alignment

use of beast.evolution.alignment.Alignment in project beast2 by CompEvol.

the class SequenceSimulator method simulate.

// intArray2Sequence
/**
 * perform the actual sequence generation
 *
 * @return alignment containing randomly generated sequences for the nodes in the
 *         leaves of the tree
 * @
 */
public Alignment simulate() {
    Node root = m_tree.getRoot();
    double[] categoryProbs = m_siteModel.getCategoryProportions(root);
    int[] category = new int[m_sequenceLength];
    for (int i = 0; i < m_sequenceLength; i++) {
        category[i] = Randomizer.randomChoicePDF(categoryProbs);
    }
    double[] frequencies = m_siteModel.getSubstitutionModel().getFrequencies();
    int[] seq = new int[m_sequenceLength];
    for (int i = 0; i < m_sequenceLength; i++) {
        seq[i] = Randomizer.randomChoicePDF(frequencies);
    }
    Alignment alignment = new Alignment();
    alignment.userDataTypeInput.setValue(m_data.get().getDataType(), alignment);
    alignment.setID("SequenceSimulator");
    traverse(root, seq, category, alignment);
    return alignment;
}
Also used : Alignment(beast.evolution.alignment.Alignment) Node(beast.evolution.tree.Node)

Aggregations

Alignment (beast.evolution.alignment.Alignment)102 Test (org.junit.Test)43 Sequence (beast.evolution.alignment.Sequence)31 FilteredAlignment (beast.evolution.alignment.FilteredAlignment)30 Tree (beast.evolution.tree.Tree)29 SiteModel (beast.evolution.sitemodel.SiteModel)27 TreeLikelihood (beast.evolution.likelihood.TreeLikelihood)22 BeagleTreeLikelihood (beast.evolution.likelihood.BeagleTreeLikelihood)20 ArrayList (java.util.ArrayList)17 UncertainAlignmentTest (test.beast.evolution.alignment.UncertainAlignmentTest)17 Frequencies (beast.evolution.substitutionmodel.Frequencies)13 RealParameter (beast.core.parameter.RealParameter)12 TaxonSet (beast.evolution.alignment.TaxonSet)11 BEASTInterface (beast.core.BEASTInterface)10 ClusterTree (beast.util.ClusterTree)9 Taxon (beast.evolution.alignment.Taxon)6 HKY (beast.evolution.substitutionmodel.HKY)6 Node (beast.evolution.tree.Node)6 TreeParser (beast.util.TreeParser)6 IOException (java.io.IOException)6