Search in sources :

Example 1 with GeneralDataType

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

the class SpecificEigendecompositionTest method setupModel.

private ComplexSubstitutionModel setupModel(int dim, double[] rates) {
    String[] labels = new String[dim];
    for (Integer i = 0; i < dim; i++) {
        labels[i] = i.toString();
    }
    GeneralDataType dataType = new GeneralDataType(labels);
    Parameter freqVector = new Parameter.Default(dim);
    for (int i = 0; i < dim; i++) {
        freqVector.setParameterValue(i, (double) 1 / dim);
    }
    FrequencyModel freqModel = new FrequencyModel(dataType, freqVector);
    Parameter rateVector = new Parameter.Default(rates);
    return new ComplexSubstitutionModel("test", dataType, freqModel, rateVector) {

        protected EigenSystem getDefaultEigenSystem(int stateCount) {
            return new ComplexColtEigenSystem(stateCount, false, ColtEigenSystem.defaultMaxConditionNumber, ColtEigenSystem.defaultMaxIterations);
        }
    };
}
Also used : GeneralDataType(dr.evolution.datatype.GeneralDataType) Parameter(dr.inference.model.Parameter)

Example 2 with GeneralDataType

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

the class GeneralDataTypeParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    List<String> states = new ArrayList<String>();
    for (int i = 0; i < xo.getChildCount(); i++) {
        if (xo.getChild(i) instanceof XMLObject) {
            XMLObject cxo = (XMLObject) xo.getChild(i);
            if (cxo.getName().equals(STATE)) {
                states.add(cxo.getStringAttribute(CODE));
            } else if (cxo.getName().equals(ALIAS)) {
            // Do nothing just now
            } else if (cxo.getName().equals(AMBIGUITY)) {
            // Do nothing just now
            } else {
                throw new XMLParseException("illegal element, " + cxo.getName() + ", in " + getParserName() + " element");
            }
        } else if (xo.getChild(i) instanceof Identifiable) {
            states.add(((Identifiable) xo.getChild(i)).getId());
        } else {
            throw new XMLParseException("illegal element in " + getParserName() + " element");
        }
    }
    if (states.size() == 0) {
        throw new XMLParseException("No state elements defined in " + getParserName() + " element");
    } else if (states.size() < 2) {
        throw new XMLParseException("Less than two state elements defined in " + getParserName() + " element");
    }
    GeneralDataType dataType = new GeneralDataType(states);
    for (int i = 0; i < xo.getChildCount(); i++) {
        if (xo.getChild(i) instanceof XMLObject) {
            XMLObject cxo = (XMLObject) xo.getChild(i);
            if (cxo.getName().equals(ALIAS)) {
                String alias = cxo.getStringAttribute(CODE);
                //                    if (alias.length() != 1) {
                //                        throw new XMLParseException("State alias codes in " + getParserName() + " element must be exactly one character");
                //                    }
                String state = cxo.getStringAttribute(STATE);
                try {
                    dataType.addAlias(alias, state);
                } catch (IllegalArgumentException iae) {
                    throw new XMLParseException(iae.getMessage() + "in " + getParserName() + " element");
                }
            } else if (cxo.getName().equals(AMBIGUITY)) {
                String code = cxo.getStringAttribute(CODE);
                //                    if (code.length() != 1) {
                //                        throw new XMLParseException("State ambiguity codes in " + getParserName() + " element must be exactly one character");
                //                    }
                String[] ambiguities = cxo.getStringArrayAttribute(STATES);
                if (ambiguities.length == 1) {
                    String codes = ambiguities[0];
                    if (codes.length() < 2) {
                        throw new XMLParseException("States for ambiguity code in " + getParserName() + " element are not ambiguous");
                    }
                    ambiguities = new String[codes.length()];
                    for (int j = 0; j < codes.length(); j++) {
                        ambiguities[j] = String.valueOf(codes.charAt(j));
                    }
                }
                try {
                    dataType.addAmbiguity(code, ambiguities);
                } catch (IllegalArgumentException iae) {
                    throw new XMLParseException(iae.getMessage() + "in " + getParserName() + " element");
                }
            }
        }
    }
    return dataType;
}
Also used : ArrayList(java.util.ArrayList) GeneralDataType(dr.evolution.datatype.GeneralDataType) Identifiable(dr.util.Identifiable)

