use of dr.evolution.util.TaxonList in project beast-mcmc by beast-dev.
the class BeastGenerator method writeDifferentTaxa.
public void writeDifferentTaxa(AbstractPartitionData dataPartition, XMLWriter writer) {
TaxonList taxonList = dataPartition.getTaxonList();
String name = dataPartition.getPartitionTreeModel().getName();
writer.writeComment("gene name = " + name + ", ntax= " + taxonList.getTaxonCount());
writer.writeOpenTag(TaxaParser.TAXA, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, name + "." + TaxaParser.TAXA) });
for (int i = 0; i < taxonList.getTaxonCount(); i++) {
if (!(dataPartition instanceof PartitionPattern && ((PartitionPattern) dataPartition).getPatterns().isMasked(i))) {
final Taxon taxon = taxonList.getTaxon(i);
writer.writeIDref(TaxonParser.TAXON, taxon.getId());
}
}
writer.writeCloseTag(TaxaParser.TAXA);
}
use of dr.evolution.util.TaxonList in project beast-mcmc by beast-dev.
the class TipDateSamplingComponentOptions method selectOperators.
public void selectOperators(final ModelOptions modelOptions, final List<Operator> ops) {
if (tipDateSamplingType == TipDateSamplingType.SAMPLE_INDIVIDUALLY || tipDateSamplingType == TipDateSamplingType.SAMPLE_PRECISION) {
TaxonList taxa = getTaxonSet();
String description = "Random walk for the age of this tip";
//OperatorType type = OperatorType.RANDOM_WALK_ABSORBING;
OperatorType type = OperatorType.UNIFORM;
if (tipDateSamplingType == TipDateSamplingType.SAMPLE_PRECISION) {
description = "Uniform sample from precision of age of this tip";
//type = OperatorType.UNIFORM;
}
for (int i = 0; i < taxa.getTaxonCount(); i++) {
Taxon taxon = taxa.getTaxon(i);
Operator operator = tipDateOperators.get(taxon);
if (operator == null) {
Parameter parameter = getTipDateParameter(taxon);
// operator = new Operator("age(" + taxon.getId() + ")", "", parameter, OperatorType.SCALE, 0.75, 1.0);
operator = new Operator.Builder("age(" + taxon.getId() + ")", description, parameter, type, 1.0, 1.0).build();
if (tipDateSamplingType == TipDateSamplingType.SAMPLE_INDIVIDUALLY) {
operator.setWeight(2.0);
}
tipDateOperators.put(taxon, operator);
}
ops.add(operator);
}
} else if (tipDateSamplingType == TipDateSamplingType.SAMPLE_JOINT) {
ops.add(modelOptions.getOperator("treeModel.tipDates"));
}
}
use of dr.evolution.util.TaxonList in project beast-mcmc by beast-dev.
the class UncertainAttributePatternsParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
String attributeName = xo.getStringAttribute(ATTRIBUTE);
TaxonList taxa = (TaxonList) xo.getChild(TaxonList.class);
DataType dataType = DataTypeUtils.getDataType(xo);
if (dataType == null) {
throw new XMLParseException("dataType expected for attributePatterns element");
}
// using a SimpleSiteList rather than Patterns to allow ancestral reconstruction
UncertainSiteList patterns = new UncertainSiteList(dataType, taxa);
boolean normalize = xo.getAttribute(NORMALIZE, true);
if (dataType == null) {
// TODO Is this necessary given XMLSyntaxRules?
throw new XMLParseException("dataType expected for attributePatterns element");
}
double[][] uncertainPattern = new double[taxa.getTaxonCount()][];
// Parse attributes
boolean attributeFound = false;
for (int i = 0; i < taxa.getTaxonCount(); i++) {
Taxon taxon = taxa.getTaxon(i);
Object value = taxon.getAttribute(attributeName);
if (value != null) {
attributeFound = true;
List<StateProbability> stateProbabilities;
try {
stateProbabilities = parseStates(value.toString(), dataType);
} catch (StateParseException e) {
throw new XMLParseException("State or probability for attribute (" + attributeName + ") in taxon " + taxon.getId() + " is invalid; state = \"" + e.getState() + "\" and probability =\"" + e.getProbability() + "\"");
}
uncertainPattern[i] = convertToPartials(stateProbabilities, dataType, normalize);
} else {
throw new XMLParseException("State for attribute (" + attributeName + ") in taxon " + taxon.getId() + " is unknown.");
}
}
if (!attributeFound) {
throw new XMLParseException("The attribute (" + attributeName + ") was missing in all taxa. Check the name of the attribute.");
}
patterns.addPattern(uncertainPattern);
Logger.getLogger("dr.evolution").info("\n ---------------------------------\nCreating an uncertain attribute model for attribute \"" + attributeName + "\"");
Logger.getLogger("dr.evolution").info("\tIf you publish results using this model, please reference:");
Logger.getLogger("dr.evolution").info("\t" + Citable.Utils.getCitationString(patterns));
Logger.getLogger("dr.evolution").info("\n");
return patterns;
}
use of dr.evolution.util.TaxonList in project beast-mcmc by beast-dev.
the class SitePatternsParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
Alignment alignment = (Alignment) xo.getChild(Alignment.class);
TaxonList taxa = null;
int from = 0;
int to = -1;
int every = xo.getAttribute(EVERY, 1);
boolean strip = xo.getAttribute(STRIP, true);
boolean unique = xo.getAttribute(UNIQUE, true);
if (xo.hasAttribute(FROM)) {
from = xo.getIntegerAttribute(FROM) - 1;
if (from < 0)
throw new XMLParseException("illegal 'from' attribute in patterns element");
}
if (xo.hasAttribute(TO)) {
to = xo.getIntegerAttribute(TO) - 1;
if (to < 0 || to < from)
throw new XMLParseException("illegal 'to' attribute in patterns element");
}
if (every <= 0)
throw new XMLParseException("illegal 'every' attribute in patterns element");
if (xo.hasChildNamed(TAXON_LIST)) {
taxa = (TaxonList) xo.getElementFirstChild(TAXON_LIST);
}
int[] constantPatternCounts = null;
if (xo.hasChildNamed(CONSTANT_PATTERNS)) {
Parameter param = (Parameter) xo.getElementFirstChild(CONSTANT_PATTERNS);
if (param.getDimension() != alignment.getStateCount()) {
throw new XMLParseException("The " + CONSTANT_PATTERNS + " parameter length should be equal to the number of states");
}
constantPatternCounts = new int[param.getDimension()];
int i = 0;
for (double value : param.getParameterValues()) {
constantPatternCounts[i] = (int) value;
i++;
}
}
if (from > alignment.getSiteCount())
throw new XMLParseException("illegal 'from' attribute in patterns element");
if (to > alignment.getSiteCount())
throw new XMLParseException("illegal 'to' attribute in patterns element");
SitePatterns patterns = new SitePatterns(alignment, taxa, from, to, every, strip, unique, constantPatternCounts);
int f = from + 1;
// fixed a *display* error by adding + 1 for consistency with f = from + 1
int t = to + 1;
if (to == -1)
t = alignment.getSiteCount();
if (xo.hasAttribute(XMLParser.ID)) {
final Logger logger = Logger.getLogger("dr.evoxml");
logger.info("Site patterns '" + xo.getId() + "' created from positions " + Integer.toString(f) + "-" + Integer.toString(t) + " of alignment '" + alignment.getId() + "'");
if (every > 1) {
logger.info(" only using every " + every + " site");
}
logger.info(" " + (unique ? "unique " : "") + "pattern count = " + patterns.getPatternCount());
}
return patterns;
}
use of dr.evolution.util.TaxonList in project beast-mcmc by beast-dev.
the class LinkedGroupParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
TaxonList taxa = null;
double linkageProbability = 0.9999999999;
if (xo.hasAttribute("probability")) {
linkageProbability = xo.getDoubleAttribute("probability");
}
taxa = (TaxonList) xo.getChild(TaxonList.class);
LinkedGroup lg = new LinkedGroup(taxa, linkageProbability);
return lg;
}
Aggregations