Skip to content

Commit

Permalink
clean up tests + templates #6
Browse files Browse the repository at this point in the history
  • Loading branch information
rbouckaert committed Oct 4, 2022
1 parent 1164eea commit 9260d06
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 26 deletions.
25 changes: 17 additions & 8 deletions fxtemplates/ClockModels.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@
<operator id='StrictClockRateScaler.c:$(n)' spec='kernel.BactrianScaleOperator' scaleFactor="0.1" weight="3" parameter='@clockRate.c:$(n)'/>
<upDownOperator id='strictClockUpDownOperator.c:$(n)' spec='kernel.BactrianUpDownOperator' scaleFactor="0.1" weight="3">
<up idref="clockRate.c:$(n)"/>
<down idref="Tree.t:$(n)"/>
</upDownOperator>
<operator id="strictClockUpDownOperator.c:$(n)" spec="beast.base.evolution.operator.AdaptableOperatorSampler" weight="1.5">
<parameter idref="clockRate.c:$(n)"/>
<tree idref="Tree.t:$(n)"/>
<operator idref="AVMNOperator.$(n)"/>
<operator id='strictClockUpDownOperatorX.c:$(n)' spec='kernel.BactrianUpDownOperator' scaleFactor="0.75" weight="3">
<up idref="clockRate.c:$(n)"/>
<down idref="Tree.t:$(n)"/>
</operator>
</operator>
<prior id='ClockPrior.c:$(n)' x='@clockRate.c:$(n)'>
<Gamma name="distr">
Expand All @@ -33,6 +38,8 @@
]]>
<connect srcID='clockRate.c:$(n)' targetID='state' inputName='stateNode'
if='inlikelihood(clockRate.c:$(n)) and clockRate.c:$(n)/estimate=true'/>
<connect srcID='clockRate.c:$(n)' targetID='AVMNLogTransform.$(n)' inputName='f'
if='inlikelihood(clockRate.c:$(n)) and clockRate.c:$(n)/estimate=true'/>
<connect srcID='ClockPrior.c:$(n)' targetID='prior' inputName='distribution'
if='inlikelihood(clockRate.c:$(n)) and clockRate.c:$(n)/estimate=true'>substitution rate of
partition c:$(n)
Expand All @@ -42,7 +49,7 @@
partition c:$(n)
</connect>
<connect srcID='strictClockUpDownOperator.c:$(n)' targetID='mcmc' inputName='operator'
if='nooperator(FixMeanRatesOperator) and inlikelihood(clockRate.c:$(n)) and inlikelihood(Tree.t:$(n)) and Tree.t:$(n)/estimate=true and clockRate.c:$(n)/estimate=true'>
if='inlikelihood(clockRate.c:$(n)) and clockRate.c:$(n)/estimate=true and inlikelihood(Tree.t:$(n)) and Tree.t:$(n)/estimate=true'>
Scale up substitution rate c:$(n) and scale down tree t:$(n)
</connect>
</subtemplate>
Expand Down Expand Up @@ -77,10 +84,10 @@
<operator id='ClockRateScaler.c:$(n)' spec='kernel.BactrianScaleOperator' scaleAll='false' scaleFactor="0.1" weight="15" parameter="@clockrates.c:$(n)"/>
<operator id='randomClockScaler.c:$(n)' spec='kernel.BactrianScaleOperator' scaleAll='false' scaleFactor="0.1" weight="1" parameter="@meanClockRate.c:$(n)"/>
<upDownOperator id='randomClockUpDownOperator.c:$(n)' spec='kernel.BactrianUpDownOperator' scaleFactor="0.1" weight="3">
<operator id='randomClockUpDownOperator.c:$(n)' spec='kernel.BactrianUpDownOperator' scaleFactor="0.1" weight="3">
<up idref="meanClockRate.c:$(n)"/>
<down idref="Tree.t:$(n)"/>
</upDownOperator>
</operator>
<distribution idref="prior">
<if cond='inlikelihood(RandomLocalClock.c:$(n))'>
Expand Down Expand Up @@ -119,6 +126,8 @@
if='inlikelihood(Indicators.c:$(n))'/>
<connect srcID='meanClockRate.c:$(n)' targetID='state' inputName='stateNode'
if='inlikelihood(meanClockRate.c:$(n)) and meanClockRate.c:$(n)/estimate=true'/>
<connect srcID='meanClockRate.c:$(n)' targetID='AVMNLogTransform.$(n)' inputName='f'
if='inlikelihood(clockRate.c:$(n)) and clockRate.c:$(n)/estimate=true'/>
<connect srcID='clockrates.c:$(n)' targetID='state' inputName='stateNode'
if='inlikelihood(clockrates.c:$(n))'/>

