use of jebl.evolution.io.NewickExporter in project beast-mcmc by beast-dev.
the class CoalGenApp method simulate.
public static void simulate(String inputFileName, String treesFileName, String outputFileName) throws IOException, TraceException, Importer.ImportException {
File logFile = new File(inputFileName);
System.out.println("Loading trace file: " + inputFileName);
LogFileTraces traces = new LogFileTraces(inputFileName, logFile);
traces.loadTraces();
traces.setBurnIn(0);
System.out.println(traces.getStateCount() + " states loaded");
System.out.println();
System.out.println("Opening trees file: " + treesFileName);
// BufferedReader reader = new BufferedReader(new FileReader(treesFileName));
System.out.println("Simulating...");
System.out.println("0 25 50 75 100");
System.out.println("|--------------|--------------|--------------|--------------|");
int stepSize = traces.getStateCount() / 60;
if (stepSize < 1)
stepSize = 1;
PrintWriter writer = new PrintWriter(new FileWriter(outputFileName));
FileReader fileReader = new FileReader(treesFileName);
TreeImporter importer = new NexusImporter(fileReader);
EmpiricalDemographicFunction demo = null;
IntervalGenerator intervals = null;
TreeSimulator sim = null;
CoalGenData data = new CoalGenData();
data.traces = traces;
// const stepwise bsp
data.setDemographicModel(7);
data.setupSkyline();
double[] popSizes = new double[data.popSizeCount];
double[] groupSizes = new double[data.groupSizeCount];
NewickExporter exporter = new NewickExporter(writer);
int count = 0;
try {
while (importer.hasTree()) {
RootedTree inTree = (RootedTree) importer.importNextTree();
if (sim == null) {
setSamplingTimes(inTree);
sim = new TreeSimulator(inTree.getTaxa(), "date");
}
data.getNextSkyline(popSizes, groupSizes);
double[] times = getTimes(inTree, groupSizes);
demo = new EmpiricalDemographicFunction(popSizes, times, true);
intervals = new CoalescentIntervalGenerator(demo);
RootedTree outTree = sim.simulate(intervals);
exporter.exportTree(outTree);
writer.println();
writer.flush();
if (count > 0 && count % stepSize == 0) {
System.out.print("*");
System.out.flush();
}
count++;
}
} catch (ImportException e) {
e.printStackTrace();
}
fileReader.close();
writer.close();
}
Aggregations