Search in sources :

Example 26 with Taxon

use of dr.evolution.util.Taxon in project beast-mcmc by beast-dev.

the class AlloppDiploidHistory method simpletree2dhtesttree.

// for testing
private void simpletree2dhtesttree(SimpleNode snode) {
    if (snode.getChildCount() == 2) {
        simpletree2dhtesttree(snode.getChild(0));
        int lft = nextn - 1;
        simpletree2dhtesttree(snode.getChild(1));
        int rgt = nextn - 1;
        dhnodes[nextn].lft = lft;
        dhnodes[lft].anc = nextn;
        dhnodes[nextn].rgt = rgt;
        dhnodes[rgt].anc = nextn;
    }
    dhnodes[nextn].height = snode.getHeight();
    dhnodes[nextn].taxon = new Taxon(snode.getTaxon().getId());
    dhnodes[nextn].union = apsp.speciesseqEmptyUnion();
    nextn++;
}
Also used : Taxon(dr.evolution.util.Taxon)

Example 27 with Taxon

use of dr.evolution.util.Taxon in project beast-mcmc by beast-dev.

the class MoveLinkageGroup method doOperation.

public double doOperation() {
    // pick a read uniformly at random, add it to a linkage group uniformly at random
    int r = MathUtils.nextInt(readCount);
    Taxon read = hlm.getData().getReadsTaxa().getTaxon(r);
    int g = hlm.getLinkageGroupId(read);
    int newGroup = MathUtils.nextInt(groupCount);
    hlm.moveReadGroup(read, g, newGroup);
    // moves are symmetric -- same forward and backward proposal probabilities
    double logHastings = 0.0;
    return logHastings;
}
Also used : Taxon(dr.evolution.util.Taxon)

Example 28 with Taxon

use of dr.evolution.util.Taxon in project beast-mcmc by beast-dev.

the class LinkageGroupSwap method doOperation.

@Override
public double doOperation() {
    if (MathUtils.nextBoolean()) {
        // swap all taxa in one group to a new group
        int A = MathUtils.nextInt(groupCount);
        int B = MathUtils.nextInt(groupCount);
        HashSet<Taxon> aTaxa = new HashSet<Taxon>(hlm.getGroup(A));
        HashSet<Taxon> bTaxa = new HashSet<Taxon>(hlm.getGroup(B));
        for (Taxon taxon : aTaxa) {
            hlm.moveReadGroup(taxon, A, B);
        }
        for (Taxon taxon : bTaxa) {
            hlm.moveReadGroup(taxon, B, A);
        }
    } else {
        // pick two linkage groups uniformly A, B
        // pick an alignment column uniformly X
        // move all reads in group A that are defined in column X to group B, and
        // vice versa from B to A.
        // pick a read uniformly at random, add it to a linkage group uniformly at random
        ArrayList<Taxon> aTaxa = new ArrayList<Taxon>();
        ArrayList<Taxon> bTaxa = new ArrayList<Taxon>();
        int A = 0, B = 0;
        // choice of X and Y to groups that have something in col X.
        while (aTaxa.size() == 0 && bTaxa.size() == 0) {
            int X = MathUtils.nextInt(columnCount);
            A = MathUtils.nextInt(groupCount);
            B = MathUtils.nextInt(groupCount);
            if (A == B)
                // nothing to do.
                continue;
            // find all reads intersecting column X
            Alignment aln = hlm.getData().getAlignment();
            for (int i = 0; i < aln.getTaxonCount(); i++) {
                int state = aln.getPatternState(i, X);
                if (state == hlm.getDataType().getGapState() || state == hlm.getDataType().getUnknownState())
                    // seq undefined in this column
                    continue;
                if (hlm.getGroup(A).contains(aln.getTaxon(i))) {
                    aTaxa.add(aln.getTaxon(i));
                }
                if (hlm.getGroup(B).contains(aln.getTaxon(i))) {
                    bTaxa.add(aln.getTaxon(i));
                }
            }
        }
        // move taxa from A to B and from B to A
        for (Taxon taxon : aTaxa) {
            hlm.moveReadGroup(taxon, A, B);
        }
        for (Taxon taxon : bTaxa) {
            hlm.moveReadGroup(taxon, B, A);
        }
    }
    return 0;
}
Also used : Alignment(dr.evolution.alignment.Alignment) Taxon(dr.evolution.util.Taxon) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 29 with Taxon

use of dr.evolution.util.Taxon in project beast-mcmc by beast-dev.

the class TreeDataLikelihoodParser method createTreeDataLikelihood.

