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++;
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations