Search in sources :

Example 46 with DataType

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

the class AncestralStatesComponentGenerator method writeCountingParameter.

// END: generate
private void writeCountingParameter(XMLWriter writer, AbstractPartitionData partition, String prefix) {
    AncestralStatesComponentOptions component = (AncestralStatesComponentOptions) options.getComponentOptions(AncestralStatesComponentOptions.class);
    if (!component.isCountingStates(partition)) {
        return;
    }
    StringBuilder matrix = new StringBuilder();
    DataType dataType = partition.getDataType();
    int stateCount = dataType.getStateCount();
    if (dataType.getType() == DataType.GENERAL) {
        PartitionSubstitutionModel substModel = partition.getPartitionSubstitutionModel();
        stateCount = substModel.getDiscreteStateSet().size();
    }
    for (int i = 0; i < stateCount; i++) {
        for (int j = 0; j < stateCount; j++) {
            if (i == j) {
                matrix.append(" 0.0");
            } else {
                matrix.append(" 1.0");
            }
        }
    }
    writer.writeTag("parameter", new Attribute[] { new Attribute.Default<String>("id", partition.getPrefix() + "count"), new Attribute.Default<String>("value", matrix.toString()) }, true);
}
Also used : Attribute(dr.util.Attribute) DataType(dr.evolution.datatype.DataType) PartitionSubstitutionModel(dr.app.beauti.options.PartitionSubstitutionModel)

Example 47 with DataType

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

the class ExtractPairs method getPairAlignment.

public Alignment getPairAlignment(int x, int y) {
    SimpleAlignment pairAlignment = new SimpleAlignment();
    StringBuffer sequence0 = new StringBuffer();
    StringBuffer sequence1 = new StringBuffer();
    DataType dataType = alignment.getDataType();
    int stateCount = dataType.getStateCount();
    for (int i = 0; i < alignment.getSiteCount(); i++) {
        int s0 = alignment.getState(x, i);
        int s1 = alignment.getState(y, i);
        char c0 = dataType.getChar(s0);
        char c1 = dataType.getChar(s1);
        if (s0 < stateCount || s1 < stateCount) {
            sequence0.append(c0);
            sequence1.append(c1);
        }
    }
    // trim hanging ends on left
    int left = 0;
    while ((dataType.getState(sequence0.charAt(left)) >= stateCount) || (dataType.getState(sequence1.charAt(left)) >= stateCount)) {
        left += 1;
    }
    // trim hanging ends on right
    int right = sequence0.length() - 1;
    while ((dataType.getState(sequence0.charAt(right)) >= stateCount) || (dataType.getState(sequence1.charAt(right)) >= stateCount)) {
        right -= 1;
    }
    if (right < left)
        return null;
    String sequenceString0 = sequence0.substring(left, right + 1);
    String sequenceString1 = sequence1.substring(left, right + 1);
    pairAlignment.addSequence(new Sequence(alignment.getTaxon(x), sequenceString0));
    pairAlignment.addSequence(new Sequence(alignment.getTaxon(y), sequenceString1));
    return pairAlignment;
}
Also used : DataType(dr.evolution.datatype.DataType) Sequence(dr.evolution.sequence.Sequence)

Example 48 with DataType

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

the class GapStrippedAlignment method getSequence.

/**
     * Very inefficient implementation, use sparingly
     * @param sequenceIndex
     * @return
     */
public final Sequence getSequence(int sequenceIndex) {
    DataType dataType = getDataType();
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < alignment.getSiteCount(); i++) {
        if (!hasGap[i]) {
            buffer.append(dataType.getChar(alignment.getState(sequenceIndex, i)));
        }
    }
    return new Sequence(buffer.toString());
}
Also used : DataType(dr.evolution.datatype.DataType) Sequence(dr.evolution.sequence.Sequence)

Example 49 with DataType

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

the class ImportanceNarrowExchange method setTaxaWeights.

