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;
}
}
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);
}
}
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;
}
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();
}
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;
}
Aggregations