Skip to content

Commit

Permalink
issue #4 add button to BEAUti for pre-calc mu rates
Browse files Browse the repository at this point in the history
  • Loading branch information
rbouckaert committed May 4, 2015
1 parent cc059e6 commit e9decd8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
27 changes: 26 additions & 1 deletion src/beast/app/draw/SNAPPTreeLikelihoodEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
import java.util.List;

import javax.swing.Box;
import javax.swing.JButton;

import beast.app.beauti.BeautiDoc;
import beast.app.draw.InputEditor;
import beast.app.draw.ListInputEditor;
import beast.app.draw.ParameterInputEditor;
import beast.core.BEASTInterface;
import beast.core.Input;
import beast.core.parameter.RealParameter;
import beast.evolution.sitemodel.SiteModel;
import snap.Data;
import snap.likelihood.SnAPTreeLikelihood;
import snap.likelihood.SnapSubstitutionModel;

Expand All @@ -26,6 +29,8 @@ public Class<?> baseType() {
}

SnapSubstitutionModel substModel;
Data data;
JButton muButton;

@Override
public void init(Input<?> input, BEASTInterface plugin, int itemNr, ExpandOption bExpand, boolean bAddButtons) {
Expand All @@ -40,17 +45,37 @@ public void init(Input<?> input, BEASTInterface plugin, int itemNr, ExpandOption
for (Object o : (List<?>) input.get()) {
if (o instanceof SnAPTreeLikelihood) {
SnAPTreeLikelihood plugin2 = (SnAPTreeLikelihood) o;
if (plugin2.dataInput.get() instanceof Data) {
data = (Data) plugin2.dataInput.get();
}
substModel = (SnapSubstitutionModel) ((SiteModel.Base) plugin2.siteModelInput.get()).substModelInput.get();
doc.getInputEditorFactory().addInputs(m_listBox, substModel, this, null, doc);
doc.getInputEditorFactory().addInputs(m_listBox, plugin2, this, null, doc);
muButton = new JButton("Calc mutation rates");
muButton.setToolTipText("Calcaulate mutation rates based on data in the alignment");
muButton.addActionListener(e -> setUpMutationRates());
add(muButton);
}
}
add(m_listBox);
updateState();
}


public InputEditor createMutationRateVEditor() throws Exception {
private Object setUpMutationRates() {
double proportionZeros = data.getProportionZeros();
double muU = 1 / (2.0 * proportionZeros);
double muV = 1 / (2.0 * (1.0- proportionZeros));
RealParameter pU = substModel.m_pU.get();
pU.valuesInput.setValue(muU + "", pU);
RealParameter pV = substModel.m_pV.get();
pV.valuesInput.setValue(muV + "", pV);
refreshPanel();
return null;
}


public InputEditor createMutationRateVEditor() throws Exception {
ParameterInputEditor editor = (ParameterInputEditor) doc.getInputEditorFactory().createInputEditor(substModel.m_pV, substModel, doc);
editor.m_isEstimatedBox.setVisible(false);
return editor;
Expand Down
13 changes: 7 additions & 6 deletions templates/SNAPP.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
snap.likelihood.SnAPTreeLikelihood.useAmbiguities,
snap.likelihood.SnAPTreeLikelihood.tree,
snap.likelihood.SnAPTreeLikelihood.dominant,
snap.likelihood.SnAPTreeLikelihood.ascSiteCount,
snap.likelihood.SnAPPrior.coalescenceRate
'
buttonLabelMap='beast.app.beauti.BeautiInitDlg.&gt;&gt; details=Edit parameters,
Expand Down Expand Up @@ -138,12 +139,12 @@
</tree>
<parameter name='coalescenceRate' id='coalescenceRate' value='10'/>
</distribution>
<distribution id='alphaPrior.$(n)' spec='Prior' x='@alpha'><distr spec='OneOnX'/></distribution>
<distribution id='betaPrior.$(n)' spec='Prior' x='@beta'><distr spec='OneOnX'/></distribution>
<distribution id='lambdaPrior.$(n)' spec='Prior' x='@lambda'><distr spec='OneOnX'/></distribution>
<distribution id='kappaPrior.$(n)' spec='Prior' x='@kappa'><distr spec='OneOnX'/></distribution>
<distribution id='uPrior.$(n)' spec='Prior' x='@u'><distr spec='OneOnX'/></distribution>
<distribution id='vPrior.$(n)' spec='Prior' x='@v'><distr spec='OneOnX'/></distribution>
<distribution id='alphaPrior.$(n)' spec='beast.math.distributions.Prior' x='@alpha'><distr spec='OneOnX'/></distribution>
<distribution id='betaPrior.$(n)' spec='beast.math.distributions.Prior' x='@beta'><distr spec='OneOnX'/></distribution>
<distribution id='lambdaPrior.$(n)' spec='beast.math.distributions.Prior' x='@lambda'><distr spec='OneOnX'/></distribution>
<distribution id='kappaPrior.$(n)' spec='beast.math.distributions.Prior' x='@kappa'><distr spec='OneOnX'/></distribution>
<distribution id='uPrior.$(n)' spec='beast.math.distributions.Prior' x='@u'><distr spec='OneOnX'/></distribution>
<distribution id='vPrior.$(n)' spec='beast.math.distributions.Prior' x='@v'><distr spec='OneOnX'/></distribution>
<snaptreelikelihood spec='snap.likelihood.SnAPTreeLikelihood' name='distribution' id='treeLikelihood.$(n)' initFromTree='false' pattern='coalescenceRate' non-polymorphic='true'>
Expand Down

0 comments on commit e9decd8

Please sign in to comment.