use of dr.evolution.util.Taxon in project beast-mcmc by beast-dev.
the class XMLExporter method exportAlignment.
// END: Constructor
public String exportAlignment(SimpleAlignment alignment) throws IOException {
StringWriter sw = new StringWriter();
XMLWriter writer = new XMLWriter(sw);
// TODO: if we keep the taxa element than lets also write dates
// writer.writeOpenTag(TaxaParser.TAXA, // tagname
// new Attribute[] { // attributes[]
// new Attribute.Default<String>(XMLParser.ID, TaxaParser.TAXA) });
//
// for (int i = 0; i < alignment.getTaxonCount(); i++) {
//
// Taxon taxon = alignment.getTaxon(i);
//
// writer.writeTag(
// TaxonParser.TAXON, // tagname
// new Attribute[] { // attributes[]
// new Attribute.Default<String>(XMLParser.ID, taxon.getId()) },
// true // close
// );
//
//// System.out.println(taxon.getAttribute(Utils.ABSOLUTE_HEIGHT));
//
//// writer.writeCloseTag(TaxonParser.TAXON);
//
// }// END: taxon loop
//
// writer.writeCloseTag(TaxaParser.TAXA);
//
// writer.writeBlankLine();
// tagname
writer.writeOpenTag(// tagname
AlignmentParser.ALIGNMENT, new Attribute[] { // attributes[]
new Attribute.Default<String>(XMLParser.ID, AlignmentParser.ALIGNMENT), new Attribute.Default<String>(DataType.DATA_TYPE, alignment.getDataType().getDescription()) });
for (int i = 0; i < alignment.getSequenceCount(); i++) {
Taxon taxon = alignment.getTaxon(i);
writer.writeOpenTag(SequenceParser.SEQUENCE);
writer.writeIDref(TaxonParser.TAXON, taxon.getId());
writer.writeText(alignment.getSequence(i).getSequenceString());
writer.writeCloseTag(SequenceParser.SEQUENCE);
}
//END: sequences loop
writer.writeCloseTag(AlignmentParser.ALIGNMENT);
writer.close();
return sw.toString();
}
use of dr.evolution.util.Taxon in project beast-mcmc by beast-dev.
the class TreesTableModel method applyTaxa.
// END: setRow
public void applyTaxa(Tree tree) {
// set attributes to be parsed later in Taxa panel
Taxa taxa = new Taxa();
for (Taxon taxon : tree.asList()) {
double absoluteHeight = Utils.getAbsoluteTaxonHeight(taxon, tree);
taxon.setAttribute(Utils.ABSOLUTE_HEIGHT, absoluteHeight);
taxon.setAttribute(Utils.TREE_FILENAME, tree.getId());
taxa.addTaxon(taxon);
dataList.allTaxa.addTaxon(taxon);
}
// END: taxon loop
}
use of dr.evolution.util.Taxon in project beast-mcmc by beast-dev.
the class Utils method printTaxaSet.
// END: printDataType
public static void printTaxaSet(Taxa taxa) {
for (int i = 0; i < taxa.getTaxonCount(); i++) {
Taxon taxon = taxa.getTaxon(i);
System.out.print("\t\t " + taxonToString(taxon, false) + ("\n"));
}
}
use of dr.evolution.util.Taxon in project beast-mcmc by beast-dev.
the class Utils method printHashMap.
// END: printMap
public static void printHashMap(ConcurrentHashMap<?, ?> hashMap) {
Iterator<?> iterator = hashMap.entrySet().iterator();
while (iterator.hasNext()) {
Entry<?, ?> pairs = (Entry<?, ?>) iterator.next();
Taxon taxon = (Taxon) pairs.getKey();
int[] sequence = (int[]) pairs.getValue();
System.out.println(taxon.toString());
Utils.printArray(sequence);
}
// END: while has next
}
use of dr.evolution.util.Taxon in project beast-mcmc by beast-dev.
the class Utils method getAbsoluteTaxonHeight.
// END: taxonExists
// private boolean isFileInList(File file) {
// boolean exists = false;
//
// for (File file2 : dataList.treesList) {
//
// if (file.getName().equalsIgnoreCase(file2.getName())) {
// exists = true;
// break;
// }
//
// }
//
// return exists;
// }// END: isFileInList
public static double getAbsoluteTaxonHeight(Taxon taxon, Tree tree) {
double height = 0.0;
for (int i = 0; i < tree.getExternalNodeCount(); i++) {
NodeRef externalNode = tree.getExternalNode(i);
Taxon externalNodeTaxon = tree.getNodeTaxon(externalNode);
if (externalNodeTaxon.equals(taxon)) {
height = tree.getNodeHeight(externalNode);
}
}
return height;
}
Aggregations