Search in sources :

Example 46 with FrequencyModel

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

the class EmpiricalAminoAcidModelParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    FrequencyModel freqModel = null;
    if (xo.hasAttribute(FREQUENCIES)) {
        XMLObject cxo = xo.getChild(FREQUENCIES);
        freqModel = (FrequencyModel) cxo.getChild(FrequencyModel.class);
    }
    EmpiricalRateMatrix rateMatrix = null;
    String type = xo.getStringAttribute(TYPE);
    if (type.equals(AminoAcidModelType.BLOSUM_62.getXMLName())) {
        rateMatrix = Blosum62.INSTANCE;
    } else if (type.equals(AminoAcidModelType.DAYHOFF.getXMLName())) {
        rateMatrix = Dayhoff.INSTANCE;
    } else if (type.equals(AminoAcidModelType.JTT.getXMLName())) {
        rateMatrix = JTT.INSTANCE;
    } else if (type.equals(AminoAcidModelType.MT_REV_24.getXMLName())) {
        rateMatrix = MTREV.INSTANCE;
    } else if (type.equals(AminoAcidModelType.CP_REV_45.getXMLName())) {
        rateMatrix = CPREV.INSTANCE;
    } else if (type.equals(AminoAcidModelType.WAG.getXMLName())) {
        rateMatrix = WAG.INSTANCE;
    } else if (type.equals(AminoAcidModelType.LG.getXMLName())) {
        rateMatrix = LG.INSTANCE;
    } else if (type.equals(AminoAcidModelType.FLU.getXMLName())) {
        rateMatrix = FLU.INSTANCE;
    } else {
        throw new XMLParseException("Unrecognized empirical amino acid model: " + type);
    }
    return new EmpiricalAminoAcidModel(rateMatrix, freqModel);
}
Also used : FrequencyModel(dr.evomodel.substmodel.FrequencyModel) EmpiricalRateMatrix(dr.evomodel.substmodel.EmpiricalRateMatrix)

Example 47 with FrequencyModel

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

the class EmpiricalCodonModelParser 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 = null;
    Parameter mntParam = null;
    if (xo.hasChildNamed(KAPPATSTV)) {
        kappaParam = (Parameter) xo.getElementFirstChild(KAPPATSTV);
        if (kappaParam.getDimension() != 2 && kappaParam.getDimension() != 9) {
            throw new XMLParseException("If you use the kappa parameter, you need to enter exactly\n" + "two values for ts and tv or nine values\n" + "according to the Kosiol ECM+F+omega+9k model");
        }
    } else {
        mntParam = (Parameter) xo.getElementFirstChild(MULTI_NT_CHANGE);
    }
    String dirString = xo.getStringAttribute(ECM_DATA_DIR);
    String freqString = xo.getStringAttribute(ECM_FREQ_MATRIX);
    String matString = xo.getStringAttribute(ECM_DATA_MATRIX);
    EmpiricalRateMatrixReader rateMat = new EmpiricalRateMatrixReader(EMPIRICAL_RATE_MATRIX, codons, dirString, freqString, matString);
    FrequencyModel freqModel = null;
    if (xo.getChild(FrequencyModel.class) != null) {
        freqModel = (FrequencyModel) xo.getChild(FrequencyModel.class);
    } else {
        freqModel = createNewFreqModel(codons, rateMat);
    }
    return new EmpiricalCodonModel(codons, omegaParam, kappaParam, mntParam, rateMat, freqModel);
}
Also used : FrequencyModel(dr.evomodel.substmodel.FrequencyModel) Parameter(dr.inference.model.Parameter) EmpiricalRateMatrixReader(dr.evomodel.substmodel.EmpiricalRateMatrixReader) Codons(dr.evolution.datatype.Codons) EmpiricalCodonModel(dr.evomodel.substmodel.codon.EmpiricalCodonModel)

Example 48 with FrequencyModel

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

the class HKYParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Parameter kappaParam = (Parameter) xo.getElementFirstChild(KAPPA);
    FrequencyModel freqModel = (FrequencyModel) xo.getElementFirstChild(FrequencyModelParser.FREQUENCIES);
    if (kappaParam.getId() == null && kappaParam.getParameterValue(0) == 1.0) {
        Logger.getLogger("dr.evomodel").info("\nCreating JC substitution model.");
    } else {
        Logger.getLogger("dr.evomodel").info("\nCreating HKY substitution model. Initial kappa = " + kappaParam.getParameterValue(0));
    }
    return new HKY(kappaParam, freqModel);
}
Also used : FrequencyModel(dr.evomodel.substmodel.FrequencyModel) HKY(dr.evomodel.substmodel.nucleotide.HKY) Parameter(dr.inference.model.Parameter)

Example 49 with FrequencyModel

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

the class LewisMkSubstitutionModelParser method parseXMLObject.

