use of dr.evolution.datatype.DataType in project beast-mcmc by beast-dev.
the class HomologyRecursion method init.
public void init(Tree tree, Alignment alignment, SubstitutionModel substModel, double mutationRate, double lengthDistr, double deathRate) {
// initialize the iParent and iTau arrays based on the given tree.
initTree(tree, mutationRate);
int[] treeIndex = new int[tree.getTaxonCount()];
for (int i = 0; i < treeIndex.length; i++) {
treeIndex[i] = tree.getTaxonIndex(alignment.getTaxonId(i));
// System.out.println("alignment[" + i + "] = tree[" + treeIndex[i] + "]");
}
// initialize the iAlignment array from the given alignment.
initAlignment(alignment, treeIndex);
// initialize the iSequences array from the given alignment.
initSequences(alignment, treeIndex);
// initialize the iTrans array from the substitution model -- must be called after populating tree!
initSubstitutionModel(substModel);
// iLambda, iMu
iLambda = deathRate * lengthDistr;
iMu = deathRate;
// iNumNucs - alphabet size
DataType dataType = substModel.getDataType();
iNumNucs = dataType.getStateCount();
// Initialise TKF91 coefficients in iB, iH, iN, iE, and iInitial
initTKF91();
// Check
checkConsistency();
// Initialise native method
iNativeMethod = new NativeTreeLikelihood();
iNativeMethod.init(iNumNucs, cMaxUnalignDimension, iParent, iEquil, iTrans, iSequences, iN, iH, iE, iB);
}
use of dr.evolution.datatype.DataType in project beast-mcmc by beast-dev.
the class HomologyRecursion method initSubstitutionModel.
/**
* initialize the iTrans array from the substitution model -- must be called after populating tree!
*/
private void initSubstitutionModel(SubstitutionModel model) {
DataType dataType = model.getDataType();
int stateCount = dataType.getStateCount();
iTrans = new double[iTau.length][stateCount][stateCount];
double[] transProb = new double[stateCount * stateCount];
int count;
for (int i = 0; i < iTau.length; i++) {
model.getTransitionProbabilities(iTau[i], transProb);
count = 0;
for (int j = 0; j < stateCount; j++) {
for (int k = 0; k < stateCount; k++) {
iTrans[i][j][k] = transProb[count];
count += 1;
}
}
}
// initialize equlibrium distribution
iEquil = new double[stateCount];
for (int k = 0; k < stateCount; k++) {
iEquil[k] = model.getFrequencyModel().getFrequency(k);
}
}
use of dr.evolution.datatype.DataType in project beast-mcmc by beast-dev.
the class HomologyRecursion method initSequences.
/**
* Initializes the iSequence array from the given alignment.
*/
private void initSequences(Alignment alignment, int[] treeIndex) {
int numSeqs = alignment.getSequenceCount();
DataType dataType = alignment.getDataType();
int numStates = dataType.getStateCount();
iSequences = new int[numSeqs][];
for (int i = 0; i < numSeqs; i++) {
int seqLength = 0;
for (int j = 0; j < alignment.getSiteCount(); j++) {
int state = alignment.getState(i, j);
if (state >= 0 && state < numStates) {
seqLength += 1;
}
}
iSequences[treeIndex[i]] = new int[seqLength];
int count = 0;
for (int j = 0; j < alignment.getSiteCount(); j++) {
int state = alignment.getState(i, j);
if (state >= 0 && state < numStates) {
iSequences[treeIndex[i]][count] = state;
count += 1;
}
}
}
}
use of dr.evolution.datatype.DataType in project beast-mcmc by beast-dev.
the class BinarySubstitutionModelParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
Parameter ratesParameter;
XMLObject cxo = xo.getChild(GeneralSubstitutionModelParser.FREQUENCIES);
FrequencyModel freqModel = (FrequencyModel) cxo.getChild(FrequencyModel.class);
DataType dataType = freqModel.getDataType();
if (dataType != TwoStates.INSTANCE)
throw new XMLParseException("Frequency model must have binary (two state) data type.");
int relativeTo = 0;
ratesParameter = new Parameter.Default(0);
return new GeneralSubstitutionModel(dataType, freqModel, ratesParameter, relativeTo);
}
use of dr.evolution.datatype.DataType in project beast-mcmc by beast-dev.
the class DataPanel method linkSubstitutionModels.
public void linkSubstitutionModels() {
int[] selRows = dataTable.getSelectedRows();
List<AbstractPartitionData> selectedPartitionData = new ArrayList<AbstractPartitionData>();
DataType dateType = null;
for (int row : selRows) {
AbstractPartitionData partition = options.dataPartitions.get(row);
if (dateType == null) {
dateType = partition.getDataType();
} else {
if (partition.getDataType() != dateType) {
JOptionPane.showMessageDialog(this, "Can only link the models for data partitions \n" + "of the same data type (e.g., nucleotides)", "Unable to link models", JOptionPane.ERROR_MESSAGE);
return;
}
}
if (!selectedPartitionData.contains(partition))
selectedPartitionData.add(partition);
}
Object[] modelArray = options.getPartitionSubstitutionModels(selectedPartitionData).toArray();
if (selectModelDialog == null) {
selectModelDialog = new SelectModelDialog(frame);
}
int result = selectModelDialog.showDialog(modelArray);
if (result != JOptionPane.CANCEL_OPTION) {
PartitionSubstitutionModel model = selectModelDialog.getModel();
if (selectModelDialog.getMakeCopy()) {
model.setName(selectModelDialog.getName());
}
for (AbstractPartitionData partition : selectedPartitionData) {
partition.setPartitionSubstitutionModel(model);
}
}
if (options.getPartitionSubstitutionModels(Microsatellite.INSTANCE).size() <= 1) {
options.shareMicroSat = true;
}
modelsChanged();
fireDataChanged();
repaint();
}
Aggregations