Search in sources :

Example 26 with FrequencyModel

use of dr.oldevomodel.substmodel.FrequencyModel in project beast-mcmc by beast-dev.

the class TwoStateCovarionModelParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Parameter alphaParameter;
    Parameter switchingRateParameter;
    XMLObject cxo = xo.getChild(AbstractCovarionDNAModel.FREQUENCIES);
    FrequencyModel freqModel = (FrequencyModel) cxo.getChild(FrequencyModel.class);
    // fancy new datatype courtesy of Helen
    TwoStateCovarion dataType = TwoStateCovarion.INSTANCE;
    cxo = xo.getChild(ALPHA);
    alphaParameter = (Parameter) cxo.getChild(Parameter.class);
    // alpha must be positive and less than 1.0 because the fast rate is normalized to 1.0
    alphaParameter.addBounds(new Parameter.DefaultBounds(1.0, 0.0, 1));
    cxo = xo.getChild(SWITCHING_RATE);
    switchingRateParameter = (Parameter) cxo.getChild(Parameter.class);
    if (dataType != freqModel.getDataType()) {
        throw new XMLParseException("Data type of " + getParserName() + " element does not match that of its frequencyModel.");
    }
    TwoStateCovarionModel model = new TwoStateCovarionModel(dataType, freqModel, alphaParameter, switchingRateParameter);
    System.out.println(model);
    return model;
}
Also used : FrequencyModel(dr.oldevomodel.substmodel.FrequencyModel) TwoStateCovarionModel(dr.oldevomodel.substmodel.TwoStateCovarionModel) Parameter(dr.inference.model.Parameter) TwoStateCovarion(dr.evolution.datatype.TwoStateCovarion)

Example 27 with FrequencyModel

use of dr.oldevomodel.substmodel.FrequencyModel in project beast-mcmc by beast-dev.

the class YangCodonModelParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Codons codons = Codons.UNIVERSAL;
    if (xo.hasAttribute(GeneticCode.GENETIC_CODE)) {
        String codeStr = xo.getStringAttribute(GeneticCode.GENETIC_CODE);
        if (codeStr.equals(GeneticCode.UNIVERSAL.getName())) {
            codons = Codons.UNIVERSAL;
        } else if (codeStr.equals(GeneticCode.VERTEBRATE_MT.getName())) {
            codons = Codons.VERTEBRATE_MT;
        } else if (codeStr.equals(GeneticCode.YEAST.getName())) {
            codons = Codons.YEAST;
        } else if (codeStr.equals(GeneticCode.MOLD_PROTOZOAN_MT.getName())) {
            codons = Codons.MOLD_PROTOZOAN_MT;
        } else if (codeStr.equals(GeneticCode.INVERTEBRATE_MT.getName())) {
            codons = Codons.INVERTEBRATE_MT;
        } else if (codeStr.equals(GeneticCode.CILIATE.getName())) {
            codons = Codons.CILIATE;
        } else if (codeStr.equals(GeneticCode.ECHINODERM_MT.getName())) {
            codons = Codons.ECHINODERM_MT;
        } else if (codeStr.equals(GeneticCode.EUPLOTID_NUC.getName())) {
            codons = Codons.EUPLOTID_NUC;
        } else if (codeStr.equals(GeneticCode.BACTERIAL.getName())) {
            codons = Codons.BACTERIAL;
        } else if (codeStr.equals(GeneticCode.ALT_YEAST.getName())) {
            codons = Codons.ALT_YEAST;
        } else if (codeStr.equals(GeneticCode.ASCIDIAN_MT.getName())) {
            codons = Codons.ASCIDIAN_MT;
        } else if (codeStr.equals(GeneticCode.FLATWORM_MT.getName())) {
            codons = Codons.FLATWORM_MT;
        } else if (codeStr.equals(GeneticCode.BLEPHARISMA_NUC.getName())) {
            codons = Codons.BLEPHARISMA_NUC;
        } else if (codeStr.equals(GeneticCode.NO_STOPS.getName())) {
            codons = Codons.NO_STOPS;
        }
    }
    Parameter omegaParam = (Parameter) xo.getElementFirstChild(OMEGA);
    Parameter kappaParam = (Parameter) xo.getElementFirstChild(KAPPA);
    FrequencyModel freqModel = (FrequencyModel) xo.getChild(FrequencyModel.class);
    return new YangCodonModel(codons, omegaParam, kappaParam, freqModel);
}
Also used : FrequencyModel(dr.oldevomodel.substmodel.FrequencyModel) Parameter(dr.inference.model.Parameter) Codons(dr.evolution.datatype.Codons) YangCodonModel(dr.oldevomodel.substmodel.YangCodonModel)

Example 28 with FrequencyModel

use of dr.oldevomodel.substmodel.FrequencyModel in project beast-mcmc by beast-dev.

the class ComplexSubstitutionModelParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    DataType dataType = DataTypeUtils.getDataType(xo);
    if (dataType == null)
        dataType = (DataType) xo.getChild(DataType.class);
    XMLObject cxo = xo.getChild(RATES);
    Parameter ratesParameter = (Parameter) cxo.getChild(Parameter.class);
    int rateCount = (dataType.getStateCount() - 1) * dataType.getStateCount();
    if (ratesParameter.getDimension() != rateCount) {
        throw new XMLParseException("Rates parameter in " + getParserName() + " element should have " + (rateCount) + " dimensions.  However parameter dimension is " + ratesParameter.getDimension());
    }
    cxo = xo.getChild(ROOT_FREQUENCIES);
    FrequencyModel rootFreq = (FrequencyModel) cxo.getChild(FrequencyModel.class);
    if (dataType != rootFreq.getDataType()) {
        throw new XMLParseException("Data type of " + getParserName() + " element does not match that of its rootFrequencyModel.");
    }
    Parameter indicators = null;
    if (xo.hasChildNamed(INDICATOR)) {
        indicators = (Parameter) ((XMLObject) xo.getChild(INDICATOR)).getChild(Parameter.class);
        if (ratesParameter.getDimension() != indicators.getDimension())
            throw new XMLParseException("Rate parameter dimension must match indicator parameter dimension");
    }
    StringBuffer sb = new StringBuffer().append("Constructing a complex substitution model using\n").append("\tRate parameters: ").append(ratesParameter.getId()).append("\n").append("\tRoot frequency model: ").append(rootFreq.getId()).append("\n");
    ComplexSubstitutionModel model;
    if (indicators == null)
        model = new ComplexSubstitutionModel(xo.getId(), dataType, rootFreq, ratesParameter);
    else {
        boolean randomize = xo.getAttribute(RANDOMIZE, false);
        boolean connected = xo.getAttribute(CONNECTED, false);
        model = new SVSComplexSubstitutionModel(xo.getId(), dataType, rootFreq, ratesParameter, indicators);
        if (randomize) {
            BayesianStochasticSearchVariableSelection.Utils.randomize(indicators, dataType.getStateCount(), false);
            boolean valid = !Double.isInfinite(model.getLogLikelihood());
            if (!valid) {
                throw new XMLParseException("Poor tolerance in complex substitution model.  Please retry analysis using BEAGLE");
            }
        }
        sb.append("\tBSSVS indicators: ").append(indicators.getId()).append("\n");
        sb.append("\tGraph must be connected: ").append(connected).append("\n");
    }
    boolean doNormalization = xo.getAttribute(NORMALIZATION, true);
    model.setNormalization(doNormalization);
    sb.append("\tNormalized: ").append(doNormalization).append("\n");
    boolean checkConditioning = xo.getAttribute(CHECK_CONDITIONING, true);
    model.setCheckConditioning(checkConditioning);
    if (checkConditioning) {
        double maxConditionNumber = xo.getAttribute(MAX_CONDITION_NUMBER, 1000);
        model.setMaxConditionNumber(maxConditionNumber);
        sb.append("\tMax. condition number: ").append(maxConditionNumber).append("\n");
    }
    int maxIterations = xo.getAttribute(MAX_ITERATIONS, 1000);
    model.setMaxIterations(maxIterations);
    sb.append("\tMax iterations: ").append(maxIterations).append("\n");
    sb.append("\t\tPlease cite Edwards, Suchard et al. (2011)\n");
    Logger.getLogger("dr.evomodel.substmodel").info(sb.toString());
    return model;
}
Also used : FrequencyModel(dr.oldevomodel.substmodel.FrequencyModel) SVSComplexSubstitutionModel(dr.oldevomodel.substmodel.SVSComplexSubstitutionModel) SVSComplexSubstitutionModel(dr.oldevomodel.substmodel.SVSComplexSubstitutionModel) ComplexSubstitutionModel(dr.oldevomodel.substmodel.ComplexSubstitutionModel) DataType(dr.evolution.datatype.DataType) Parameter(dr.inference.model.Parameter)

Example 29 with FrequencyModel

use of dr.oldevomodel.substmodel.FrequencyModel in project beast-mcmc by beast-dev.