Expand All @@ -128,7 +137,7 @@
partition c:$(n)
</connect>
<connect srcID='randomClockUpDownOperator.c:$(n)' targetID='mcmc' inputName='operator'
if='nooperator(FixMeanRatesOperator) and inlikelihood(meanClockRate.c:$(n)) and inlikelihood(Tree.t:$(n)) and meanClockRate.c:$(n)/estimate=true'>
if='inlikelihood(meanClockRate.c:$(n)) and inlikelihood(Tree.t:$(n)) and Tree.t:$(n)/esimate=true and meanClockRate.c:$(n)/estimate=true'>
Up/down scaler for mean rate and tree of partition c:$(n)
</connect>
<connect srcID='IndicatorsBitFlip.c:$(n)' targetID='mcmc' inputName='operator'
Expand Down
4 changes: 2 additions & 2 deletions fxtemplates/Standard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ ClusterTree/clusterType/,
<operator id='StrictClockRateScalerX.c:$(n)' spec='kernel.BactrianScaleOperator' scaleFactor="0.75" weight="3" parameter='@clockRate.c:$(n)'/>
</operator>
<operator id="strictClockUpDownOperator.s:$(n)" spec="beast.base.evolution.operator.AdaptableOperatorSampler" weight="1.5">
<operator id="strictClockUpDownOperator.c:$(n)" spec="beast.base.evolution.operator.AdaptableOperatorSampler" weight="1.5">
<parameter idref="clockRate.c:$(n)"/>
<tree idref="Tree.t:$(n)"/>
<operator idref="AVMNOperator.$(n)"/>
Expand Down Expand Up @@ -402,7 +402,7 @@ ClusterTree/clusterType/,
<connect srcID='StrictClockRateScaler.c:$(n)' targetID='mcmc' inputName='operator' if='inlikelihood(clockRate.c:$(n)) and clockRate.c:$(n)/estimate=true'>Scale clock rate of partition c:$(n)</connect>
<connect srcID='YuleBirthRateScaler.t:$(n)' targetID='mcmc' inputName='operator' if='inposterior(birthRate.t:$(n)) and birthRate.t:$(n)/estimate=true'>Scales birth rate of Yule prior for partition t:$(n)</connect>
<connect srcID='strictClockUpDownOperator.c:$(n)' targetID='mcmc' inputName='operator'
if='nooperator(FixMeanRatesOperator) and inlikelihood(clockRate.c:$(n)) and inlikelihood(Tree.t:$(n)) and Tree.t:$(n)/estimate=true and clockRate.c:$(n)/estimate=true'>
if='inlikelihood(clockRate.c:$(n)) and inlikelihood(Tree.t:$(n)) and Tree.t:$(n)/estimate=true and clockRate.c:$(n)/estimate=true'>
Scale up substitution rate c:$(n) and scale down tree t:($n)
</connect>

