use of dr.evolution.alignment.Alignment 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.alignment.Alignment in project beast-mcmc by beast-dev.
the class HypermutantAlignmentParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
Alignment alignment = (Alignment) xo.getChild(Alignment.class);
if (alignment.getDataType().getType() != DataType.NUCLEOTIDES) {
throw new XMLParseException("HypermutantAlignment can only convert nucleotide alignments");
}
String typeName = xo.getStringAttribute(CONTEXT_TYPE);
HypermutantAlignment.APOBECType type = null;
try {
type = HypermutantAlignment.APOBECType.valueOf(typeName.toUpperCase());
} catch (IllegalArgumentException iae) {
throw new XMLParseException("Unrecognised hypermutation type: " + typeName);
}
HypermutantAlignment convert = new HypermutantAlignment(type, alignment);
int mutatedCount = convert.getMutatedContextCount();
int totalCount = mutatedCount + convert.getUnmutatedContextCount();
Logger.getLogger("dr.evoxml").info("Converted alignment, '" + xo.getId() + "' to a hypermutant alignment targeting " + type.toString() + " contexts.\r" + "\tPotentially mutated contexts: " + mutatedCount + " out of a total of " + totalCount + " contexts");
return convert;
}
use of dr.evolution.alignment.Alignment in project beast-mcmc by beast-dev.
the class MetagenomeDataParser method parseXMLObject.
@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
TaxonList taxa = null;
taxa = (TaxonList) xo.getChild(TaxonList.class);
if (taxa == null)
taxa = (Tree) xo.getChild(Tree.class);
Alignment alignment = (Alignment) xo.getChild(Alignment.class);
LinkageConstraints lc = (LinkageConstraints) xo.getChild(LinkageConstraints.class);
boolean fixedReferenceTree = false;
if (xo.hasAttribute("fixedReferenceTree")) {
fixedReferenceTree = xo.getBooleanAttribute("fixedReferenceTree");
}
MetagenomeData md = new MetagenomeData(taxa, alignment, lc, fixedReferenceTree);
return md;
}
use of dr.evolution.alignment.Alignment in project beast-mcmc by beast-dev.
the class TKF91LikelihoodParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
TreeModel tree = (TreeModel) xo.getChild(TreeModel.class);
Alignment alignment = (Alignment) xo.getChild(Alignment.class);
GammaSiteModel siteModel = (GammaSiteModel) xo.getChild(GammaSiteModel.class);
TKF91Model tkfModel = (TKF91Model) xo.getChild(TKF91Model.class);
return new TKF91Likelihood(tree, alignment, siteModel, tkfModel);
}
use of dr.evolution.alignment.Alignment in project beast-mcmc by beast-dev.
the class LineageSitePatternsParser 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);
}
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");
LineageSitePatterns patterns = new LineageSitePatterns(alignment, taxa, from, to, every, strip, unique);
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(" pattern count = " + patterns.getPatternCount());
}
return patterns;
}
Aggregations