Search in sources :

Example 11 with DataType

use of dr.evolution.datatype.DataType 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;
}
Also used : UncertainSiteList(dr.evolution.alignment.UncertainSiteList) TaxonList(dr.evolution.util.TaxonList) Taxon(dr.evolution.util.Taxon) DataType(dr.evolution.datatype.DataType)

Example 12 with DataType

use of dr.evolution.datatype.DataType in project beast-mcmc by beast-dev.

the class DataTypeUtils method getDataType.

public static DataType getDataType(XMLObject xo) throws XMLParseException {
    DataType dataType = null;
    if (xo.hasAttribute(DataType.DATA_TYPE)) {
        String dataTypeStr = xo.getStringAttribute(DataType.DATA_TYPE);
        if (xo.hasAttribute(GeneticCode.GENETIC_CODE)) {
            dataTypeStr += "-" + xo.getStringAttribute(GeneticCode.GENETIC_CODE);
        }
        dataType = DataType.getRegisteredDataTypeByName(dataTypeStr);
    }
    for (int i = 0; i < xo.getChildCount(); i++) {
        Object child = xo.getChild(i);
        if (child instanceof DataType) {
            if (dataType != null) {
                throw new XMLParseException("Multiple dataTypes defined for alignment element");
            }
            dataType = (DataType) child;
        }
    }
    return dataType;
}
Also used : DataType(dr.evolution.datatype.DataType) XMLObject(dr.xml.XMLObject) XMLParseException(dr.xml.XMLParseException)

Example 13 with DataType

use of dr.evolution.datatype.DataType in project beast-mcmc by beast-dev.

the class IstvanOperator method initSubstitutionModel.

/**
 * initialize the iProbs array from the substitution model -- must be called after populating tree!
 */
private void initSubstitutionModel(SubstitutionModel model) {
    DataType dataType = model.getDataType();
    int stateCount = dataType.getStateCount();
    iProbs = new double[iTau.length][stateCount][stateCount];
    double[] transProb = new double[stateCount * stateCount];
    int count;
    for (int i = 0; i < iTau.length; i++) {
        model.getTransitionProbabilities(iTau[i], transProb);
        count = 0;
        for (int j = 0; j < stateCount; j++) {
            for (int k = 0; k < stateCount; k++) {
                iProbs[i][j][k] = transProb[count];
                count += 1;
            }
        }
    }
    // initialize equlibrium distribution
    iBaseFreqs = new double[stateCount];
    for (int k = 0; k < stateCount; k++) {
        iBaseFreqs[k] = model.getFrequencyModel().getFrequency(k);
    }
}
Also used : DataType(dr.evolution.datatype.DataType)

Example 14 with DataType

use of dr.evolution.datatype.DataType in project beast-mcmc by beast-dev.

the class IstvanOperator method initAlignment.

/**
 * Initializes the iAlignment array from the given alignment.
 */
private void initAlignment(Alignment alignment, int[] treeIndex) {
    int numSeqs = alignment.getSequenceCount();
    int numSites = alignment.getSiteCount();
    DataType dataType = alignment.getDataType();
    int numStates = dataType.getStateCount();
    iAlignment = new int[numSeqs][numSites];
    // populate alignment in order of tree
    for (int i = 0; i < numSeqs; i++) {
        for (int j = 0; j < numSites; j++) {
            iAlignment[treeIndex[i]][j] = alignment.getState(i, j);
        }
    }
}
Also used : DataType(dr.evolution.datatype.DataType)

Example 15 with DataType

use of dr.evolution.datatype.DataType in project beast-mcmc by beast-dev.

the class HomologyRecursion method initAlignment.

/**
 * Initializes the iAlignment array from the given alignment.
 */
private void initAlignment(Alignment alignment, int[] treeIndex) {
    int numSeqs = alignment.getSequenceCount();
    int numSites = alignment.getSiteCount();
    DataType dataType = alignment.getDataType();
    int numStates = dataType.getStateCount();
    iAlignment = new IntMathVec[numSites];
    int[] column = new int[numSeqs];
    for (int i = 0; i < numSites; i++) {
        for (int j = 0; j < numSeqs; j++) {
            column[treeIndex[j]] = ((alignment.getState(j, i) >= numStates) ? 0 : 1);
        }
        iAlignment[i] = new IntMathVec(column);
    }
}
Also used : DataType(dr.evolution.datatype.DataType)

Aggregations

DataType (dr.evolution.datatype.DataType)66 Parameter (dr.inference.model.Parameter)26 FrequencyModel (dr.evomodel.substmodel.FrequencyModel)11 FrequencyModel (dr.oldevomodel.substmodel.FrequencyModel)11 ArrayList (java.util.ArrayList)8 Sequence (dr.evolution.sequence.Sequence)7 PartitionSubstitutionModel (dr.app.beauti.options.PartitionSubstitutionModel)4 PatternList (dr.evolution.alignment.PatternList)4 GeneralDataType (dr.evolution.datatype.GeneralDataType)4 Taxon (dr.evolution.util.Taxon)4 TaxonList (dr.evolution.util.TaxonList)4 GeneralSubstitutionModel (dr.evomodel.substmodel.GeneralSubstitutionModel)4 SVSComplexSubstitutionModel (dr.oldevomodel.substmodel.SVSComplexSubstitutionModel)4 Attribute (dr.util.Attribute)4 Codons (dr.evolution.datatype.Codons)3 HiddenDataType (dr.evolution.datatype.HiddenDataType)3 NodeRef (dr.evolution.tree.NodeRef)3 Tree (dr.evolution.tree.Tree)3 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)3 SubstitutionModel (dr.evomodel.substmodel.SubstitutionModel)3