Expand Down
3 changes: 2 additions & 1 deletion src/test/beastfx/app/beauti/BeautiBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
*
*/
@ExtendWith(ApplicationExtension.class)
public class BeautiBase extends Beauti {
public class BeautiBase extends ApplicationExtension {
final static String TEMPLATE_DIR = BeautiConfig.TEMPLATE_DIR;
final static String NEXUS_DIR = "../beast2/examples/nexus/";

Expand All @@ -92,6 +92,7 @@ public class BeautiBase extends Beauti {

public BeautiBase() {
// make sure BEAST.base and BEAST.app are installed
System.setProperty("beast.is.junit.testing", "true");
try {
Set<String> packages = listInstalledPackages();
if (!packages.contains("BEAST.base")) {
Expand Down
18 changes: 17 additions & 1 deletion src/test/beastfx/app/beauti/BeautiCLITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,29 @@
import java.io.PrintStream;

import org.junit.jupiter.api.Test;
import org.testfx.framework.junit5.Start;

import beastfx.app.beauti.Beauti;
import beastfx.app.beauti.BeautiTabPane;
import beastfx.app.inputeditor.BeautiDoc;
import javafx.stage.Stage;

public class BeautiCLITest {
public class BeautiCLITest extends BeautiBase {

BeautiDoc doc;

@Start
public void start(Stage stage) {
try {
System.setProperty("beast.is.junit.testing", "true");
BeautiTabPane tabPane = BeautiTabPane.main2(new String[] {}, stage);
this.doc = tabPane.doc;
stage.show();
} catch (Exception e) {
e.printStackTrace();
}
}

public static void setUpTestDir() {
// make sure output goes to test directory
File testDir = new File("./test");
Expand Down
3 changes: 2 additions & 1 deletion src/test/beastfx/app/beauti/BeautiDivergenceDatingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void start(Stage stage) {
}
}

final static String PREFIX = "doc/tutorials/DivergenceDating/figures/BEAUti_";
final static String PREFIX = "../beast2/doc/tutorials/DivergenceDating/figures/BEAUti_";

@Test
public void DivergenceDatingTutorial(FxRobot robot) throws Exception {
Expand Down Expand Up @@ -261,6 +261,7 @@ public void DivergenceDatingTutorial(FxRobot robot) throws Exception {
robot.clickOn("#listOfTaxonCandidates").clickOn("Homo_sapiens");
clickOnButtonWithText(robot, ">>");
robot.clickOn("#listOfTaxonCandidates").clickOn("Pan");
clickOnButtonWithText(robot, ">>");
// dialog.list("listOfTaxonCandidates").selectItems("Homo_sapiens", "Pan");
// dialog.button(">>").click();
// dialog.okButton().click();
Expand Down
2 changes: 1 addition & 1 deletion src/test/beastfx/app/beauti/BeautiRateTutorialTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void start(Stage stage) {
}
// file used to store, then reload xml
final static String XML_FILE = "rsv.xml";
final static String PREFIX = "doc/tutorials/MEPs/figures/generated/BEAUti_";
final static String PREFIX = "../beast2/doc/tutorials/MEPs/figures/generated/BEAUti_";

@Test
public void MEPTutorial(FxRobot robot) throws Exception {
Expand Down
2 changes: 1 addition & 1 deletion src/test/beastfx/app/beauti/BeautiStarBeastTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void start(Stage stage) {
}
}

final static String PREFIX = "doc/tutorials/STARBEAST/figures/BEAUti_";
final static String PREFIX = "../beast2/doc/tutorials/STARBEAST/figures/BEAUti_";

@Test
public void simpleStarBeastTest(FxRobot robot) throws Exception {
Expand Down
11 changes: 6 additions & 5 deletions src/test/beastfx/app/beauti/FixedMeanRateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.testfx.framework.junit5.Start;

import beast.base.inference.operator.DeltaExchangeOperator;
import beast.base.inference.operator.kernel.BactrianDeltaExchangeOperator;
import beastfx.app.beauti.BeautiTabPane;
import javafx.stage.Stage;

Expand All @@ -23,6 +24,7 @@ public class FixedMeanRateTest extends BeautiBase {
@Start
public void start(Stage stage) {
try {
System.setProperty("beast.is.junit.testing", "true");
BeautiTabPane tabPane = BeautiTabPane.main2(new String[] {}, stage);
this.doc = tabPane.doc;
stage.show();
Expand All @@ -32,8 +34,7 @@ public void start(Stage stage) {
}

@Test
public void testFixedMeanRate(FxRobot robot) throws Exception {

public void testFixedMeanRate(FxRobot robot) throws Exception {
importAlignment(NEXUS_DIR, new File("26.nex"), new File("29.nex"));

robot.clickOn("#Mode").clickOn("#autoUpdateFixMeanSubstRate");
Expand All @@ -58,7 +59,7 @@ public void testFixedMeanRate(FxRobot robot) throws Exception {



DeltaExchangeOperator operator = (DeltaExchangeOperator) doc.pluginmap.get("FixMeanMutationRatesOperator");
BactrianDeltaExchangeOperator operator = (BactrianDeltaExchangeOperator) doc.pluginmap.get("FixMeanMutationRatesOperator");
int nrOfParameters = operator.parameterInput.get().size();
if(nrOfParameters != 2) {
throw new IllegalArgumentException("Expected 2 parameters for deltaExchangeOperator, not " + nrOfParameters);
Expand All @@ -81,7 +82,7 @@ public void testFixedMeanRateSharedSiteModel(FxRobot robot) throws Exception {
clickOnButtonWithText(robot, "Link Site Models");
clickOnButtonWithText(robot, "Unlink Site Models");

DeltaExchangeOperator operator = (DeltaExchangeOperator) doc.pluginmap.get("FixMeanMutationRatesOperator");
BactrianDeltaExchangeOperator operator = (BactrianDeltaExchangeOperator) doc.pluginmap.get("FixMeanMutationRatesOperator");
int nrOfParameters = operator.parameterInput.get().size();
if (nrOfParameters != 3) {
throw new IllegalArgumentException("Expected 3 parameters for deltaExchangeOperator, not " + nrOfParameters);
Expand All @@ -96,7 +97,7 @@ public void testFixedMeanRateSharedSiteModel(FxRobot robot) throws Exception {
selectPartitions(robot, 0, 2);
// beautiFrame.table().selectCells(TableCell.row(0).column(1), TableCell.row(2).column(1));
clickOnButtonWithText(robot, "Link Site Models");
operator = (DeltaExchangeOperator) doc.pluginmap.get("FixMeanMutationRatesOperator");
operator = (BactrianDeltaExchangeOperator) doc.pluginmap.get("FixMeanMutationRatesOperator");
nrOfParameters = operator.parameterInput.get().size();

//SiteModelInputEditor.customConnector(doc);
Expand Down
12 changes: 6 additions & 6 deletions src/test/beastfx/app/beauti/LinkUnlinkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public void linkSiteModelsAndDeleteTest(FxRobot robot) throws Exception {
//JComboBoxFixture substModel = beautiFrame.comboBox("substModel");
//substModel.selectItem("HKY");
printBeautiState();
assertParameterCountInPriorIs(5+2);
assertParameterCountInPriorIs(5+3);

selectTab(robot, "Partitions");
warning("Link site models");
Expand All @@ -322,19 +322,19 @@ public void linkSiteModelsAndDeleteTest(FxRobot robot) throws Exception {
printBeautiState();

selectPartitions(robot, 0, 1, 2);
assertParameterCountInPriorIs(5+2);
assertParameterCountInPriorIs(5+3);
clickOnButtonWithText(robot, "Unlink Site Models");

printBeautiState();
assertParameterCountInPriorIs(9+6);
assertParameterCountInPriorIs(9+9);

warning("Delete second partition");
selectTab(robot, "Partitions");
selectPartitions(robot, 1);
clickOnButtonWithText(robot, "-");
printBeautiState();

assertParameterCountInPriorIs(6+4);
assertParameterCountInPriorIs(6+6);

warning("Delete first partition");
selectTab(robot, "Partitions");
Expand All @@ -344,7 +344,7 @@ public void linkSiteModelsAndDeleteTest(FxRobot robot) throws Exception {
clickOnButtonWithText(robot, "-");
printBeautiState();
assertPriorsEqual("YuleModel.t:26", "YuleBirthRatePrior.t:26", "KappaPrior.s:59", "FrequenciesPrior.s:59");
assertParameterCountInPriorIs(3+2);
assertParameterCountInPriorIs(3+3);

makeSureXMLParses();
}
Expand Down Expand Up @@ -429,7 +429,7 @@ public void linkClocksAndDeleteTest(FxRobot robot) throws Exception {
}

@Test
public void linkSiteModelssAndDeleteTest(FxRobot robot) throws Exception {
public void linkSiteModelsAndDeleteTest2(FxRobot robot) throws Exception {
warning("Load gopher data 26.nex, 47.nex, 59.nex");
importAlignment(NEXUS_DIR, new File("26.nex"), new File("47.nex"), new File("59.nex"));

Expand Down

0 comments on commit 9260d06

Please sign in to comment.