use of beast.core.BEASTInterface in project beast2 by CompEvol.
the class BeautiDoc method determinePartitions.
public void determinePartitions() {
CompoundDistribution likelihood = (CompoundDistribution) pluginmap.get("likelihood");
if (likelihood == null) {
return;
}
partitionNames.clear();
possibleContexts.clear();
for (Distribution distr : likelihood.pDistributions.get()) {
if (distr instanceof GenericTreeLikelihood) {
GenericTreeLikelihood treeLikelihood = (GenericTreeLikelihood) distr;
alignments.add(treeLikelihood.dataInput.get());
PartitionContext context = new PartitionContext(treeLikelihood);
partitionNames.add(context);
boolean found = false;
for (PartitionContext context2 : possibleContexts) {
if (context.equals(context2)) {
found = true;
}
}
if (!found) {
possibleContexts.add(context);
}
}
}
alignments.clear();
for (int i = 0; i < 3; i++) {
pPartitionByAlignments[i].clear();
pPartition[i].clear();
currentPartitions[i].clear();
}
List<GenericTreeLikelihood> treeLikelihoods = new ArrayList<>();
for (Distribution distr : likelihood.pDistributions.get()) {
if (distr instanceof GenericTreeLikelihood) {
GenericTreeLikelihood treeLikelihood = (GenericTreeLikelihood) distr;
alignments.add(treeLikelihood.dataInput.get());
treeLikelihoods.add(treeLikelihood);
}
}
for (Distribution distr : likelihood.pDistributions.get()) {
if (distr instanceof GenericTreeLikelihood) {
GenericTreeLikelihood treeLikelihood = (GenericTreeLikelihood) distr;
try {
// sync SiteModel, ClockModel and Tree to any changes that
// may have occurred
// this should only affect the clock model in practice
int partition = getPartitionNr((BEASTInterface) treeLikelihood.siteModelInput.get());
GenericTreeLikelihood treeLikelihood2 = treeLikelihoods.get(partition);
treeLikelihood.siteModelInput.setValue(treeLikelihood2.siteModelInput.get(), treeLikelihood);
currentPartitions[0].add(partition);
BranchRateModel rateModel = treeLikelihood.branchRateModelInput.get();
if (rateModel != null) {
partition = getPartitionNr((BEASTInterface) rateModel);
treeLikelihood2 = treeLikelihoods.get(partition);
treeLikelihood.branchRateModelInput.setValue(treeLikelihood2.branchRateModelInput.get(), treeLikelihood);
currentPartitions[1].add(partition);
} else {
currentPartitions[1].add(0);
}
partition = getPartitionNr((BEASTInterface) treeLikelihood.treeInput.get());
treeLikelihood2 = treeLikelihoods.get(partition);
treeLikelihood.treeInput.setValue(treeLikelihood2.treeInput.get(), treeLikelihood);
currentPartitions[2].add(partition);
} catch (Exception e) {
e.printStackTrace();
}
pPartitionByAlignments[0].add(treeLikelihood);
pPartitionByAlignments[1].add(treeLikelihood);
pPartitionByAlignments[2].add(treeLikelihood);
}
}
int partitionCount = partitionNames.size();
for (int i = 0; i < 3; i++) {
boolean[] usedPartition = new boolean[partitionCount];
for (int j = 0; j < partitionCount; j++) {
// getPartitionNr(m_pPartitionByAlignments[i].get(j));
int partitionIndex = currentPartitions[i].get(j);
usedPartition[partitionIndex] = true;
}
for (int j = 0; j < partitionCount; j++) {
if (usedPartition[j]) {
pPartition[i].add(pPartitionByAlignments[i].get(j));
}
}
}
Log.warning.println("PARTITIONS0:\n");
Log.warning.println(Arrays.toString(currentPartitions));
}
use of beast.core.BEASTInterface in project beast2 by CompEvol.
the class BeautiDoc method connect.
/**
* connect source beastObject with target beastObject
*
* @ *
*/
public void connect(BeautiConnector connector, PartitionContext context) {
if (!connector.isRegularConnector) {
return;
}
String srcID = translatePartitionNames(connector.sourceID, context);
BEASTInterface srcBEASTObject = pluginmap.get(srcID);
if (srcBEASTObject == null) {
throw new IllegalArgumentException("Could not find beastObject with id " + srcID + ". Typo in template perhaps?\n");
}
String targetID = translatePartitionNames(connector.targetID, context);
connect(srcBEASTObject, targetID, connector.targetInput);
}
use of beast.core.BEASTInterface in project beast2 by CompEvol.
the class BeautiDoc method collectClockModels.
private void collectClockModels() {
// collect branch rate models from model
CompoundDistribution likelihood = (CompoundDistribution) pluginmap.get("likelihood");
while (clockModels.size() < partitionNames.size()) {
try {
GenericTreeLikelihood treelikelihood = new GenericTreeLikelihood();
treelikelihood.branchRateModelInput.setValue(new StrictClockModel(), treelikelihood);
List<BeautiSubTemplate> availableBEASTObjects = inputEditorFactory.getAvailableTemplates(treelikelihood.branchRateModelInput, treelikelihood, null, this);
BEASTInterface beastObject = availableBEASTObjects.get(0).createSubNet(partitionNames.get(clockModels.size()), true);
clockModels.add((BranchRateModel.Base) beastObject);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
int k = 0;
for (Distribution d : likelihood.pDistributions.get()) {
BranchRateModel clockModel = ((GenericTreeLikelihood) d).branchRateModelInput.get();
// sanity check
Tree tree = null;
try {
for (Input<?> input : ((BEASTInterface) clockModel).listInputs()) {
if (input.getName().equals("tree")) {
tree = (Tree) input.get();
}
}
if (tree != null && tree != ((GenericTreeLikelihood) d).treeInput.get()) {
clockModel = clockModels.get(k);
Log.warning.println("WARNING: unlinking clock model for " + d.getID());
// TODO #557: this should move to the event of clock model drop box
// JOptionPane.showMessageDialog(beauti.getSelectedComponent(),
// "Cannot link all clock model(s) except strict clock with different trees !");
((GenericTreeLikelihood) d).branchRateModelInput.setValue(clockModel, d);
}
} catch (Exception e) {
// ignore
}
if (clockModel != null) {
String id = ((BEASTInterface) clockModel).getID();
id = parsePartition(id);
String partition = alignments.get(k).getID();
if (id.equals(partition)) {
clockModels.set(k, clockModel);
}
k++;
}
}
}
use of beast.core.BEASTInterface in project beast2 by CompEvol.
the class BeautiDoc method toJSON.
// save
private String toJSON() {
Set<BEASTInterface> beastObjects = new HashSet<>();
String json = new JSONProducer().toJSON(mcmc.get(), beastObjects);
json = json.replaceFirst("\\{", "{ beautitemplate:\"" + templateName + "\", beautistatus:\"" + getBeautiStatus() + "\", ");
return json + "\n";
}
use of beast.core.BEASTInterface in project beast2 by CompEvol.
the class BeautiDoc method setUpActivePlugins.
// scrubAll
protected void setUpActivePlugins() {
posteriorPredecessors = new ArrayList<>();
collectPredecessors(((MCMC) mcmc.get()).posteriorInput.get(), posteriorPredecessors);
likelihoodPredecessors = new ArrayList<>();
if (pluginmap.containsKey("likelihood")) {
collectPredecessors(pluginmap.get("likelihood"), likelihoodPredecessors);
}
Log.trace.print("InPosterior=");
for (BEASTInterface o : posteriorPredecessors) {
pluginmap.put(o.getID(), o);
Log.trace.print(o.getID() + " ");
// if (!pluginmap.containsKey(o)) {
// System.err.println("MISSING: " + o.getID());
// }
}
Log.trace.println();
}
Aggregations