use of beast.core.parameter.RealParameter in project beast2 by CompEvol.
the class EmpiricalSubstitutionModel method getEmpericalFrequencieValues.
/**
* convert empirical frequencies into a RealParameter *
*/
Frequencies getEmpericalFrequencieValues() {
double[] freqs = getEmpiricalFrequencies();
int[] order = getEncodingOrder();
int states = freqs.length;
Frequencies freqsParam = new Frequencies();
String valuesString = "";
for (int i = 0; i < states; i++) {
valuesString += freqs[order[i]] + " ";
}
RealParameter freqsRParam = new RealParameter();
freqsRParam.initByName("value", valuesString, "lower", 0.0, "upper", 1.0, "dimension", states);
freqsParam.frequenciesInput.setValue(freqsRParam, freqsParam);
freqsParam.initAndValidate();
return freqsParam;
}
use of beast.core.parameter.RealParameter in project beast2 by CompEvol.
the class ClusterTree method initAndValidate.
@Override
public void initAndValidate() {
RealParameter clockRate = clockRateInput.get();
if (dataInput.get() != null) {
taxaNames = dataInput.get().getTaxaNames();
} else {
if (m_taxonset.get() == null) {
throw new RuntimeException("At least one of taxa and taxonset input needs to be specified");
}
taxaNames = m_taxonset.get().asStringList();
}
if (Boolean.valueOf(System.getProperty("beast.resume")) && (isEstimatedInput.get() || (m_initial.get() != null && m_initial.get().isEstimatedInput.get()))) {
// don't bother creating a cluster tree to save some time, if it is read from file anyway
// make a caterpillar
Node left = newNode();
left.setNr(0);
left.setID(taxaNames.get(0));
left.setHeight(0);
for (int i = 1; i < taxaNames.size(); i++) {
final Node right = newNode();
right.setNr(i);
right.setID(taxaNames.get(i));
right.setHeight(0);
final Node parent = newNode();
parent.setNr(taxaNames.size() + i - 1);
parent.setHeight(i);
left.setParent(parent);
parent.setLeft(left);
right.setParent(parent);
parent.setRight(right);
left = parent;
}
root = left;
leafNodeCount = taxaNames.size();
nodeCount = leafNodeCount * 2 - 1;
internalNodeCount = leafNodeCount - 1;
super.initAndValidate();
return;
}
distance = distanceInput.get();
if (distance == null) {
distance = new JukesCantorDistance();
}
if (distance instanceof Distance.Base) {
if (dataInput.get() == null) {
// Distance requires an alignment?
}
((Distance.Base) distance).setPatterns(dataInput.get());
}
linkType = clusterTypeInput.get();
if (linkType == Type.upgma)
linkType = Type.average;
if (linkType == Type.neighborjoining || linkType == Type.neighborjoining2) {
distanceIsBranchLength = true;
}
final Node root = buildClusterer();
setRoot(root);
root.labelInternalNodes((getNodeCount() + 1) / 2);
super.initAndValidate();
if (linkType == Type.neighborjoining2) {
// set tip dates to zero
final Node[] nodes = getNodesAsArray();
for (int i = 0; i < getLeafNodeCount(); i++) {
nodes[i].setHeight(0);
}
super.initAndValidate();
}
if (m_initial.get() != null)
processTraits(m_initial.get().m_traitList.get());
else
processTraits(m_traitList.get());
if (timeTraitSet != null)
adjustTreeNodeHeights(root);
else {
// all nodes should be at zero height if no date-trait is available
for (int i = 0; i < getLeafNodeCount(); i++) {
getNode(i).setHeight(0);
}
}
// divide all node heights by clock rate to convert from substitutions to time.
for (Node node : getInternalNodes()) {
double height = node.getHeight();
node.setHeight(height / clockRate.getValue());
}
initStateNodes();
}
use of beast.core.parameter.RealParameter in project beast2 by CompEvol.
the class FrequenciesInputEditor method addComboBox.
// init
@Override
protected /**
* suppress combobox *
*/
void addComboBox(JComponent box, Input<?> input, BEASTInterface beastObject) {
Frequencies freqs = (Frequencies) input.get();
JComboBox<String> comboBox = new JComboBox<>(new String[] { "Estimated", "Empirical", "All equal" });
if (freqs.frequenciesInput.get() != null) {
comboBox.setSelectedIndex(0);
freqsParameter = freqs.frequenciesInput.get();
alignment = (Alignment) getCandidate(freqs.dataInput, freqs);
} else if (freqs.estimateInput.get()) {
comboBox.setSelectedIndex(1);
alignment = freqs.dataInput.get();
freqsParameter = (RealParameter) getCandidate(freqs.frequenciesInput, freqs);
} else {
comboBox.setSelectedIndex(2);
alignment = freqs.dataInput.get();
freqsParameter = (RealParameter) getCandidate(freqs.frequenciesInput, freqs);
}
comboBox.addActionListener(e -> {
// @SuppressWarnings("unchecked")
// JComboBox<String> comboBox = (JComboBox<String>) e.getSource();
int selected = comboBox.getSelectedIndex();
// Frequencies freqs = (Frequencies) m_input.get();
try {
switch(selected) {
case 0:
freqs.frequenciesInput.setValue(freqsParameter, freqs);
freqs.dataInput.setValue(null, freqs);
break;
case 1:
freqs.frequenciesInput.setValue(null, freqs);
freqs.dataInput.setValue(alignment, freqs);
freqs.estimateInput.setValue(true, freqs);
break;
case 2:
freqs.frequenciesInput.setValue(null, freqs);
freqs.dataInput.setValue(alignment, freqs);
freqs.estimateInput.setValue(false, freqs);
break;
}
} catch (Exception e2) {
e2.printStackTrace();
}
// System.err.println(freqs.frequencies.get() + " " + freqs.m_data.get() + " " + freqs.m_bEstimate.get());
});
box.add(comboBox);
}
use of beast.core.parameter.RealParameter in project beast2 by CompEvol.
the class SiteModelInputEditor method processEntry2.
void processEntry2() {
String categories = categoryCountEntry.getText();
try {
int categoryCount = Integer.parseInt(categories);
RealParameter shapeParameter = ((SiteModel) m_input.get()).shapeParameterInput.get();
if (!gammaShapeEditor.getComponent().isVisible() && categoryCount >= 2) {
// we are flipping from no gamma to gamma heterogeneity accross sites
// so set the estimate flag on the shape parameter
shapeParameter.isEstimatedInput.setValue(true, shapeParameter);
} else if (gammaShapeEditor.getComponent().isVisible() && categoryCount < 2) {
// we are flipping from with gamma to no gamma heterogeneity accross sites
// so unset the estimate flag on the shape parameter
shapeParameter.isEstimatedInput.setValue(false, shapeParameter);
}
Object o = ((ParameterInputEditor) gammaShapeEditor).getComponent();
if (o instanceof ParameterInputEditor) {
ParameterInputEditor e = (ParameterInputEditor) o;
e.m_isEstimatedBox.setSelected(shapeParameter.isEstimatedInput.get());
}
gammaShapeEditor.getComponent().setVisible(categoryCount >= 2);
repaint();
} catch (java.lang.NumberFormatException e) {
// ignore.
}
}
use of beast.core.parameter.RealParameter in project beast2 by CompEvol.
the class SiteModelInputEditor method setUpOperator.
/**
* set up relative weights and parameter input *
*/
public void setUpOperator() {
boolean isAllClocksAreEqual = true;
try {
boolean hasOneEstimatedRate = customConnector(doc);
if (doc.autoUpdateFixMeanSubstRate) {
fixMeanRatesCheckBox.setSelected(hasOneEstimatedRate);
doFixMeanRates(hasOneEstimatedRate);
}
try {
double commonClockRate = -1;
CompoundDistribution likelihood = (CompoundDistribution) doc.pluginmap.get("likelihood");
for (Distribution d : likelihood.pDistributions.get()) {
GenericTreeLikelihood treelikelihood = (GenericTreeLikelihood) d;
if (treelikelihood.siteModelInput.get() instanceof SiteModel) {
SiteModel siteModel = (SiteModel) treelikelihood.siteModelInput.get();
RealParameter mutationRate = siteModel.muParameterInput.get();
// clockRate.m_bIsEstimated.setValue(true, clockRate);
if (mutationRate.isEstimatedInput.get()) {
if (commonClockRate < 0) {
commonClockRate = mutationRate.valuesInput.get().get(0);
} else {
if (Math.abs(commonClockRate - mutationRate.valuesInput.get().get(0)) > 1e-10) {
isAllClocksAreEqual = false;
}
}
}
}
}
} catch (Exception e) {
}
List<RealParameter> parameters = operator.parameterInput.get();
if (!fixMeanRatesCheckBox.isSelected()) {
fixMeanRatesValidateLabel.setVisible(false);
repaint();
return;
}
if (parameters.size() == 0) {
fixMeanRatesValidateLabel.setVisible(true);
fixMeanRatesValidateLabel.m_circleColor = Color.red;
fixMeanRatesValidateLabel.setToolTipText("The model is invalid: At least one substitution rate should be estimated.");
repaint();
return;
}
if (!isAllClocksAreEqual) {
fixMeanRatesValidateLabel.setVisible(true);
fixMeanRatesValidateLabel.m_circleColor = Color.orange;
fixMeanRatesValidateLabel.setToolTipText("Not all substitution rates are equal. Are you sure this is what you want?");
} else if (parameters.size() == 1) {
fixMeanRatesValidateLabel.setVisible(true);
fixMeanRatesValidateLabel.m_circleColor = Color.orange;
fixMeanRatesValidateLabel.setToolTipText("At least 2 clock models should have their rate estimated");
} else if (parameters.size() < doc.getPartitions("SiteModel").size()) {
fixMeanRatesValidateLabel.setVisible(true);
fixMeanRatesValidateLabel.m_circleColor = Color.orange;
fixMeanRatesValidateLabel.setToolTipText("Not all partitions have their rate estimated");
} else {
fixMeanRatesValidateLabel.setVisible(false);
}
repaint();
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations