Search in sources :

Example 1 with MutationDeathType

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

the class MutationDeathModelParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Parameter dummyFreqParameter;
    Parameter delParam = (Parameter) xo.getChild(Parameter.class);
    Logger.getLogger("dr.evomodel").info("Creating MutationDeath substitution model.\n\tInitial death rate is " + delParam.getParameterValue(0));
    MutationDeathType dT = (MutationDeathType) xo.getChild(MutationDeathType.class);
    SubstitutionModel evoModel = (SubstitutionModel) xo.getChild(SubstitutionModel.class);
    if (evoModel == null) {
        // Assuming pure survival model
        Logger.getLogger("dr.evomodel").info("\tSubstitutionModel not provided assuming pure death/survival model.");
        dummyFreqParameter = new Parameter.Default(new double[] { 1.0, 0.0 });
    } else {
        dummyFreqParameter = new Parameter.Default(dT.getStateCount());
        double[] freqs = evoModel.getFrequencyModel().getFrequencies();
        for (int i = 0; i < freqs.length; ++i) {
            dummyFreqParameter.setParameterValueQuietly(i, freqs[i]);
        }
        dummyFreqParameter.setParameterValueQuietly(dT.getStateCount() - 1, 0.0);
    }
    FrequencyModel dummyFrequencies = new FrequencyModel(dT, dummyFreqParameter);
    Parameter mutationRate;
    if (xo.hasChildNamed(MUTATION_RATE)) {
        mutationRate = (Parameter) xo.getElementFirstChild(MUTATION_RATE);
    } else {
        mutationRate = new Parameter.Default(new double[] { 1.0 });
    }
    Logger.getLogger("dr.evomodel").info("\tInitial mutation rate is " + mutationRate.getParameterValue(0));
    return new MutationDeathModel(delParam, dT, evoModel, dummyFrequencies, mutationRate);
}
Also used : FrequencyModel(dr.evomodel.substmodel.FrequencyModel) Parameter(dr.inference.model.Parameter) MutationDeathModel(dr.evomodel.substmodel.MutationDeathModel) MutationDeathType(dr.evolution.datatype.MutationDeathType) SubstitutionModel(dr.evomodel.substmodel.SubstitutionModel)

Example 2 with MutationDeathType

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

the class MutationDeathTypeParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Logger.getLogger("dr.evolution").info("\nCreating an extended data type.");
    Logger.getLogger("dr.evolution").info("\tIf you publish results using this model, please reference Alekseyenko, Lee and Suchard (in submision).\n");
    DataType dataType = DataTypeUtils.getDataType(xo);
    char extantChar = '\0';
    XMLObject cxo = xo.getChild(EXTANT);
    if (cxo != null) {
        extantChar = cxo.getStringAttribute(CODE).charAt(0);
    }
    cxo = xo.getChild(STATE);
    char stateChar;
    if (cxo != null) {
        stateChar = cxo.getStringAttribute(CODE).charAt(0);
    } else {
        stateChar = dataType.getChar(dataType.getGapState());
    }
    Logger.getLogger("dr.evolution").info("\tNon-existent code: " + stateChar);
    if (dataType == null && extantChar == '\0')
        throw new XMLParseException("In " + xo.getName() + " you must either provide a data type or a code for extant state");
    MutationDeathType mdt;
    if (dataType != null) {
        Logger.getLogger("dr.evolution").info("\tBase type: " + dataType.toString());
        mdt = new MutationDeathType(dataType, stateChar);
    } else {
        Logger.getLogger("dr.evolution").info("\tExtant code: " + extantChar);
        mdt = new MutationDeathType(stateChar, extantChar);
    }
    char ambiguityChar = '\0';
    String states;
    Object dxo;
    for (int i = 0; i < xo.getChildCount(); ++i) {
        dxo = xo.getChild(i);
        if (dxo instanceof XMLObject) {
            cxo = (XMLObject) dxo;
            if (cxo.getName().equals(AMBIGUITY)) {
                ambiguityChar = cxo.getStringAttribute(CODE).charAt(0);
                if (cxo.hasAttribute(STATES)) {
                    states = cxo.getStringAttribute(STATES);
                } else {
                    states = "";
                }
                mdt.addAmbiguity(ambiguityChar, states);
                Logger.getLogger("dr.evolution").info("\tAmbiguity code: " + ambiguityChar);
            }
        }
    }
    return mdt;
}
Also used : DataType(dr.evolution.datatype.DataType) MutationDeathType(dr.evolution.datatype.MutationDeathType)

Example 3 with MutationDeathType

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

the class MutationDeathModelParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Parameter dummyFreqParameter;
    Parameter delParam = (Parameter) xo.getChild(Parameter.class);
    Logger.getLogger("dr.evomodel").info("Creating MutationDeath substitution model.\n\tInitial death rate is " + delParam.getParameterValue(0));
    MutationDeathType dT = (MutationDeathType) xo.getChild(MutationDeathType.class);
    AbstractSubstitutionModel evoModel = (AbstractSubstitutionModel) xo.getChild(AbstractSubstitutionModel.class);
    if (evoModel == null) {
        // Assuming pure survival model
        Logger.getLogger("dr.evomodel").info("\tSubstitutionModel not provided assuming pure death/survival model.");
        dummyFreqParameter = new Parameter.Default(new double[] { 1.0, 0.0 });
    } else {
        dummyFreqParameter = new Parameter.Default(dT.getStateCount());
        double[] freqs = evoModel.getFrequencyModel().getFrequencies();
        for (int i = 0; i < freqs.length; ++i) {
            dummyFreqParameter.setParameterValueQuietly(i, freqs[i]);
        }
        dummyFreqParameter.setParameterValueQuietly(dT.getStateCount() - 1, 0.0);
    }
    FrequencyModel dummyFrequencies = new FrequencyModel(dT, dummyFreqParameter);
    Parameter mutationRate;
    if (xo.hasChildNamed(MUTATION_RATE)) {
        mutationRate = (Parameter) xo.getElementFirstChild(MUTATION_RATE);
    } else {
        mutationRate = new Parameter.Default(new double[] { 1.0 });
    }
    Logger.getLogger("dr.evomodel").info("\tInitial mutation rate is " + mutationRate.getParameterValue(0));
    return new MutationDeathModel(delParam, dT, evoModel, dummyFrequencies, mutationRate);
}
Also used : FrequencyModel(dr.oldevomodel.substmodel.FrequencyModel) AbstractSubstitutionModel(dr.oldevomodel.substmodel.AbstractSubstitutionModel) Parameter(dr.inference.model.Parameter) MutationDeathModel(dr.oldevomodel.substmodel.MutationDeathModel) MutationDeathType(dr.evolution.datatype.MutationDeathType)

Aggregations

MutationDeathType (dr.evolution.datatype.MutationDeathType)3 Parameter (dr.inference.model.Parameter)2 DataType (dr.evolution.datatype.DataType)1 FrequencyModel (dr.evomodel.substmodel.FrequencyModel)1 MutationDeathModel (dr.evomodel.substmodel.MutationDeathModel)1 SubstitutionModel (dr.evomodel.substmodel.SubstitutionModel)1 AbstractSubstitutionModel (dr.oldevomodel.substmodel.AbstractSubstitutionModel)1 FrequencyModel (dr.oldevomodel.substmodel.FrequencyModel)1 MutationDeathModel (dr.oldevomodel.substmodel.MutationDeathModel)1