Example 3 with GeneralDataType

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

the class Coevolve method makePairDataType.

private DataType makePairDataType(Alignment alignment) {
    DataType dataType = alignment.getDataType();
    int stateCount = dataType.getStateCount();
    String[] stateChars = new String[stateCount * stateCount];
    for (int i = 0; i < Math.min(10, stateChars.length); i++) {
        stateChars[i] = String.valueOf((char) ('0' + i));
    }
    if (stateCount > 10) {
        for (int i = 10; i < stateChars.length; i++) {
            stateChars[i] = String.valueOf((char) ('A' + i - 10));
        }
    }
    GeneralDataType newDataType = new GeneralDataType(stateChars);
    return newDataType;
}
Also used : GeneralDataType(dr.evolution.datatype.GeneralDataType) DataType(dr.evolution.datatype.DataType) GeneralDataType(dr.evolution.datatype.GeneralDataType)

Example 4 with GeneralDataType

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

the class GeneralF81Model method main.

public static void main(String[] args) {
    GeneralDataType general = new GeneralDataType(new String[] { "0", "1", "2" });
    FrequencyModel freqModel = new FrequencyModel(general, new double[] { 0.2, 0.3, 0.5 });
    GeneralF81Model f81 = new GeneralF81Model(freqModel);
    int S = general.getStateCount();
    double[] P = new double[S * S];
    f81.getTransitionProbabilities(0.01, P);
    int c = 0;
    for (int i = 0; i < S; i++) {
        System.out.print(P[c]);
        double rowSum = P[c];
        c += 1;
        for (int j = 1; j < S; j++) {
            System.out.print(", " + P[c]);
            rowSum += P[c];
            c += 1;
        }
        System.out.println(" : " + rowSum);
    }
}
Also used : GeneralDataType(dr.evolution.datatype.GeneralDataType)

Example 5 with GeneralDataType

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

the class CompositeDataTypeParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    List<String> states = new ArrayList<String>();
    List<DataType> dataTypes = new ArrayList<DataType>();
    for (int i = 0; i < xo.getChildCount(); i++) {
        if (xo.getChild(i) instanceof DataType) {
            dataTypes.add((DataType) xo.getChild(i));
        } else {
            throw new XMLParseException("illegal element in " + getParserName() + " element");
        }
    }
    if (dataTypes.size() != 2) {
        throw new XMLParseException("CompositeDataType requires exactly 2 component DataTypes");
    }
    DataType dt1 = dataTypes.get(0);
    DataType dt2 = dataTypes.get(1);
    List<String> jointStates = new ArrayList<String>();
    for (int state1 = 0; state1 < dt1.getStateCount(); state1++) {
        String code1 = dt1.getCode(state1);
        for (int state2 = 0; state2 < dt2.getStateCount(); state2++) {
            String code2 = dt2.getCode(state2);
            jointStates.add(code1 + COMPOSITE_STATE_SEPARATOR + code2);
        }
    }
    if (states.size() == 0) {
        throw new XMLParseException("No state elements defined in " + getParserName() + " element");
    } else if (states.size() < 2) {
        throw new XMLParseException("Fewer than two state elements defined in " + getParserName() + " element");
    }
    GeneralDataType dataType = new GeneralDataType(states);
    return dataType;
}
Also used : ArrayList(java.util.ArrayList) GeneralDataType(dr.evolution.datatype.GeneralDataType) DataType(dr.evolution.datatype.DataType) GeneralDataType(dr.evolution.datatype.GeneralDataType)

Aggregations

GeneralDataType (dr.evolution.datatype.GeneralDataType)7 ArrayList (java.util.ArrayList)3 DataType (dr.evolution.datatype.DataType)2 Parameter (dr.inference.model.Parameter)1 FrequencyModel (dr.oldevomodel.substmodel.FrequencyModel)1 GeneralF81Model (dr.oldevomodel.substmodel.GeneralF81Model)1 Identifiable (dr.util.Identifiable)1