use of jebl.evolution.trees.RootedTree in project beast-mcmc by beast-dev.
the class TreeSpaceFrame method importDataFile.
public void importDataFile(File file) throws IOException, ImportException {
Reader reader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(reader);
String line = bufferedReader.readLine();
while (line != null && line.length() == 0) {
line = bufferedReader.readLine();
}
if ((line != null && line.toUpperCase().contains("#NEXUS"))) {
int treeCount = 0;
do {
line = bufferedReader.readLine();
} while (line != null && !line.contains("("));
while (line != null) {
if (line.contains("(")) {
treeCount++;
if (treeCount > 1) {
break;
}
}
line = bufferedReader.readLine();
}
// is a NEXUS file
RootedTree tree = importFirstTree(file);
if (tree != null) {
if (treeCount > 1) {
InputFile inputFile = new InputFile(file, tree, -1);
document.addTreeFile(inputFile);
treePlotter.setTrees(loadTrees(inputFile));
inputFile.setTreeCount(treeCount);
document.fireDataChanged();
} else {
InputFile inputFile = new InputFile(file, tree);
document.addTreeFile(inputFile);
treePlotter.setTrees(loadTrees(inputFile));
inputFile.setTreeCount(treeCount);
document.fireDataChanged();
}
}
} else {
JOptionPane.showMessageDialog(this, "Error parsing imported file. This may not be a NEXUS file", "Error reading file", JOptionPane.ERROR_MESSAGE);
}
}
use of jebl.evolution.trees.RootedTree in project beast-mcmc by beast-dev.
the class TreeSpaceFrame method importFirstTree.
// nexus
private RootedTree importFirstTree(File file) throws IOException, ImportException {
RootedTree tree = null;
FileReader reader = new FileReader(file);
NexusImporter importer = new NexusImporter(reader);
tree = (RootedTree) importer.importNextTree();
return tree;
}
use of jebl.evolution.trees.RootedTree 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();
}
use of jebl.evolution.trees.RootedTree in project beast-mcmc by beast-dev.
the class TreeKMLGenerator method main.
public static void main(String[] args) {
String inputTreeFile = args[0];
RootedTree tree = null;
try {
TreeImporter importer = new NexusImporter(new FileReader(inputTreeFile));
tree = (RootedTree) importer.importNextTree();
} catch (ImportException e) {
e.printStackTrace();
return;
} catch (IOException e) {
e.printStackTrace();
return;
}
TreeKMLGenerator generator = new TreeKMLGenerator(tree);
Settings settings = new Settings(AnalysisType.CONTINUOUS);
// settings.getAltitudeTreeSettings().setTreeType(TreeType.ARC_TREE);
// settings.getAltitudeTreeSettings().getBranchStyle().setColorProperty("height");
settings.getGroundTreeSettings().setTreeType(TreeType.SURFACE_TREE);
settings.getGroundTreeSettings().getBranchStyle().setColorProperty("height");
settings.setPlotAltitude(0);
settings.setMostRecentDate(2003);
//settings.setAgeCutOff(1995);
settings.setTimeDivisionCount(0);
settings.setTraitName("antigenic");
settings.setLatitudeName("antigenic1");
settings.setLongitudeName("antigenic2");
try {
BufferedWriter out = new BufferedWriter(new FileWriter(args[0] + ".kml"));
Document doc = new Document(generator.generate(args[0], settings));
try {
XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
outputter.output(doc, out);
} catch (IOException e) {
System.err.println(e);
}
out.close();
} catch (IOException e) {
e.printStackTrace();
return;
}
}
use of jebl.evolution.trees.RootedTree in project beast-mcmc by beast-dev.
the class TreeGeoJSONGenerator method main.
public static void main(String[] args) {
String inputTreeFile = args[0];
RootedTree tree = null;
try {
TreeImporter importer = new NexusImporter(new FileReader(inputTreeFile));
tree = (RootedTree) importer.importNextTree();
} catch (ImportException e) {
e.printStackTrace();
return;
} catch (IOException e) {
e.printStackTrace();
return;
}
TreeGeoJSONGenerator generator = new TreeGeoJSONGenerator(tree, null);
try {
generator.generate("", new PrintWriter(new File("output.geojson")));
} catch (FileNotFoundException e) {
//To change body of catch statement use File | Settings | File Templates.
e.printStackTrace();
}
}
Aggregations