use of dr.evolution.tree.Tree in project beast-mcmc by beast-dev.
the class BeagleBranchLikelihood method main.
// END: LikelihoodColumn class
// ////////////
// ---TEST---//
// ////////////
public static void main(String[] args) {
try {
MathUtils.setSeed(666);
int sequenceLength = 1000;
ArrayList<Partition> partitionsList = new ArrayList<Partition>();
// create tree
NewickImporter importer = new NewickImporter("((SimSeq1:22.0,SimSeq2:22.0):12.0,(SimSeq3:23.1,SimSeq4:23.1):10.899999999999999);");
Tree tree = importer.importTree(null);
TreeModel treeModel = new TreeModel(tree);
// create Frequency Model
Parameter freqs = new Parameter.Default(new double[] { 0.25, 0.25, 0.25, 0.25 });
FrequencyModel freqModel = new FrequencyModel(Nucleotides.INSTANCE, freqs);
// create branch model
Parameter kappa1 = new Parameter.Default(1, 1);
HKY hky1 = new HKY(kappa1, freqModel);
BranchModel homogeneousBranchModel = new HomogeneousBranchModel(hky1);
List<SubstitutionModel> substitutionModels = new ArrayList<SubstitutionModel>();
substitutionModels.add(hky1);
List<FrequencyModel> freqModels = new ArrayList<FrequencyModel>();
freqModels.add(freqModel);
// create branch rate model
Parameter rate = new Parameter.Default(1, 1.000);
BranchRateModel branchRateModel = new StrictClockBranchRates(rate);
// create site model
GammaSiteRateModel siteRateModel = new GammaSiteRateModel("siteModel");
// create partition
Partition partition1 = new //
Partition(//
treeModel, //
homogeneousBranchModel, //
siteRateModel, //
branchRateModel, //
freqModel, // from
0, // to
sequenceLength - 1, // every
1);
partitionsList.add(partition1);
// feed to sequence simulator and generate data
BeagleSequenceSimulator simulator = new BeagleSequenceSimulator(partitionsList);
Alignment alignment = simulator.simulate(false, false);
System.out.println(alignment);
BeagleTreeLikelihood btl = new BeagleTreeLikelihood(alignment, treeModel, homogeneousBranchModel, siteRateModel, branchRateModel, null, false, PartialsRescalingScheme.DEFAULT, true);
System.out.println("BTL(homogeneous) = " + btl.getLogLikelihood());
BeagleBranchLikelihood bbl = new BeagleBranchLikelihood(alignment, treeModel, homogeneousBranchModel, siteRateModel, freqModel, branchRateModel);
int branchIndex = 4;
System.out.println(bbl.getBranchLogLikelihood(branchIndex));
bbl.finalizeBeagle();
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
} catch (Throwable e) {
e.printStackTrace();
System.exit(-1);
}
// END: try-catch block
}
use of dr.evolution.tree.Tree in project beast-mcmc by beast-dev.
the class IndependentCoalescentSampler method doOperation.
/**
* change the parameter and return the hastings ratio.
*/
public double doOperation() {
CoalescentSimulator simulator = new CoalescentSimulator();
List<TaxonList> taxonLists = new ArrayList<TaxonList>();
double rootHeight = -1.0;
double oldLikelihood = 0.0;
double newLikelihood = 0.0;
// should have one child that is node
for (int i = 0; i < xo.getChildCount(); i++) {
final Object child = xo.getChild(i);
//careful: Trees are TaxonLists ... (AER); see OldCoalescentSimulatorParser
if (child instanceof Tree) {
//do nothing
} else if (child instanceof TaxonList) {
//taxonLists.add((TaxonList) child);
taxonLists.add((Taxa) child);
//taxa added
break;
}
}
try {
Tree[] trees = new Tree[taxonLists.size()];
// simulate each taxonList separately
for (int i = 0; i < taxonLists.size(); i++) {
trees[i] = simulator.simulateTree(taxonLists.get(i), demoModel);
}
oldLikelihood = coalescent.getLogLikelihood();
SimpleTree simTree = simulator.simulateTree(trees, demoModel, rootHeight, trees.length != 1);
//this would be the normal way to do it
treeModel.beginTreeEdit();
//now it's allowed to adjust the tree structure
treeModel.adoptTreeStructure(simTree);
//endTreeEdit() would then fire the events
treeModel.endTreeEdit();
newLikelihood = coalescent.getLogLikelihood();
} catch (IllegalArgumentException iae) {
try {
throw new XMLParseException(iae.getMessage());
} catch (XMLParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return oldLikelihood - newLikelihood;
}
use of dr.evolution.tree.Tree in project beast-mcmc by beast-dev.
the class DataLikelihoodTester method createSpecifiedTree.
private static TreeModel createSpecifiedTree(String t) throws Exception {
NewickImporter importer = new NewickImporter(t);
Tree tree = importer.importTree(null);
//treeModel
return new TreeModel(tree);
}
use of dr.evolution.tree.Tree in project beast-mcmc by beast-dev.
the class ProgressiveScalarTreeTransform method main.
// TODO Move to JUnitTest
public static void main(String[] args) throws Exception {
NewickImporter importer = new NewickImporter("((((A:2,B:1):0.5,C:3):1.5,(D:1.5,E:1):3.5):1,F:5);");
Tree tree = importer.importTree(null);
Parameter scale = new Parameter.Default(0.5);
TreeTransform xform = new ProgressiveScalarTreeTransform(scale);
TreeModel treeModel = new TreeModel("original", tree);
TransformedTreeModel model = new TransformedTreeModel("tree", treeModel, xform);
System.err.println(model.toString());
TreeTransform xform2 = new SingleScalarTreeTransform(scale);
TransformedTreeModel model2 = new TransformedTreeModel("tree2", treeModel, xform2);
System.err.println(model2.toString());
}
use of dr.evolution.tree.Tree in project beast-mcmc by beast-dev.
the class TreeTransform method setupTraits.
private void setupTraits() {
TreeTrait baseTrait = new TreeTrait.D() {
public String getTraitName() {
return TREE_TRANSFORM_PREFIX;
}
public Intent getIntent() {
return Intent.BRANCH;
}
public Double getTrait(Tree tree, NodeRef node) {
return getScaleForNode(tree, node);
}
public boolean getLoggable() {
return true;
}
};
treeTraits.addTrait(baseTrait);
}
Aggregations