the class CovarionGTRParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    XMLObject cxo = xo.getChild(AbstractCovarionDNAModel.FREQUENCIES);
    FrequencyModel freqModel = (FrequencyModel) cxo.getChild(FrequencyModel.class);
    OldHiddenNucleotides dataType = (OldHiddenNucleotides) freqModel.getDataType();
    Parameter hiddenRates = (Parameter) xo.getElementFirstChild(AbstractCovarionDNAModel.HIDDEN_CLASS_RATES);
    Parameter switchingRates = (Parameter) xo.getElementFirstChild(AbstractCovarionDNAModel.SWITCHING_RATES);
    Parameter rateACParameter = null;
    if (xo.hasChildNamed(GTRParser.A_TO_C)) {
        rateACParameter = (Parameter) xo.getElementFirstChild(GTRParser.A_TO_C);
    }
    Parameter rateAGParameter = null;
    if (xo.hasChildNamed(GTRParser.A_TO_G)) {
        rateAGParameter = (Parameter) xo.getElementFirstChild(GTRParser.A_TO_G);
    }
    Parameter rateATParameter = null;
    if (xo.hasChildNamed(GTRParser.A_TO_T)) {
        rateATParameter = (Parameter) xo.getElementFirstChild(GTRParser.A_TO_T);
    }
    Parameter rateCGParameter = null;
    if (xo.hasChildNamed(GTRParser.C_TO_G)) {
        rateCGParameter = (Parameter) xo.getElementFirstChild(GTRParser.C_TO_G);
    }
    Parameter rateCTParameter = null;
    if (xo.hasChildNamed(GTRParser.C_TO_T)) {
        rateCTParameter = (Parameter) xo.getElementFirstChild(GTRParser.C_TO_T);
    }
    Parameter rateGTParameter = null;
    if (xo.hasChildNamed(GTRParser.G_TO_T)) {
        rateGTParameter = (Parameter) xo.getElementFirstChild(GTRParser.G_TO_T);
    }
    if (dataType != freqModel.getDataType()) {
        throw new XMLParseException("Data type of " + getParserName() + " element does not match that of its frequencyModel.");
    }
    return new CovarionGTR(dataType, hiddenRates, switchingRates, rateACParameter, rateAGParameter, rateATParameter, rateCGParameter, rateCTParameter, rateGTParameter, freqModel);
}
Also used : FrequencyModel(dr.oldevomodel.substmodel.FrequencyModel) OldHiddenNucleotides(dr.evolution.datatype.OldHiddenNucleotides) Parameter(dr.inference.model.Parameter) CovarionGTR(dr.oldevomodel.substmodel.CovarionGTR)

Example 30 with FrequencyModel

use of dr.oldevomodel.substmodel.FrequencyModel in project beast-mcmc by beast-dev.

the class CovarionHKYParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Parameter kappaParam;
    Parameter switchingRates;
    Parameter hiddenClassRates;
    FrequencyModel freqModel;
    kappaParam = (Parameter) xo.getElementFirstChild(KAPPA);
    switchingRates = (Parameter) xo.getElementFirstChild(AbstractCovarionDNAModel.SWITCHING_RATES);
    hiddenClassRates = (Parameter) xo.getElementFirstChild(AbstractCovarionDNAModel.HIDDEN_CLASS_RATES);
    freqModel = (FrequencyModel) xo.getElementFirstChild(AbstractCovarionDNAModel.FREQUENCIES);
    if (!(freqModel.getDataType() instanceof OldHiddenNucleotides)) {
        throw new IllegalArgumentException("Datatype must be hidden nucleotides!!");
    }
    OldHiddenNucleotides dataType = (OldHiddenNucleotides) freqModel.getDataType();
    int hiddenStateCount = dataType.getHiddenClassCount();
    int switchingRatesCount = hiddenStateCount * (hiddenStateCount - 1) / 2;
    if (switchingRates.getDimension() != switchingRatesCount) {
        throw new IllegalArgumentException("switching rates parameter must have " + switchingRatesCount + " dimensions, for " + hiddenStateCount + " hidden categories");
    }
    CovarionHKY model = new CovarionHKY(dataType, kappaParam, hiddenClassRates, switchingRates, freqModel);
    System.out.println(model);
    return model;
}
Also used : FrequencyModel(dr.oldevomodel.substmodel.FrequencyModel) OldHiddenNucleotides(dr.evolution.datatype.OldHiddenNucleotides) Parameter(dr.inference.model.Parameter) CovarionHKY(dr.oldevomodel.substmodel.CovarionHKY)

Aggregations

FrequencyModel (dr.oldevomodel.substmodel.FrequencyModel)59 Parameter (dr.inference.model.Parameter)44 GammaSiteModel (dr.oldevomodel.sitemodel.GammaSiteModel)20 HKY (dr.oldevomodel.substmodel.HKY)18 SitePatterns (dr.evolution.alignment.SitePatterns)16 TreeLikelihood (dr.oldevomodel.treelikelihood.TreeLikelihood)16 DataType (dr.evolution.datatype.DataType)11 GeneralSubstitutionModel (dr.oldevomodel.substmodel.GeneralSubstitutionModel)6 ExchangeOperator (dr.evomodel.operators.ExchangeOperator)5 SubtreeSlideOperator (dr.evomodel.operators.SubtreeSlideOperator)5 WilsonBalding (dr.evomodel.operators.WilsonBalding)5 ArrayLogFormatter (dr.inference.loggers.ArrayLogFormatter)5 MCLogger (dr.inference.loggers.MCLogger)5 TabDelimitedFormatter (dr.inference.loggers.TabDelimitedFormatter)5 MCMC (dr.inference.mcmc.MCMC)5 MCMCOptions (dr.inference.mcmc.MCMCOptions)5 ArrayTraceList (dr.inference.trace.ArrayTraceList)5 Trace (dr.inference.trace.Trace)5 TraceCorrelation (dr.inference.trace.TraceCorrelation)5 GTR (dr.oldevomodel.substmodel.GTR)5