use of beast.core.BEASTInterface in project beast2 by CompEvol.
the class ModelBuilder method setDrawingFlag.
public void setDrawingFlag() {
for (int i = 0; i < m_doc.m_objects.size(); i++) {
Shape shape = m_doc.m_objects.get(i);
shape.m_bNeedsDrawing = false;
if (shape.m_bNeedsDrawing) {
shape.m_bNeedsDrawing = true;
}
if (shape instanceof BEASTObjectShape) {
BEASTInterface beastObject = ((BEASTObjectShape) shape).m_beastObject;
if (needsDrawing(beastObject)) {
shape.m_bNeedsDrawing = true;
}
} else if (shape instanceof InputShape) {
BEASTObjectShape beastObjectShape = ((InputShape) shape).m_beastObjectShape;
if (beastObjectShape != null) {
if (needsDrawing(beastObjectShape.m_beastObject)) {
shape.m_bNeedsDrawing = true;
}
} else {
shape.m_bNeedsDrawing = true;
}
} else if (shape instanceof Arrow) {
Shape tail = ((Arrow) shape).m_tailShape;
boolean needsDrawing = true;
if (tail instanceof BEASTObjectShape) {
needsDrawing = needsDrawing(((BEASTObjectShape) tail).m_beastObject);
}
if (needsDrawing) {
Shape head = ((Arrow) shape).m_headShape;
if (head instanceof InputShape) {
BEASTObjectShape beastObjectShape = ((InputShape) head).m_beastObjectShape;
if (beastObjectShape != null) {
needsDrawing = needsDrawing(beastObjectShape.m_beastObject);
}
}
if (needsDrawing) {
shape.m_bNeedsDrawing = true;
}
}
} else {
shape.m_bNeedsDrawing = true;
}
}
}
use of beast.core.BEASTInterface in project beast2 by CompEvol.
the class ParameterInputEditor method addComboBox.
@Override
protected void addComboBox(JComponent box, Input<?> input, BEASTInterface beastObject) {
Box paramBox = Box.createHorizontalBox();
Parameter.Base<?> parameter = null;
if (itemNr >= 0) {
parameter = (Parameter.Base<?>) ((List<?>) input.get()).get(itemNr);
} else {
parameter = (Parameter.Base<?>) input.get();
}
if (parameter == null) {
super.addComboBox(box, input, beastObject);
} else {
setUpEntry();
paramBox.add(m_entry);
if (doc.allowLinking) {
boolean isLinked = doc.isLinked(m_input);
if (isLinked || doc.suggestedLinks((BEASTInterface) m_input.get()).size() > 0) {
JButton linkbutton = new JButton(Utils.getIcon(BeautiPanel.ICONPATH + (isLinked ? "link.png" : "unlink.png")));
linkbutton.setBorder(BorderFactory.createEmptyBorder());
linkbutton.setToolTipText("link/unlink this parameter with another compatible parameter");
linkbutton.addActionListener(e -> {
if (doc.isLinked(m_input)) {
// unlink
try {
BEASTInterface candidate = doc.getUnlinkCandidate(m_input, m_beastObject);
m_input.setValue(candidate, m_beastObject);
doc.deLink(m_input);
} catch (RuntimeException e2) {
e2.printStackTrace();
JOptionPane.showMessageDialog(this, "Could not unlink: " + e2.getMessage());
}
} else {
// create a link
List<BEASTInterface> candidates = doc.suggestedLinks((BEASTInterface) m_input.get());
JComboBox<BEASTInterface> jcb = new JComboBox<>(candidates.toArray(new BEASTInterface[] {}));
JOptionPane.showMessageDialog(null, jcb, "select parameter to link with", JOptionPane.QUESTION_MESSAGE);
BEASTInterface candidate = (BEASTInterface) jcb.getSelectedItem();
if (candidate != null) {
try {
m_input.setValue(candidate, m_beastObject);
doc.addLink(m_input);
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
refreshPanel();
});
paramBox.add(linkbutton);
}
}
paramBox.add(Box.createHorizontalGlue());
m_isEstimatedBox = new JCheckBox(doc.beautiConfig.getInputLabel(parameter, parameter.isEstimatedInput.getName()));
m_isEstimatedBox.setName(input.getName() + ".isEstimated");
if (input.get() != null) {
m_isEstimatedBox.setSelected(parameter.isEstimatedInput.get());
}
m_isEstimatedBox.setToolTipText(parameter.isEstimatedInput.getHTMLTipText());
boolean isClockRate = false;
for (Object output : parameter.getOutputs()) {
if (output instanceof BranchRateModel.Base) {
isClockRate |= ((BranchRateModel.Base) output).meanRateInput.get() == parameter;
}
}
m_isEstimatedBox.setEnabled(!isClockRate || !getDoc().autoSetClockRate);
m_isEstimatedBox.addActionListener(e -> {
try {
Parameter.Base<?> parameter2 = (Parameter.Base<?>) m_input.get();
parameter2.isEstimatedInput.setValue(m_isEstimatedBox.isSelected(), parameter2);
if (isParametricDistributionParameter) {
String id = parameter2.getID();
if (id.startsWith("RealParameter")) {
ParametricDistribution parent = null;
for (Object beastObject2 : parameter2.getOutputs()) {
if (beastObject2 instanceof ParametricDistribution) {
parent = (ParametricDistribution) beastObject2;
break;
}
}
Distribution grandparent = null;
for (Object beastObject2 : parent.getOutputs()) {
if (beastObject2 instanceof Distribution) {
grandparent = (Distribution) beastObject2;
break;
}
}
id = "parameter.hyper" + parent.getClass().getSimpleName() + "-" + m_input.getName() + "-" + grandparent.getID();
doc.pluginmap.remove(parameter2.getID());
parameter2.setID(id);
doc.addPlugin(parameter2);
}
PartitionContext context = new PartitionContext(id.substring("parameter.".length()));
Log.warning.println(context + " " + id);
doc.beautiConfig.hyperPriorTemplate.createSubNet(context, true);
}
refreshPanel();
} catch (Exception ex) {
Log.err.println("ParameterInputEditor " + ex.getMessage());
}
});
paramBox.add(m_isEstimatedBox);
// only show the estimate flag if there is an operator that works on this parameter
m_isEstimatedBox.setVisible(doc.isExpertMode());
m_isEstimatedBox.setToolTipText("Estimate value of this parameter in the MCMC chain");
// m_bAddButtons = false;
if (itemNr < 0) {
for (Object beastObject2 : ((BEASTInterface) m_input.get()).getOutputs()) {
if (beastObject2 instanceof ParametricDistribution) {
m_isEstimatedBox.setVisible(true);
isParametricDistributionParameter = true;
break;
}
}
for (Object beastObject2 : ((BEASTInterface) m_input.get()).getOutputs()) {
if (beastObject2 instanceof Operator) {
m_isEstimatedBox.setVisible(true);
// m_editPluginButton.setVisible(true);
break;
}
}
} else {
for (Object beastObject2 : ((BEASTInterface) ((List<?>) m_input.get()).get(itemNr)).getOutputs()) {
if (beastObject2 instanceof Operator) {
m_isEstimatedBox.setVisible(true);
// m_editPluginButton.setVisible(true);
break;
}
}
}
box.add(paramBox);
}
}
use of beast.core.BEASTInterface in project beast2 by CompEvol.
the class IntegerListInputEditor method setValue.
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void setValue(Object o) {
if (itemNr < 0) {
m_input.setValue(o, m_beastObject);
} else {
// set value of an item in a list
List list = (List) m_input.get();
Object other = list.get(itemNr);
if (other != o) {
if (other instanceof BEASTInterface) {
BEASTInterface.getOutputs(other).remove(m_beastObject);
}
list.set(itemNr, o);
if (o instanceof BEASTInterface) {
BEASTInterface.getOutputs(o).add(m_beastObject);
}
}
}
}
use of beast.core.BEASTInterface in project MultiTypeTree by tgvaughan.
the class InitMigrationModelConnector method customConnector.
public static boolean customConnector(BeautiDoc doc) {
for (BEASTInterface p : doc.getPartitions("Tree")) {
TreeLikelihood treeLikelihood = (TreeLikelihood) p;
StructuredCoalescentMultiTypeTree tree = (StructuredCoalescentMultiTypeTree) treeLikelihood.treeInput.get();
String pID = BeautiDoc.parsePartition(tree.getID());
SCMigrationModel migModel = (SCMigrationModel) doc.pluginmap.get("migModel.t:" + pID);
SCMigrationModel migModelInit = (SCMigrationModel) doc.pluginmap.get("migModelInit.t:" + pID);
String rateMatrixStr = getParameterString((RealParameter) migModel.rateMatrixInput.get());
String popSizesStr = getParameterString((RealParameter) migModel.popSizesInput.get());
// Ensure model has appropriate number of demes
int uniqueTraitCount = uniqueTraitsInData(tree).size();
StringBuilder rateMatrixStrBuilder = new StringBuilder();
StringBuilder popSizesStrBuilder = new StringBuilder();
migModel.getTypeSet().initAndValidate();
if (migModel.popSizesInput.get().getDimension() != migModel.getNTypes()) {
for (int i = 0; i < migModel.getNTypes(); i++) {
popSizesStrBuilder.append(" 1.0");
for (int j = 0; j < migModel.getNTypes(); j++) {
if (j == i)
continue;
rateMatrixStrBuilder.append(" 1.0");
}
}
popSizesStr = popSizesStrBuilder.toString();
rateMatrixStr = rateMatrixStrBuilder.toString();
((RealParameter) migModel.popSizesInput.get()).setDimension(migModel.getNTypes());
((RealParameter) migModel.popSizesInput.get()).valuesInput.setValue(popSizesStr, (RealParameter) migModel.popSizesInput.get());
((RealParameter) migModel.rateMatrixInput.get()).setDimension(migModel.getNTypes() * (migModel.getNTypes() - 1));
((RealParameter) migModel.rateMatrixInput.get()).valuesInput.setValue(rateMatrixStr, (RealParameter) migModel.rateMatrixInput.get());
((RealParameter) migModel.popSizesInput.get()).initAndValidate();
((RealParameter) migModel.rateMatrixInput.get()).initAndValidate();
migModel.initAndValidate();
}
((RealParameter) migModelInit.popSizesInput.get()).setDimension(migModel.getNTypes());
((RealParameter) migModelInit.popSizesInput.get()).valuesInput.setValue(popSizesStr, (RealParameter) migModelInit.popSizesInput.get());
((RealParameter) migModelInit.rateMatrixInput.get()).setDimension(migModel.getNTypes() * (migModel.getNTypes() - 1));
((RealParameter) migModelInit.rateMatrixInput.get()).valuesInput.setValue(rateMatrixStr, (RealParameter) migModelInit.rateMatrixInput.get());
try {
((RealParameter) migModelInit.popSizesInput.get()).initAndValidate();
((RealParameter) migModelInit.rateMatrixInput.get()).initAndValidate();
migModelInit.initAndValidate();
} catch (Exception ex) {
System.err.println("Error configuring initial migration model.");
}
}
return false;
}
use of beast.core.BEASTInterface in project bacter by tgvaughan.
the class CustomConnectors method applyRestrictions.
public static void applyRestrictions(BeautiDoc doc) {
for (BEASTInterface p : doc.getPartitions("Tree")) {
ACGLikelihood acgLikelihood = (ACGLikelihood) p;
SimulatedACG acg = (SimulatedACG) ((ACGLikelihood) p).treeInput.get();
ACGCoalescent coalescent = null;
for (BEASTInterface output : acg.getOutputs()) {
if (output instanceof ACGCoalescent) {
coalescent = (ACGCoalescent) output;
break;
}
}
if (coalescent == null)
continue;
acg.setWholeLocusMode(coalescent.wholeLocusConversionsInput.get());
}
}
Aggregations