private void setTaxaWeights(PatternList patterns) throws Exception {
    final DataType type = patterns.getDataType();
    Map<Integer, Integer> counts = new HashMap<Integer, Integer>();
    int[] taxaCounts = new int[patterns.getPatternLength()];
    for (int nPat = 0; nPat < patterns.getPatternCount(); ++nPat) {
        final int[] pattern = patterns.getPattern(nPat);
        counts.clear();
        for (int s : pattern) {
            if (type.isGapState(s) || type.isAmbiguousState(s) || type.isUnknownState(s)) {
                continue;
            }
            if (!counts.containsKey(s)) {
                counts.put(s, 0);
            }
            counts.put(s, counts.get(s) + 1);
        }
        if (counts.size() <= 1) {
            continue;
        }
        Map.Entry<Integer, Integer> m = null;
        for (Map.Entry<Integer, Integer> e : counts.entrySet()) {
            if (m == null || e.getValue() > m.getValue()) {
                m = e;
            }
        }
        assert m != null;
        for (int i = 0; i < pattern.length; ++i) {
            final int s = pattern[i];
            if (!(type.isGapState(s) || type.isAmbiguousState(s) || type.isUnknownState(s))) {
                if (s != m.getKey()) {
                    taxaCounts[i] += patterns.getPatternWeight(nPat);
                }
            }
        }
    }
    nodeCounts = new int[tree.getNodeCount()];
    Map<Taxon, Integer> taxaWeights = new HashMap<Taxon, Integer>();
    for (int i = 0; i < taxaCounts.length; ++i) {
        taxaWeights.put(patterns.getTaxon(i), taxaCounts[i]);
    }
    for (int i = 0; i < tree.getExternalNodeCount(); ++i) {
        final NodeRef leaf = tree.getExternalNode(i);
        final Taxon nodeTaxon = tree.getNodeTaxon(leaf);
        //            assert taxaWeights.containsKey(nodeTaxon) : nodeTaxon;
        if (!taxaWeights.containsKey(nodeTaxon)) {
            throw new Exception("" + nodeTaxon + " in tree " + tree.getId() + " not in patterns" + patterns.getId() + ".");
        }
        nodeCounts[leaf.getNumber()] = taxaWeights.get(nodeTaxon);
    }
}
Also used : NodeRef(dr.evolution.tree.NodeRef) HashMap(java.util.HashMap) Taxon(dr.evolution.util.Taxon) DataType(dr.evolution.datatype.DataType) Map(java.util.Map) HashMap(java.util.HashMap)

Example 50 with DataType

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

the class BinarySubstitutionModelParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Parameter ratesParameter;
    XMLObject cxo = xo.getChild(dr.oldevomodelxml.substmodel.GeneralSubstitutionModelParser.FREQUENCIES);
    FrequencyModel freqModel = (FrequencyModel) cxo.getChild(FrequencyModel.class);
    DataType dataType = freqModel.getDataType();
    if (dataType != TwoStates.INSTANCE)
        throw new XMLParseException("Frequency model must have binary (two state) data type.");
    int relativeTo = 0;
    ratesParameter = new Parameter.Default(0);
    return new GeneralSubstitutionModel(getParserName(), dataType, freqModel, ratesParameter, relativeTo);
}
Also used : FrequencyModel(dr.evomodel.substmodel.FrequencyModel) Parameter(dr.inference.model.Parameter) DataType(dr.evolution.datatype.DataType) GeneralSubstitutionModel(dr.evomodel.substmodel.GeneralSubstitutionModel)

Aggregations

DataType (dr.evolution.datatype.DataType)58 Parameter (dr.inference.model.Parameter)24 FrequencyModel (dr.oldevomodel.substmodel.FrequencyModel)11 FrequencyModel (dr.evomodel.substmodel.FrequencyModel)10 Sequence (dr.evolution.sequence.Sequence)6 GeneralDataType (dr.evolution.datatype.GeneralDataType)4 Taxon (dr.evolution.util.Taxon)4 SVSComplexSubstitutionModel (dr.oldevomodel.substmodel.SVSComplexSubstitutionModel)4 ArrayList (java.util.ArrayList)4 PartitionSubstitutionModel (dr.app.beauti.options.PartitionSubstitutionModel)3 PatternList (dr.evolution.alignment.PatternList)3 HiddenDataType (dr.evolution.datatype.HiddenDataType)3 NodeRef (dr.evolution.tree.NodeRef)3 Tree (dr.evolution.tree.Tree)3 TaxonList (dr.evolution.util.TaxonList)3 GeneralSubstitutionModel (dr.evomodel.substmodel.GeneralSubstitutionModel)3 GeneralSubstitutionModel (dr.oldevomodel.substmodel.GeneralSubstitutionModel)3 SimpleAlignment (dr.evolution.alignment.SimpleAlignment)2 Codons (dr.evolution.datatype.Codons)2 TreeTraitProvider (dr.evolution.tree.TreeTraitProvider)2