protected Likelihood createTreeDataLikelihood(List<PatternList> patternLists, List<BranchModel> branchModels, List<SiteRateModel> siteRateModels, TreeModel treeModel, BranchRateModel branchRateModel, TipStatesModel tipStatesModel, boolean useAmbiguities, PartialsRescalingScheme scalingScheme, boolean delayRescalingUntilUnderflow) throws XMLParseException {
    if (tipStatesModel != null) {
        throw new XMLParseException("Tip State Error models are not supported yet with TreeDataLikelihood");
    }
    List<Taxon> treeTaxa = treeModel.asList();
    List<Taxon> patternTaxa = patternLists.get(0).asList();
    if (!patternTaxa.containsAll(treeTaxa)) {
        throw new XMLParseException("TreeModel contains more taxa than the partition pattern list.");
    }
    if (!treeTaxa.containsAll(patternTaxa)) {
        throw new XMLParseException("TreeModel contains fewer taxa than the partition pattern list.");
    }
    //        DataLikelihoodDelegate dataLikelihoodDelegate = new BeagleDataLikelihoodDelegate(
    //                treeModel,
    //                patternLists.get(0),
    //                branchModel,
    //                siteRateModel,
    //                useAmbiguities,
    //                scalingScheme,
    //                delayRescalingUntilUnderflow);
    boolean useBeagle3 = Boolean.parseBoolean(System.getProperty("USE_BEAGLE3", "true"));
    boolean useJava = Boolean.parseBoolean(System.getProperty("java.only", "false"));
    if (useBeagle3 && MultiPartitionDataLikelihoodDelegate.IS_MULTI_PARTITION_COMPATIBLE() && !useJava) {
        DataLikelihoodDelegate dataLikelihoodDelegate = new MultiPartitionDataLikelihoodDelegate(treeModel, patternLists, branchModels, siteRateModels, useAmbiguities, scalingScheme, delayRescalingUntilUnderflow);
        return new TreeDataLikelihood(dataLikelihoodDelegate, treeModel, branchRateModel);
    } else {
        // The multipartition data likelihood isn't available so make a set of single partition data likelihoods
        List<Likelihood> treeDataLikelihoods = new ArrayList<Likelihood>();
        for (int i = 0; i < patternLists.size(); i++) {
            DataLikelihoodDelegate dataLikelihoodDelegate = new BeagleDataLikelihoodDelegate(treeModel, patternLists.get(i), branchModels.get(i), siteRateModels.get(i), useAmbiguities, scalingScheme, delayRescalingUntilUnderflow);
            treeDataLikelihoods.add(new TreeDataLikelihood(dataLikelihoodDelegate, treeModel, branchRateModel));
        }
        if (treeDataLikelihoods.size() == 1) {
            return treeDataLikelihoods.get(0);
        }
        return new CompoundLikelihood(treeDataLikelihoods);
    }
}
Also used : CompoundLikelihood(dr.inference.model.CompoundLikelihood) Likelihood(dr.inference.model.Likelihood) TreeDataLikelihood(dr.evomodel.treedatalikelihood.TreeDataLikelihood) Taxon(dr.evolution.util.Taxon) CompoundLikelihood(dr.inference.model.CompoundLikelihood) ArrayList(java.util.ArrayList) BeagleDataLikelihoodDelegate(dr.evomodel.treedatalikelihood.BeagleDataLikelihoodDelegate) TreeDataLikelihood(dr.evomodel.treedatalikelihood.TreeDataLikelihood) BeagleDataLikelihoodDelegate(dr.evomodel.treedatalikelihood.BeagleDataLikelihoodDelegate) MultiPartitionDataLikelihoodDelegate(dr.evomodel.treedatalikelihood.MultiPartitionDataLikelihoodDelegate) DataLikelihoodDelegate(dr.evomodel.treedatalikelihood.DataLikelihoodDelegate) MultiPartitionDataLikelihoodDelegate(dr.evomodel.treedatalikelihood.MultiPartitionDataLikelihoodDelegate)

Example 30 with Taxon

use of dr.evolution.util.Taxon in project beast-mcmc by beast-dev.

the class MonophylyStatisticParser method parseTaxonListOrTaxa.

public static TaxonList parseTaxonListOrTaxa(XMLObject cxo) {
    TaxonList taxa = (TaxonList) cxo.getChild(TaxonList.class);
    if (taxa == null) {
        Taxa taxa1 = new Taxa();
        for (int i = 0; i < cxo.getChildCount(); i++) {
            Object ccxo = cxo.getChild(i);
            if (ccxo instanceof Taxon) {
                taxa1.addTaxon((Taxon) ccxo);
            }
        }
        taxa = taxa1;
    }
    return taxa;
}
Also used : Taxa(dr.evolution.util.Taxa) TaxonList(dr.evolution.util.TaxonList) 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