use of dr.evolution.datatype.Microsatellite in project beast-mcmc by beast-dev.
the class MicrosatelliteSimulatorParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
Microsatellite msatDataType = (Microsatellite) xo.getChild(Microsatellite.class);
Taxa taxa = (Taxa) xo.getChild(Taxa.class);
Tree tree = (Tree) xo.getChild(Tree.class);
MicrosatelliteModel msatModel = (MicrosatelliteModel) xo.getChild(MicrosatelliteModel.class);
BranchRateModel brModel = (BranchRateModel) xo.getChild(BranchRateModel.class);
if (brModel == null) {
brModel = new DefaultBranchRateModel();
}
MicrosatelliteSimulator msatSim = new MicrosatelliteSimulator(msatDataType, taxa, tree, new GammaSiteModel(msatModel), brModel);
Patterns patterns = msatSim.simulateMsatPattern();
String msatPatId = xo.getAttribute("id", "simMsatPat");
patterns.setId(msatPatId);
MicrosatellitePatternParser.printDetails(patterns);
MicrosatellitePatternParser.printMicrosatContent(patterns);
return patterns;
}
use of dr.evolution.datatype.Microsatellite in project beast-mcmc by beast-dev.
the class LinearBiasModelParser method parseXMLObject.
//AbstractXMLObjectParser implementation
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
OnePhaseModel subModel = (OnePhaseModel) xo.getElementFirstChild(SUBMODEL);
Microsatellite dataType = (Microsatellite) subModel.getDataType();
Parameter biasConst = null;
if (xo.hasChildNamed(BIAS_CONSTANT)) {
biasConst = (Parameter) xo.getElementFirstChild(BIAS_CONSTANT);
}
Parameter biasLin = null;
if (xo.hasChildNamed(BIAS_LINEAR)) {
biasLin = (Parameter) xo.getElementFirstChild(BIAS_LINEAR);
}
//get FrequencyModel
FrequencyModel freqModel = null;
if (xo.hasChildNamed(FrequencyModelParser.FREQUENCIES)) {
freqModel = (FrequencyModel) xo.getElementFirstChild(FrequencyModelParser.FREQUENCIES);
}
boolean estimateSubmodelParams = false;
if (xo.hasAttribute(ESTIMATE_SUBMODEL_PARAMS)) {
estimateSubmodelParams = xo.getBooleanAttribute(ESTIMATE_SUBMODEL_PARAMS);
}
System.out.println("Is estimating submodel parameter(s): " + estimateSubmodelParams);
boolean logistics = false;
if (xo.hasAttribute(LOGISTICS)) {
logistics = xo.getBooleanAttribute(LOGISTICS);
}
System.out.println("Using logistic regression: " + logistics);
boolean isSubmodel = false;
if (xo.hasAttribute(IS_SUBMODEL)) {
isSubmodel = xo.getBooleanAttribute(IS_SUBMODEL);
}
System.out.println("Is a submodel: " + isSubmodel);
return new LinearBiasModel(dataType, freqModel, subModel, biasConst, biasLin, logistics, estimateSubmodelParams, isSubmodel);
}
use of dr.evolution.datatype.Microsatellite in project beast-mcmc by beast-dev.
the class AsymQuadTest method testAsymmetricQuadraticModel.
public void testAsymmetricQuadraticModel() {
for (Instance test : all) {
Parameter expanConst = new Parameter.Default(1, test.getExpanConst());
Parameter expanLin = new Parameter.Default(1, test.getExpanLin());
Parameter expanQuad = new Parameter.Default(1, test.getExpanQuad());
Parameter contractConst = new Parameter.Default(1, test.getContractConst());
Parameter contractLin = new Parameter.Default(1, test.getContractLin());
Parameter contractQuad = new Parameter.Default(1, test.getContractQuad());
Microsatellite microsat = test.getDataType();
AsymmetricQuadraticModel aqm = new AsymmetricQuadraticModel(microsat, null, expanConst, expanLin, expanQuad, contractConst, contractLin, contractQuad, false);
aqm.computeStationaryDistribution();
double[] statDist = aqm.getStationaryDistribution();
final double[] expectedStatDist = test.getExpectedPi();
for (int k = 0; k < statDist.length; ++k) {
assertEquals(statDist[k], expectedStatDist[k], 1e-10);
}
double[] mat = new double[4 * 4];
aqm.getTransitionProbabilities(test.getDistance(), mat);
final double[] result = test.getExpectedResult();
int k;
for (k = 0; k < mat.length; ++k) {
assertEquals(result[k], mat[k], 1e-10);
// System.out.print(" " + (mat[k] - result[k]));
}
k = 0;
for (int i = 0; i < microsat.getStateCount(); i++) {
for (int j = 0; j < microsat.getStateCount(); j++) {
assertEquals(result[k++], aqm.getOneTransitionProbabilityEntry(test.getDistance(), i, j), 1e-10);
}
}
for (int j = 0; j < microsat.getStateCount(); j++) {
double[] colTransitionProb = aqm.getColTransitionProbabilities(test.getDistance(), j);
for (int i = 0; i < microsat.getStateCount(); i++) {
assertEquals(result[i * microsat.getStateCount() + j], colTransitionProb[i], 1e-10);
}
}
for (int i = 0; i < microsat.getStateCount(); i++) {
double[] rowTransitionProb = aqm.getRowTransitionProbabilities(test.getDistance(), i);
for (int j = 0; j < microsat.getStateCount(); j++) {
assertEquals(result[i * microsat.getStateCount() + j], rowTransitionProb[j], 1e-10);
}
}
}
}
use of dr.evolution.datatype.Microsatellite in project beast-mcmc by beast-dev.
the class MsatFullLikelihoodTest method setUpExample3.
private void setUpExample3() throws Exception {
//taxa
ArrayList<Taxon> taxonList3 = new ArrayList<Taxon>();
Collections.addAll(taxonList3, new Taxon("taxon1"), new Taxon("taxon2"), new Taxon("taxon3"), new Taxon("taxon4"), new Taxon("taxon5"), new Taxon("taxon6"), new Taxon("taxon7"));
Taxa taxa3 = new Taxa(taxonList3);
//msat datatype
Microsatellite msat = new Microsatellite(1, 4);
Patterns msatPatterns = new Patterns(msat, taxa3);
//pattern in the correct code form.
msatPatterns.addPattern(new int[] { 0, 3, 1, 2, 3, 0, 1 });
//create tree
NewickImporter importer = new NewickImporter("(((taxon1:0.3,taxon2:0.3):0.6,taxon3:0.9):0.9,((taxon4:0.5,taxon5:0.5):0.3,(taxon6:0.7,taxon7:0.7):0.1):1.0);");
Tree tree = importer.importTree(null);
//treeModel
TreeModel treeModel = new TreeModel(tree);
//msatsubstModel
AsymmetricQuadraticModel aqm3 = new AsymmetricQuadraticModel(msat, null);
//siteModel
GammaSiteModel siteModel = new GammaSiteModel(aqm3);
//treeLikelihood
treeLikelihood3 = new TreeLikelihood(msatPatterns, treeModel, siteModel, null, null, false, false, true, false, false);
}
use of dr.evolution.datatype.Microsatellite in project beast-mcmc by beast-dev.
the class TwoPhaseModelTest method testTwoPhaseModel.
public void testTwoPhaseModel() {
for (Instance test : all) {
OnePhaseModel subModel = test.getSubModel();
Microsatellite microsat = (Microsatellite) subModel.getDataType();
Parameter pParam = new Parameter.Default(test.getPParam());
Parameter mParam = new Parameter.Default(test.getMParam());
TwoPhaseModel tpm = new TwoPhaseModel(microsat, null, subModel, pParam, mParam, null, false);
int k;
tpm.computeStationaryDistribution();
double[] statDist = tpm.getStationaryDistribution();
final double[] expectedStatDist = test.getPi();
for (k = 0; k < statDist.length; ++k) {
assertEquals(statDist[k], expectedStatDist[k], 1e-10);
}
int stateCount = microsat.getStateCount();
double[] mat = new double[stateCount * stateCount];
tpm.getTransitionProbabilities(test.getDistance(), mat);
final double[] result = test.getExpectedResult();
for (k = 0; k < mat.length; ++k) {
assertEquals(result[k], mat[k], 5e-9);
//System.out.print(" " + (mat[k]));// - result[k]));
}
k = 0;
for (int i = 0; i < microsat.getStateCount(); i++) {
for (int j = 0; j < microsat.getStateCount(); j++) {
assertEquals(result[k++], tpm.getOneTransitionProbabilityEntry(test.getDistance(), i, j), 1e-10);
}
}
for (int j = 0; j < microsat.getStateCount(); j++) {
double[] colTransitionProb = tpm.getColTransitionProbabilities(test.getDistance(), j);
for (int i = 0; i < microsat.getStateCount(); i++) {
assertEquals(result[i * microsat.getStateCount() + j], colTransitionProb[i], 1e-10);
}
}
for (int i = 0; i < microsat.getStateCount(); i++) {
double[] rowTransitionProb = tpm.getRowTransitionProbabilities(test.getDistance(), i);
for (int j = 0; j < microsat.getStateCount(); j++) {
assertEquals(result[i * microsat.getStateCount() + j], rowTransitionProb[j], 1e-10);
}
}
}
}
Aggregations