use of dr.evolution.util.Taxon in project beast-mcmc by beast-dev.
the class TreeSummary method buildConsensusTree.
private Tree buildConsensusTree(CladeSystem cladeSystem) {
List<BitSet> bitSets = new ArrayList<BitSet>(cladeSystem.getCladeMap().keySet());
Collections.sort(bitSets, new Comparator<BitSet>() {
@Override
public int compare(BitSet b1, BitSet b2) {
return b1.cardinality() - b2.cardinality();
}
});
SimpleNode root = null;
for (int i = 0; i < bitSets.size(); i++) {
BitSet key1 = bitSets.get(i);
CladeSystem.Clade clade1 = cladeSystem.getCladeMap().get(key1);
if (key1.cardinality() == 1) {
Taxon taxon = cladeSystem.getTaxon(key1.nextSetBit(0));
clade1.node = new SimpleNode();
clade1.node.setTaxon(taxon);
clade1.node.setAttribute("clade", clade1);
}
if (clade1.credibility >= posteriorLimit) {
for (int j = i + 1; j < bitSets.size(); j++) {
BitSet key2 = bitSets.get(j);
if (isSubSet(key1, key2) && cladeSystem.getCladeCredibility(key2) >= posteriorLimit) {
// the clades are ordered by size so this is the smallest clade for which
// clade1 is a subset and has high credibility.
CladeSystem.Clade clade2 = cladeSystem.getCladeMap().get(key2);
if (clade2.node == null) {
clade2.node = new SimpleNode();
}
if (clade1.node == null) {
throw new RuntimeException("null node");
}
clade2.node.addChild(clade1.node);
clade2.node.setAttribute("credibility", clade2.credibility);
clade2.node.setAttribute("clade", clade2);
if (key2.cardinality() == cladeSystem.taxonList.getTaxonCount()) {
root = clade2.node;
}
break;
}
}
}
}
SimpleTree tree = new SimpleTree(root);
return tree;
}
use of dr.evolution.util.Taxon in project beast-mcmc by beast-dev.
the class STARBEASTGenerator method writeMultiSpecies.
/**
* write tag <sp>
*
* @param taxonList TaxonList
* @param writer XMLWriter
*/
private void writeMultiSpecies(TaxonList taxonList, XMLWriter writer) {
List<String> species = options.starBEASTOptions.getSpeciesList();
String sp;
// used in private String getIndicatorsParaValue()
numOfSpecies = species.size();
for (String eachSp : species) {
writer.writeOpenTag(SpeciesBindingsSPinfoParser.SP, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, eachSp) });
for (int i = 0; i < taxonList.getTaxonCount(); i++) {
Taxon taxon = null;
try {
taxon = taxonList.getTaxon(i);
sp = taxon.getAttribute(TraitData.TRAIT_SPECIES).toString();
} catch (Exception e) {
throw new IllegalArgumentException("Cannot get value from Taxon " + taxon.getId());
}
if (sp.equals(eachSp)) {
writer.writeIDref(TaxonParser.TAXON, taxon.getId());
}
}
writer.writeCloseTag(SpeciesBindingsSPinfoParser.SP);
}
writeGeneTrees(writer);
}
use of dr.evolution.util.Taxon in project beast-mcmc by beast-dev.
the class TraitData method getStatesListOfTrait.
public static Set<String> getStatesListOfTrait(Taxa taxonList, String traitName) {
Set<String> states = new TreeSet<String>();
if (taxonList == null) {
throw new IllegalArgumentException("taxon list is null");
}
for (int i = 0; i < taxonList.getTaxonCount(); i++) {
Taxon taxon = taxonList.getTaxon(i);
String attr = (String) taxon.getAttribute(traitName);
// ? is used to denote missing data so is not a state...
if (attr != null && !attr.equals("?")) {
states.add(attr);
}
}
return states;
}
use of dr.evolution.util.Taxon in project beast-mcmc by beast-dev.
the class TraitData method getEmptyStateIndex.
public static int getEmptyStateIndex(Taxa taxonList, String traitName) {
if (taxonList == null) {
throw new IllegalArgumentException("taxon list is null");
}
for (int i = 0; i < taxonList.getTaxonCount(); i++) {
Taxon taxon = taxonList.getTaxon(i);
String attr = (String) taxon.getAttribute(traitName);
// ? is used to denote missing data so is not a state...
if (attr == null || attr.equals("?")) {
return i;
}
}
return -1;
}
use of dr.evolution.util.Taxon in project beast-mcmc by beast-dev.
the class DateGuesser method guessDates.
public void guessDates(TaxonList taxonList) {
// To avoid duplicating code, add all the taxa into a list and
// pass it to guessDates(List<Taxon> taxonList)
List<Taxon> taxa = new ArrayList<Taxon>();
for (Taxon taxon : taxonList) {
taxa.add(taxon);
}
guessDates(taxa);
}
Aggregations