use of beast.util.XMLParser in project bacter by tgvaughan.
the class SimulatedACGTest method test5TaxonDynamicPopSize.
@Test
public void test5TaxonDynamicPopSize() throws Exception {
Randomizer.setSeed(1);
XMLParser parser = new XMLParser();
beast.core.Runnable runnable = parser.parseFile(new File("examples/ACGsimulations/simulateACGs5taxonDynamicPopSize.xml"));
runnable.run();
List<Expectation> expectations = new ArrayList<>();
expectations.add(new Expectation("acg.CFheight", 8.840, 1e-2));
expectations.add(new Expectation("acg.CFlength", 25.312, 1e-2));
expectations.add(new Expectation("acg.nConv", 25.464, 5e-2));
LogAnalyser logAnalyser = new LogAnalyser("simulateACGs5taxonDynamicPopSize.stats", expectations);
for (int i = 0; i < expectations.size(); i++) {
assertTrue(expectations.get(i).isValid());
assertTrue(expectations.get(i).isPassed());
}
Files.deleteIfExists(Paths.get("simulateACGs5taxonDynamicPopSize.stats"));
Files.deleteIfExists(Paths.get("simulateACGs5taxonDynamicPopSize.converted"));
Files.deleteIfExists(Paths.get("simulateACGs5taxonDynamicPopSize.trees"));
}
use of beast.util.XMLParser in project bacter by tgvaughan.
the class DensityCalculator method main.
public static void main(String[] args) {
if (args.length < 2) {
System.out.println("Usage: DensityCalculator BEAST_xml_file state_file");
System.exit(0);
}
XMLParser parser = new XMLParser();
beast.core.Runnable runnable = null;
try {
runnable = parser.parseFile(new File(args[0]));
} catch (Exception e) {
System.out.println("Encountered error while loading/parsing XML file.");
e.printStackTrace();
}
if (runnable == null)
System.exit(1);
if (!(runnable instanceof MCMC)) {
System.out.println("XML file does not seem to describe an MCMC analysis.");
System.exit(1);
}
MCMC mcmc = (MCMC) runnable;
Distribution posterior = mcmc.posteriorInput.get();
State state = mcmc.startStateInput.get();
state.setStateFileName(args[1]);
try {
state.restoreFromFile();
} catch (Exception e) {
System.out.println("Error reading state from file.");
e.printStackTrace();
System.exit(1);
}
try {
state.robustlyCalcPosterior(posterior);
} catch (Exception e) {
e.printStackTrace();
}
reportTargetDensities(posterior);
}
use of beast.util.XMLParser in project bacter by tgvaughan.
the class OperatorTester method main.
public static void main(String[] args) {
if (args.length < 4) {
System.out.println("Usage: OperatorTester model.xml operator_ID state_file iterations");
System.exit(0);
}
String modelFileName = args[0];
String operatorID = args[1];
String stateFileName = args[2];
int Niter = Integer.parseInt(args[3]);
XMLParser xmlParser = new XMLParser();
Runnable runnable = null;
try {
runnable = xmlParser.parseFile(new File(modelFileName));
} catch (Exception e) {
System.out.println("Error parsing model XML file.");
e.printStackTrace();
}
if (runnable == null)
System.exit(1);
if (!(runnable instanceof MCMC)) {
System.out.println("XML file does not describe MCMC analysis.");
System.exit(1);
}
MCMC mcmc = (MCMC) runnable;
Operator operator = null;
for (Operator thisOperator : mcmc.operatorsInput.get()) {
if (thisOperator.getID().equals(operatorID)) {
operator = thisOperator;
break;
}
}
if (operator == null) {
System.out.println("Model does not include operator with ID " + operatorID + ".");
System.exit(1);
}
State state = mcmc.startStateInput.get();
state.setStateFileName(stateFileName);
try {
state.restoreFromFile();
} catch (Exception e) {
System.out.println("Error loading state from file.");
e.printStackTrace();
System.exit(1);
}
try {
state.robustlyCalcPosterior(mcmc.posteriorInput.get());
} catch (Exception e) {
System.out.println("Failed to calculate posterior.");
System.exit(1);
}
Logger.FILE_MODE = Logger.LogFileMode.overwrite;
for (Logger logger : mcmc.loggersInput.get()) {
try {
logger.everyInput.setValue(1, logger);
logger.initAndValidate();
logger.init();
logger.log(0);
} catch (Exception e) {
System.out.println("Error initializing logger.");
System.exit(1);
}
}
try {
state.robustlyCalcPosterior(mcmc.posteriorInput.get());
} catch (Exception e) {
System.out.println("Failed to calculate posterior.");
System.exit(1);
}
state.storeCalculationNodes();
for (int i = 1; i < Niter; i++) {
state.store(i);
// for (Logger logger : mcmc.loggersInput.get())
// logger.log(i);
Double hgf = operator.proposal();
if (hgf > Double.NEGATIVE_INFINITY) {
state.checkCalculationNodesDirtiness();
try {
mcmc.posteriorInput.get().calculateLogP();
} catch (Exception e) {
System.out.println("Failed to calculate posterior.");
System.exit(1);
}
for (Logger logger : mcmc.loggersInput.get()) logger.log(i);
state.restore();
state.restoreCalculationNodes();
state.setEverythingDirty(false);
} else {
state.restore();
}
}
for (Logger logger : mcmc.loggersInput.get()) logger.close();
}
use of beast.util.XMLParser in project bacter by tgvaughan.
the class AddRemoveRedundantTest method test5Taxon.
@Test
public void test5Taxon() throws Exception {
Randomizer.setSeed(1);
XMLParser parser = new XMLParser();
beast.core.Runnable runnable = parser.parseFile(new File("examples/addRemoveTests/addRemoveRedundantTest5taxon.xml"));
disableScreenLog(runnable);
runnable.run();
List<Expectation> expectations = new ArrayList<>();
expectations.add(new Expectation("acg.CFheight", 1.606, 0.2));
expectations.add(new Expectation("acg.CFlength", 4.181, 0.5));
expectations.add(new Expectation("acg.nConv", 21.0, 0.5));
LogAnalyser logAnalyser = new LogAnalyser("addRemoveRedundantTest5taxon.stats", expectations);
for (int i = 0; i < expectations.size(); i++) {
assertTrue(expectations.get(i).isValid());
assertTrue(expectations.get(i).isPassed());
}
Files.deleteIfExists(Paths.get("addRemoveRedundantTest5taxon.stats"));
Files.deleteIfExists(Paths.get("addRemoveRedundantTest5taxon.converted"));
Files.deleteIfExists(Paths.get("addRemoveRedundantTest5taxon.trees"));
Files.deleteIfExists(Paths.get("addRemoveRedundantTest5taxon.cf"));
Files.deleteIfExists(Paths.get("addRemoveRedundantTest5taxon.xml.state"));
}
use of beast.util.XMLParser in project bacter by tgvaughan.
the class AddRemoveTest method test5TaxonSerialSampling.
@Test
public void test5TaxonSerialSampling() throws Exception {
Randomizer.setSeed(1);
XMLParser parser = new XMLParser();
beast.core.Runnable runnable = parser.parseFile(new File("examples/addRemoveTests/addRemoveSerialSamplingTest5taxon.xml"));
disableScreenLog(runnable);
runnable.run();
List<Expectation> expectations = new ArrayList<>();
expectations.add(new Expectation("acg.CFheight", 2.07, 0.1));
expectations.add(new Expectation("acg.CFlength", 5.00, 0.2));
expectations.add(new Expectation("acg.nConv", 25.190, 1.0));
LogAnalyser logAnalyser = new LogAnalyser("addRemoveSerialSamplingTest5taxon.stats", expectations);
for (Expectation expectation : expectations) {
assertTrue(expectation.isValid());
assertTrue(expectation.isPassed());
}
Files.deleteIfExists(Paths.get("addRemoveSerialSamplingTest5taxon.stats"));
Files.deleteIfExists(Paths.get("addRemoveSerialSamplingTest5taxon.converted"));
Files.deleteIfExists(Paths.get("addRemoveSerialSamplingTest5taxon.trees"));
Files.deleteIfExists(Paths.get("addRemoveSerialSamplingTest5taxon.cf"));
Files.deleteIfExists(Paths.get("addRemoveSerialSamplingTest5taxon.xml.state"));
}
Aggregations