Search in sources :

Example 81 with Taxon

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;
}
Also used : Taxon(dr.evolution.util.Taxon)

Example 82 with Taxon

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);
}
Also used : Attribute(dr.util.Attribute) Taxon(dr.evolution.util.Taxon)

Example 83 with Taxon

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;
}
Also used : TreeSet(java.util.TreeSet) Taxon(dr.evolution.util.Taxon)

Example 84 with Taxon

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;
}
Also used : Taxon(dr.evolution.util.Taxon)

Example 85 with Taxon

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);
}
Also used : Taxon(dr.evolution.util.Taxon)

Aggregations

Taxon (dr.evolution.util.Taxon)151 Taxa (dr.evolution.util.Taxa)31 ArrayList (java.util.ArrayList)24 TaxonList (dr.evolution.util.TaxonList)19 NodeRef (dr.evolution.tree.NodeRef)18 Date (dr.evolution.util.Date)18 Tree (dr.evolution.tree.Tree)15 Sequence (dr.evolution.sequence.Sequence)12 TreeModel (dr.evomodel.tree.TreeModel)12 Parameter (dr.inference.model.Parameter)12 Attribute (dr.util.Attribute)11 SimpleAlignment (dr.evolution.alignment.SimpleAlignment)10 Patterns (dr.evolution.alignment.Patterns)9 NewickImporter (dr.evolution.io.NewickImporter)7 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)7 Microsatellite (dr.evolution.datatype.Microsatellite)6 IOException (java.io.IOException)5 HashSet (java.util.HashSet)5 PatternList (dr.evolution.alignment.PatternList)4 DataType (dr.evolution.datatype.DataType)4