use of dr.evolution.tree.Tree in project beast-mcmc by beast-dev.
the class RateStatisticParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
final String name = xo.getAttribute(Statistic.NAME, xo.getId());
final Tree tree = (Tree) xo.getChild(Tree.class);
final BranchRateModel branchRateModel = (BranchRateModel) xo.getChild(BranchRateModel.class);
final boolean internal = xo.getBooleanAttribute("internal");
final boolean external = xo.getBooleanAttribute("external");
if (!(internal || external)) {
throw new XMLParseException("At least one of internal and external must be true!");
}
final String mode = xo.getStringAttribute(MODE);
return new RateStatistic(name, tree, branchRateModel, external, internal, mode);
}
use of dr.evolution.tree.Tree in project beast-mcmc by beast-dev.
the class SpeciesTreeStatisticParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
String name = xo.getAttribute(Statistic.NAME, xo.getId());
Tree speciesTree = (Tree) xo.getElementFirstChild("speciesTree");
Tree popTree = (Tree) xo.getElementFirstChild("populationTree");
return new SpeciesTreeStatistic(name, speciesTree, popTree);
}
use of dr.evolution.tree.Tree in project beast-mcmc by beast-dev.
the class TerminalBranchStatisticParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
String name = xo.getAttribute(Statistic.NAME, xo.getId());
Tree tree = (Tree) xo.getChild(Tree.class);
return new TerminalBranchStatistic(name, tree);
}
use of dr.evolution.tree.Tree in project beast-mcmc by beast-dev.
the class TimeSlicer method readAndAnalyzeTrees.
// private List<Tree> importTrees(String treeFileName, int burnin) throws IOException, Importer.ImportException {
//
// int totalTrees = 10000;
//
// progressStream.println("Reading trees (bar assumes 10,000 trees)...");
// progressStream.println("0 25 50 75 100");
// progressStream.println("|--------------|--------------|--------------|--------------|");
//
// int stepSize = totalTrees / 60;
// if (stepSize < 1) stepSize = 1;
//
// List<Tree> treeList = new ArrayList<Tree>();
// BufferedReader reader1 = new BufferedReader(new FileReader(treeFileName));
//
// String line1 = reader1.readLine();
// TreeImporter importer1;
// if (line1.toUpperCase().startsWith("#NEXUS")) {
// importer1 = new NexusImporter(new FileReader(treeFileName));
// } else {
// importer1 = new NewickImporter(new FileReader(treeFileName));
// }
// totalTrees = 0;
// while (importer1.hasTree()) {
// Tree treeTime = importer1.importNextTree();
//
// if (totalTrees > burnin)
// treeList.add(treeTime);
//
// if (totalTrees > 0 && totalTrees % stepSize == 0) {
// progressStream.print("*");
// progressStream.flush();
// }
// totalTrees++;
// }
// return treeList;
// }
private void readAndAnalyzeTrees(String treeFileName, int burnin, int skipEvery, String[] traits, double[] slices, boolean impute, boolean trueNoise, Normalization normalize, boolean divideByBranchLength, BranchSet branchset, Set taxaSet) throws IOException, Importer.ImportException {
int totalTrees = 10000;
int totalStars = 0;
progressStream.println("Reading and analyzing trees (bar assumes 10,000 trees)...");
progressStream.println("0 25 50 75 100");
progressStream.println("|--------------|--------------|--------------|--------------|");
int stepSize = totalTrees / 60;
if (stepSize < 1)
stepSize = 1;
BufferedReader reader1 = new BufferedReader(new FileReader(treeFileName));
String line1 = reader1.readLine();
TreeImporter importer1;
if (line1.toUpperCase().startsWith("#NEXUS")) {
importer1 = new NexusImporter(new FileReader(treeFileName));
} else {
importer1 = new NewickImporter(new FileReader(treeFileName));
}
totalTrees = 0;
while (importer1.hasTree()) {
Tree treeTime = importer1.importNextTree();
if (totalTrees % skipEvery == 0) {
treesRead++;
if (totalTrees >= burnin) {
analyzeTree(treeTime, traits, slices, impute, trueNoise, normalize, divideByBranchLength, branchset, taxaSet);
}
}
if (totalTrees > 0 && totalTrees % stepSize == 0) {
progressStream.print("*");
totalStars++;
if (totalStars % 61 == 0)
progressStream.print("\n");
progressStream.flush();
}
totalTrees++;
}
progressStream.print("\n");
}
use of dr.evolution.tree.Tree in project beast-mcmc by beast-dev.
the class GetDateFromTree method getRandomTree.
private static Tree getRandomTree() {
Random random = new Random();
// [1, 10]
int c = random.nextInt(10) + 1;
// [1000, 10000]
int tId = random.nextInt(9000) + 1000;
try {
System.out.println("randomly get " + tId + "th tree from " + pathInput + c + inputFileName + "\n\n");
FileReader fileReader = new FileReader(pathInput + c + inputFileName);
// many trees
GetDateFromTree getDateFromTree = new GetDateFromTree(fileReader);
int totalTrees = 0;
try {
while (getDateFromTree.hasTree()) {
Tree tree = getDateFromTree.importNextTree();
totalTrees++;
if (totalTrees == tId) {
return tree;
}
}
} catch (ImportException e) {
System.err.println("Error Parsing Input Tree: " + e.getMessage());
return null;
}
fileReader.close();
} catch (FileNotFoundException e) {
//To change body of catch statement use File | Settings | File Templates.
e.printStackTrace();
} catch (IOException e) {
//To change body of catch statement use File | Settings | File Templates.
e.printStackTrace();
}
return null;
}
Aggregations