Search in sources :

Example 11 with Alignment

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;
}
Also used : SitePatterns(dr.evolution.alignment.SitePatterns) Alignment(dr.evolution.alignment.Alignment) TaxonList(dr.evolution.util.TaxonList) Parameter(dr.inference.model.Parameter) Logger(java.util.logging.Logger)

Example 12 with Alignment

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;
}
Also used : Alignment(dr.evolution.alignment.Alignment) HypermutantAlignment(dr.evolution.alignment.HypermutantAlignment) HypermutantAlignment(dr.evolution.alignment.HypermutantAlignment)

Example 13 with Alignment

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;
}
Also used : Alignment(dr.evolution.alignment.Alignment) TaxonList(dr.evolution.util.TaxonList) Tree(dr.evolution.tree.Tree) MetagenomeData(dr.evolution.MetagenomeData) LinkageConstraints(dr.evolution.LinkageConstraints)

Example 14 with Alignment

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);
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) TKF91Likelihood(dr.oldevomodel.indel.TKF91Likelihood) Alignment(dr.evolution.alignment.Alignment) GammaSiteModel(dr.oldevomodel.sitemodel.GammaSiteModel) TKF91Model(dr.oldevomodel.indel.TKF91Model)

Example 15 with Alignment

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;
}
Also used : Alignment(dr.evolution.alignment.Alignment) TaxonList(dr.evolution.util.TaxonList) Logger(java.util.logging.Logger)

Aggregations

Alignment (dr.evolution.alignment.Alignment)29 SimpleAlignment (dr.evolution.alignment.SimpleAlignment)7 TaxonList (dr.evolution.util.TaxonList)7 TreeModel (dr.evomodel.tree.TreeModel)6 Parameter (dr.inference.model.Parameter)6 ImportException (dr.evolution.io.Importer.ImportException)5 Tree (dr.evolution.tree.Tree)5 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)5 GammaSiteRateModel (dr.evomodel.siteratemodel.GammaSiteRateModel)5 BeagleSequenceSimulator (dr.app.beagle.tools.BeagleSequenceSimulator)4 Partition (dr.app.beagle.tools.Partition)4 ConvertAlignment (dr.evolution.alignment.ConvertAlignment)4 SitePatterns (dr.evolution.alignment.SitePatterns)4 NewickImporter (dr.evolution.io.NewickImporter)4 HomogeneousBranchModel (dr.evomodel.branchmodel.HomogeneousBranchModel)4 FrequencyModel (dr.evomodel.substmodel.FrequencyModel)4 ArrayList (java.util.ArrayList)4 Taxon (dr.evolution.util.Taxon)3 DefaultBranchRateModel (dr.evomodel.branchratemodel.DefaultBranchRateModel)3 SubstitutionModel (dr.evomodel.substmodel.SubstitutionModel)3