use of dr.evolution.io.NexusImporter in project beast-mcmc by beast-dev.
the class TreeLengthFinder method report.
/**
* Recursively analyzes trees files.
*
* @param name the file to analyze (if this is a directory then the files within it are analyzed)
* @param burnin the burnin to use
*/
private void report(String name, int burnin) {
double treeLength = 0.0;
int count = 0;
try {
FileReader fileReader = new FileReader(new File(name));
TreeImporter importer = new NexusImporter(fileReader);
while (importer.hasTree()) {
Tree tree = importer.importNextTree();
if (count >= burnin) {
treeLength += TreeLength.FACTORY.createStatistic().getSummaryStatistic(tree)[0];
}
count++;
}
treeLength /= (count - burnin);
System.out.println(name + "\t" + burnin + "\t" + treeLength);
} catch (Importer.ImportException e) {
System.err.println("Error Parsing Input Tree: " + e.getMessage());
} catch (IOException e) {
System.err.println("Error Parsing Input Tree: " + e.getMessage());
}
}
use of dr.evolution.io.NexusImporter in project beast-mcmc by beast-dev.
the class TaxaOriginTrait method main.
/*
* Arguments:
* 0: Trait name
* 1: File name for list of taxaNames of interest
* 2: File name for trees (output from BranchJumpPlotter)
* 3: Output file name root
* */
public static void main(String[] args) {
try {
BufferedReader taxonReader = new BufferedReader(new FileReader(args[1]));
HashSet<String> tempTaxa = new HashSet<String>();
String line;
while ((line = taxonReader.readLine()) != null) {
tempTaxa.add(line);
}
String[] taxa = tempTaxa.toArray(new String[tempTaxa.size()]);
NexusImporter importer = new NexusImporter(new FileReader(args[2]));
importer.setSuppressWarnings(true);
ArrayList<FlexibleTree> tempTrees = new ArrayList<FlexibleTree>();
int count = 0;
while (importer.hasTree()) {
if (count % 100 == 0) {
System.out.println("Loaded " + count + " trees");
}
tempTrees.add((FlexibleTree) importer.importNextTree());
count++;
}
FlexibleTree[] trees = tempTrees.toArray(new FlexibleTree[tempTrees.size()]);
TaxaOriginTrait examiner = new TaxaOriginTrait(taxa, trees, args[0], args[3]);
examiner.tabulateOrigins();
} catch (IOException e) {
System.out.println("Failed to read files");
} catch (Importer.ImportException e) {
System.out.println("Failed to import trees");
}
}
use of dr.evolution.io.NexusImporter in project beast-mcmc by beast-dev.
the class OrderNexusTranslationTable method main.
public static void main(String[] args) throws Importer.ImportException, IOException {
NexusImporter importer = new NexusImporter(new FileReader(args[0]));
Tree[] trees = importer.importTrees(null);
System.out.println("Read " + trees.length + " trees from " + args[0]);
String newFileName = args[0] + ".new";
PrintStream ps = new PrintStream(new FileOutputStream(newFileName));
NexusExporter exporter = new NexusExporter(ps);
exporter.setTreePrefix("STATE_");
NumberFormat format = NumberFormat.getNumberInstance();
format.setMaximumFractionDigits(7);
exporter.setNumberFormat(format);
exporter.setSortedTranslationTable(true);
exporter.exportTrees(trees, false);
ps.flush();
ps.close();
System.out.println("Wrote " + trees.length + " trees to " + newFileName);
}
use of dr.evolution.io.NexusImporter in project beast-mcmc by beast-dev.
the class CoalGenFrame method importFromFile.
protected void importFromFile(File file) throws IOException, Importer.ImportException {
BufferedReader reader = new BufferedReader(new FileReader(file));
String line = reader.readLine();
Tree tree;
if (line.toUpperCase().startsWith("#NEXUS")) {
NexusImporter importer = new NexusImporter(reader);
tree = importer.importTree(null);
} else {
NewickImporter importer = new NewickImporter(reader);
tree = importer.importTree(null);
}
data.taxonList = tree;
statusLabel.setText(Integer.toString(data.taxonList.getTaxonCount()) + " taxa loaded.");
reader.close();
fireTaxaChanged();
}
use of dr.evolution.io.NexusImporter in project beast-mcmc by beast-dev.
the class GetNSCountsFromTrees method analyze.
private void analyze(File inputFile, int burnin, BranchSet branchSet, List<Set> inclusionSets, List<Set> exclusionSets, double[] siteList) {
if (summary) {
resultsStream.print("tree" + SEP + "cN" + SEP + "uN" + SEP + "cS" + SEP + "uS" + SEP + "cNrate" + SEP + "cSrate" + SEP + "dN/dS" + "\n");
} else {
resultsStream.print("tree" + SEP + "branch" + SEP + "N/S" + SEP + "site" + SEP + "height/date" + SEP + "fromState" + SEP + "toState");
if (branchInfo) {
resultsStream.print(SEP + "branchLength" + SEP + "branchCN/S" + SEP + "branchUN/S" + "\n");
} else {
resultsStream.print("\n");
}
}
int totalTrees = 10000;
int totalStars = 0;
System.out.println("Reading and analyzing trees (bar assumes 10,000 trees)...");
System.out.println("0 25 50 75 100");
System.out.println("|--------------|--------------|--------------|--------------|");
int stepSize = totalTrees / 60;
if (stepSize < 1)
stepSize = 1;
int count = 0;
int treeUsed = 1;
try {
FileReader fileReader = new FileReader(inputFile);
TreeImporter importer = new NexusImporter(fileReader);
while (importer.hasTree()) {
Tree tree = importer.importNextTree();
if (count >= burnin) {
getNSCounts(tree, treeUsed, branchSet, inclusionSets, exclusionSets, siteList);
treeUsed++;
}
count++;
if (totalTrees > 0 && totalTrees % stepSize == 0) {
System.out.print("*");
totalStars++;
if (totalStars % 61 == 0)
System.out.print("\n");
System.out.flush();
}
totalTrees++;
}
System.out.print("\n");
} catch (Importer.ImportException e) {
progressStream.println("Error Parsing Input Tree: " + e.getMessage());
} catch (IOException e) {
progressStream.println("Error Parsing Input Tree: " + e.getMessage());
}
}
Aggregations