use of jebl.evolution.io.NexusImporter 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.io.NexusImporter 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();
}
}
use of jebl.evolution.io.NexusImporter in project beast-mcmc by beast-dev.
the class LineageCountThroughTime method getLTT.
public static Variate[] getLTT(String treeFile, double minTime, double maxTime, int binCount, // number of trees to skip
int skip) throws IOException, ImportException {
double delta = (maxTime - minTime) / (binCount - 1);
BufferedReader reader = new BufferedReader(new FileReader(treeFile));
String line = reader.readLine();
TreeImporter importer;
if (line.toUpperCase().startsWith("#NEXUS")) {
importer = new NexusImporter(reader);
} else {
importer = new NewickImporter(reader, false);
}
int state = 0;
while (importer.hasTree() && state < skip) {
importer.importNextTree();
state += 1;
}
// the age of the end of this group
List<double[]> branchingTimes = new ArrayList<double[]>();
state = 0;
while (importer.hasTree()) {
RootedTree tree = (RootedTree) importer.importNextTree();
double[] bt = new double[tree.getInternalNodes().size()];
int i = 0;
for (Node node : tree.getInternalNodes()) {
bt[i] = tree.getHeight(node);
i++;
}
Arrays.sort(bt);
branchingTimes.add(bt);
state += 1;
}
Variate[] bins = new Variate[binCount];
double height = 0;
double n = branchingTimes.get(0).length;
for (int k = 0; k < binCount; k++) {
bins[k] = new Variate.D();
if (height >= 0.0 && height <= maxTime) {
for (state = 0; state < branchingTimes.size(); state++) {
int index = 0;
while (index < branchingTimes.get(state).length && branchingTimes.get(state)[index] < height) {
index += 1;
}
double lineageCount = 1;
if (index < branchingTimes.get(state).length) {
lineageCount = n - index + 1;
}
bins[k].add(lineageCount);
}
}
height += delta;
}
Variate xData = new Variate.D();
Variate yDataMean = new Variate.D();
Variate yDataMedian = new Variate.D();
Variate yDataUpper = new Variate.D();
Variate yDataLower = new Variate.D();
double t = minTime;
for (Variate bin : bins) {
xData.add(t);
if (bin.getCount() > 0) {
yDataMean.add(bin.getMean());
yDataMedian.add(bin.getQuantile(0.5));
yDataLower.add(bin.getQuantile(0.025));
yDataUpper.add(bin.getQuantile(0.975));
} else {
yDataMean.add(Double.NaN);
yDataMedian.add(Double.NaN);
yDataLower.add(Double.NaN);
yDataUpper.add(Double.NaN);
}
t += delta;
}
return new Variate[] { xData, yDataMean };
}
Aggregations