//public static XMLObjectParser PARSER=new LewisMkSubstitutionModelParser();
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    XMLObject cxo = xo.getChild(FREQUENCIES);
    FrequencyModel freqModel = (FrequencyModel) cxo.getChild(FrequencyModel.class);
    DataType dataType = freqModel.getDataType();
    int k = dataType.getStateCount();
    System.err.println("Number of states " + k);
    Parameter ratesParameter;
    if (xo.hasAttribute(TOTAL_ORDER) && xo.getBooleanAttribute(TOTAL_ORDER)) {
        //TOTAL ORDERING OF THE STATES BASED ON DATATYPE
        ratesParameter = new Parameter.Default(k * (k - 1) / 2, 0);
        int j = k - 1;
        for (int i = 0; i < (k - 1) * k / 2; i = i + j + 1) {
            ratesParameter.setParameterValue(i, 1);
            j -= 1;
        }
    } else if (xo.hasChildNamed(ORDER)) {
        // USER-SPECIFIED ORDERING OF THE STATES
        ratesParameter = new Parameter.Default(k * (k - 1) / 2, 0);
        for (int i = 0; i < xo.getChildCount(); ++i) {
            if (xo.getChildName(i).equals(ORDER)) {
                cxo = (XMLObject) xo.getChild(i);
                if (cxo.getName().equals(ORDER)) {
                    int from = dataType.getState(cxo.getStringAttribute(STATE).charAt(0));
                    int to = dataType.getState(cxo.getStringAttribute(ADJACENT).charAt(0));
                    if (from > to) {
                        //SWAP: from should have the smaller state number
                        to += from;
                        from = to - from;
                        to -= from;
                    }
                    int ratesIndex = (from * (2 * k - 3) - from * from) / 2 + to - 1;
                    ratesParameter.setParameterValue(ratesIndex, 1);
                }
            }
        }
    } else {
        ratesParameter = new Parameter.Default(k * (k - 1) / 2, 1);
    }
    System.err.println(ratesParameter.toString());
    System.err.println("Infinitesimal matrix:");
    for (int i = 0; i < k; ++i) {
        for (int j = 0; j < k; ++j) {
            int from, to;
            if (i < j) {
                from = i;
                to = j;
            } else {
                from = j;
                to = i;
            }
            //This is right now!!! Thanks, Marc!
            int ratesIndex = (from * (2 * k - 3) - from * from) / 2 + to - 1;
            if (i != j)
                System.err.print(Double.toString(ratesParameter.getValue(ratesIndex)) + "\t(" + ratesIndex + ")\t");
            else
                System.err.print("-\t\t");
        }
        //newline
        System.err.println("");
    }
    System.err.println("");
    if (!checkConnected(ratesParameter.getValues(), k)) {
        throw (new XMLParseException("The state transitions form a disconnected graph! This model is not suited for this case."));
    }
    return new GeneralSubstitutionModel(LEWIS_MK_MODEL, dataType, freqModel, ratesParameter, -1);
}
Also used : FrequencyModel(dr.evomodel.substmodel.FrequencyModel) DataType(dr.evolution.datatype.DataType) Parameter(dr.inference.model.Parameter) GeneralSubstitutionModel(dr.evomodel.substmodel.GeneralSubstitutionModel)

Example 50 with FrequencyModel

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

the class MarkovModulatedGY94CodonModelParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    DataType dataType = DataTypeUtils.getDataType(xo);
    HiddenCodons codons;
    if (dataType instanceof HiddenCodons)
        codons = (HiddenCodons) dataType;
    else
        throw new XMLParseException("Must construct " + MARKOV_MODULATED_YANG_MODEL + " with hidden codons");
    Parameter omegaParam = (Parameter) xo.getElementFirstChild(OMEGA);
    Parameter kappaParam = (Parameter) xo.getElementFirstChild(KAPPA);
    Parameter switchingParam = (Parameter) xo.getElementFirstChild(SWITCHING_RATES);
    FrequencyModel freqModel = (FrequencyModel) xo.getChild(FrequencyModel.class);
    EigenSystem eigenSystem;
    if (xo.getAttribute(DIAGONALIZATION, "default").compareToIgnoreCase("colt") == 0)
        eigenSystem = new ColtEigenSystem(dataType.getStateCount());
    else
        eigenSystem = new DefaultEigenSystem(dataType.getStateCount());
    return new MarkovModulatedGY94CodonModel(codons, switchingParam, omegaParam, kappaParam, freqModel, eigenSystem);
}
Also used : FrequencyModel(dr.evomodel.substmodel.FrequencyModel) DefaultEigenSystem(dr.evomodel.substmodel.DefaultEigenSystem) HiddenCodons(dr.evolution.datatype.HiddenCodons) DataType(dr.evolution.datatype.DataType) Parameter(dr.inference.model.Parameter) ColtEigenSystem(dr.evomodel.substmodel.ColtEigenSystem) ColtEigenSystem(dr.evomodel.substmodel.ColtEigenSystem) EigenSystem(dr.evomodel.substmodel.EigenSystem) DefaultEigenSystem(dr.evomodel.substmodel.DefaultEigenSystem) MarkovModulatedGY94CodonModel(dr.evomodel.substmodel.codon.MarkovModulatedGY94CodonModel)

Aggregations

FrequencyModel (dr.evomodel.substmodel.FrequencyModel)57 Parameter (dr.inference.model.Parameter)42 GammaSiteRateModel (dr.evomodel.siteratemodel.GammaSiteRateModel)23 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)22 HKY (dr.evomodel.substmodel.nucleotide.HKY)21 HomogeneousBranchModel (dr.evomodel.branchmodel.HomogeneousBranchModel)19 TreeModel (dr.evomodel.tree.TreeModel)19 DefaultBranchRateModel (dr.evomodel.branchratemodel.DefaultBranchRateModel)17 ArrayList (java.util.ArrayList)14 BranchModel (dr.evomodel.branchmodel.BranchModel)12 Partition (dr.app.beagle.tools.Partition)11 SubstitutionModel (dr.evomodel.substmodel.SubstitutionModel)11 BeagleSequenceSimulator (dr.app.beagle.tools.BeagleSequenceSimulator)10 DataType (dr.evolution.datatype.DataType)10 NewickImporter (dr.evolution.io.NewickImporter)9 Tree (dr.evolution.tree.Tree)9 Vector (dr.math.matrixAlgebra.Vector)9 PatternList (dr.evolution.alignment.PatternList)7 ImportException (dr.evolution.io.Importer.ImportException)7 BeagleTreeLikelihood (dr.evomodel.treelikelihood.BeagleTreeLikelihood)7