Search in sources :

Example 16 with Parameter

use of dr.inference.model.Parameter in project beast-mcmc by beast-dev.

the class SelectorOperatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    final Parameter parameter = (Parameter) xo.getChild(Parameter.class);
    final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    final SelectorOperator op = new SelectorOperator(parameter);
    op.setWeight(weight);
    return op;
}
Also used : Parameter(dr.inference.model.Parameter) SelectorOperator(dr.inference.operators.SelectorOperator)

Example 17 with Parameter

use of dr.inference.model.Parameter in project beast-mcmc by beast-dev.

the class SetOperatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    double[] values = xo.getDoubleArrayAttribute(SET);
    double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    Parameter parameter = (Parameter) xo.getChild(Parameter.class);
    System.out.println("Creating set operator for parameter " + parameter.getParameterName());
    System.out.print("  set = {" + values[0]);
    for (int i = 1; i < values.length; i++) {
        System.out.print(", " + values[i]);
    }
    System.out.println("}");
    SetOperator operator = new SetOperator(parameter, values);
    operator.setWeight(weight);
    return operator;
}
Also used : SetOperator(dr.inference.operators.SetOperator) Parameter(dr.inference.model.Parameter)

Example 18 with Parameter

use of dr.inference.model.Parameter in project beast-mcmc by beast-dev.

the class CompleteHistorySimulatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    int nReplications = xo.getIntegerAttribute(REPLICATIONS);
    Tree tree = (Tree) xo.getChild(Tree.class);
    GammaSiteRateModel siteModel = (GammaSiteRateModel) xo.getChild(GammaSiteRateModel.class);
    BranchRateModel rateModel = (BranchRateModel) xo.getChild(BranchRateModel.class);
    if (rateModel == null)
        rateModel = new DefaultBranchRateModel();
    DataType dataType = siteModel.getSubstitutionModel().getDataType();
    String jumpTag = xo.getAttribute(JUMP_TAG_NAME, JUMP_TAG);
    boolean sumAcrossSites = xo.getAttribute(SUM_SITES, false);
    Parameter branchSpecificParameter = null;
    Parameter variableValueParameter = null;
    if (xo.hasChildNamed(BRANCH_SPECIFIC_SPECIFICATION)) {
        XMLObject cxo = xo.getChild(BRANCH_SPECIFIC_SPECIFICATION);
        branchSpecificParameter = (Parameter) cxo.getChild(BRANCH_VARIABLE_PARAMETER).getChild(Parameter.class);
        variableValueParameter = (Parameter) cxo.getChild(VARIABLE_VALUE_PARAMETER).getChild(Parameter.class);
    }
    CompleteHistorySimulator history = new CompleteHistorySimulator(tree, siteModel, rateModel, nReplications, sumAcrossSites, branchSpecificParameter, variableValueParameter);
    XMLObject cxo = xo.getChild(COUNTS);
    if (cxo != null) {
        MarkovJumpsTreeLikelihoodParser.parseAllChildren(cxo, history, dataType.getStateCount(), jumpTag, MarkovJumpsType.COUNTS, false);
    }
    cxo = xo.getChild(REWARDS);
    if (cxo != null) {
        MarkovJumpsTreeLikelihoodParser.parseAllChildren(cxo, history, dataType.getStateCount(), jumpTag, MarkovJumpsType.REWARDS, false);
    }
    if (dataType instanceof Codons) {
        Codons codons = (Codons) dataType;
        if (xo.getAttribute(SYN_JUMPS, false)) {
            // use base 61
            double[] synRegMatrix = CodonLabeling.getRegisterMatrix(CodonLabeling.SYN, codons, false);
            Parameter registerParameter = new Parameter.Default(synRegMatrix);
            registerParameter.setId("S");
            history.addRegister(registerParameter, MarkovJumpsType.COUNTS, false);
        }
        if (xo.getAttribute(NON_SYN_JUMPS, false)) {
            // use base 61
            double[] nonSynRegMatrix = CodonLabeling.getRegisterMatrix(CodonLabeling.NON_SYN, codons, false);
            Parameter registerParameter = new Parameter.Default(nonSynRegMatrix);
            registerParameter.setId("N");
            history.addRegister(registerParameter, MarkovJumpsType.COUNTS, false);
        }
    }
    if (xo.getAttribute(ANNOTATE_WITH_ALIGNMENT, false)) {
        history.addAlignmentTrait();
    }
    boolean alignmentOnly = xo.getAttribute(ALIGNMENT_ONLY, false);
    if (dataType instanceof Codons && !alignmentOnly) {
        System.out.println("Codon models give exception when count statistics are done on them. " + "You can supress this by setting alignmentOnly to true.");
    }
    if (alignmentOnly) {
        history.setAlignmentOnly();
    }
    history.simulate();
    return history;
}
Also used : GammaSiteRateModel(dr.evomodel.siteratemodel.GammaSiteRateModel) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel) BranchRateModel(dr.evomodel.branchratemodel.BranchRateModel) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel) Tree(dr.evolution.tree.Tree) DataType(dr.evolution.datatype.DataType) Parameter(dr.inference.model.Parameter) Codons(dr.evolution.datatype.Codons) CompleteHistorySimulator(dr.app.beagle.tools.CompleteHistorySimulator)

Example 19 with Parameter

use of dr.inference.model.Parameter in project beast-mcmc by beast-dev.

the class AncestralSequenceAnnotator method loadSiteModel.

/*
     * This method is equivalent to the SubstitutionModelLoader without having to
     * be object orientated and can be much more flexible.
     */
private GammaSiteRateModel loadSiteModel(Tree tree) {
    String modelType = (String) tree.getAttribute(SUBST_MODEL);
    /* Identify the datatype and substitution model. Load the model */
    SubstitutionModelLoader sml = null;
    String substModelName = modelType.replaceFirst("\\*.+", "").replaceFirst("\\+.+", "").trim();
    System.out.println("Basic Substitution Model is " + substModelName);
    for (int i = 0; i < GENERAL_MODELS_LIST.length; i++) {
        if (substModelName.matches(GENERAL_MODELS_LIST[i])) {
            sml = new GeneralSubstitutionModelLoader(tree, modelType);
        }
    }
    for (int i = 0; i < NUCLEOTIDE_MODELS_LIST.length; i++) {
        if (substModelName.matches(NUCLEOTIDE_MODELS_LIST[i])) {
            sml = new NucleotideSubstitutionModelLoader(tree, modelType);
        }
    }
    for (int i = 0; i < AMINO_ACID_MODELS_LIST.length; i++) {
        if (substModelName.matches(AMINO_ACID_MODELS_LIST[i])) {
            sml = new AminoAcidSubstitutionModelLoader(tree, modelType);
        }
    }
    for (int i = 0; i < TRIPLET_MODELS_LIST.length; i++) {
        if (substModelName.matches(TRIPLET_MODELS_LIST[i])) {
            sml = new TripletSubstitutionModelLoader(tree, modelType);
        }
    }
    for (int i = 0; i < CODON_MODELS_LIST.length; i++) {
        if (substModelName.matches(CODON_MODELS_LIST[i])) {
            sml = new CodonSubstitutionModelLoader(tree, modelType);
        }
    }
    if (sml.getSubstitutionModel() == null) {
        System.err.println("Substitution model type '" + modelType + "' not implemented");
        System.exit(-1);
    }
    //SiteModel siteModel = new GammaSiteModel(sml.getSubstitutionModel(), new Parameter.Default(1.0), null, 0, null);
    //SiteModel siteModel = new GammaSiteModel(sml.getSubstitutionModel(), null, null, 0, null);
    String siteRatesModels = modelType.substring(modelType.indexOf("+") + 1, modelType.length());
    //String[] siteRatesModels = siteRatesParameters.split(" + ");
    System.out.println("Site rate models: " + siteRatesModels);
    if (sml.getSubstitutionModel().getDataType().getClass().equals(Codons.class) && siteRatesModels.length() > 0) {
        if (siteRatesModels.indexOf("+M2") >= 0) {
            /* M2 */
            System.out.println("Site model - M2 Codon site model used");
            Parameter m2FrequencyAAInv = new Parameter.Default(Double.parseDouble(tree.getAttribute("M2_f[AA INV]").toString()));
            Parameter m2FrequencyNeutral = new Parameter.Default(Double.parseDouble(tree.getAttribute("M2_f[Neutral]").toString()));
            Parameter m2FrequencySelected = new Parameter.Default(Double.parseDouble(tree.getAttribute("M2_f[Selected]").toString()));
            Parameter m2Omega = new Parameter.Default(Double.parseDouble(tree.getAttribute("M2_omega").toString()));
            //Parameter m2FrequencyAAInv = new Parameter.Default((Double) tree.getAttribute("M2_f[AA INV]"));
            //Parameter m2FrequencyNeutral = new Parameter.Default((Double) tree.getAttribute("M2_f[Neutral]"));
            //Parameter m2FrequencySelected = new Parameter.Default((Double) tree.getAttribute("M2_f[Selected]"));
            //Parameter m2Omega = new Parameter.Default((Double) tree.getAttribute("M2_omega"));
            System.err.println("Sorry, M2 substitution model is not yet implemented in BEAST");
            System.exit(0);
        } else if (siteRatesModels.indexOf("+M3") >= 0) {
            /* M3 */
            System.out.println("Site model - M3 Codon site model used");
            int numberOfBins = Integer.parseInt(siteRatesModels.replaceFirst(".+M3\\[", "").replaceFirst("\\].+", ""));
            System.out.println(" + M3 n value: " + numberOfBins);
            Parameter[] m3Frequencies = new Parameter[numberOfBins];
            Parameter[] m3Omegas = new Parameter[numberOfBins];
            for (int i = 1; i <= numberOfBins; i++) {
                m3Frequencies[i - 1] = new Parameter.Default(Double.parseDouble(tree.getAttribute("M3_f" + i).toString()));
                m3Omegas[i - 1] = new Parameter.Default(Double.parseDouble(tree.getAttribute("M3_omega" + i).toString()));
            //m3Frequencies[i-1] = new Parameter.Default((Double) tree.getAttribute("M3_f"+i));
            //m3Omegas[i-1] = new Parameter.Default((Double) tree.getAttribute("M3_omega"+i));
            }
            System.err.println("Sorry, M3 substitution model is not yet implemented in BEAST");
            System.exit(0);
        } else if (siteRatesModels.indexOf("+M0_omega~Beta(") >= 0) {
            /* M7 */
            System.out.println("Site model - M7 Codon site model used");
            int numberOfBins = Integer.parseInt(siteRatesModels.replaceFirst("M0_omega~Beta\\(", "").replaceFirst("\\)", ""));
            System.out.println(" + M7 n value: " + numberOfBins);
            Parameter m7BetaMu = new Parameter.Default(Double.parseDouble(tree.getAttribute("beta_mu").toString()));
            Parameter m7BetaVarMu = new Parameter.Default(Double.parseDouble(tree.getAttribute("beta_Var/mu").toString()));
            //Parameter m7BetaMu = new Parameter.Default((Double) tree.getAttribute("beta_mu"));
            //Parameter m7BetaVarMu = new Parameter.Default((Double) tree.getAttribute("beta_Var/mu"));
            System.err.println("Sorry, M7 substitution model is not yet implemented in BEAST");
            System.exit(0);
        }
    } else if (siteRatesModels.length() > 0) {
        /* i.e. for other data types. */
        /* Do gamma/lognormal + pinv */
        Parameter pInvParameter = null;
        int categories = -1;
        Parameter alphaParameter = null;
        if (siteRatesModels.indexOf("+INV") >= 0) {
            System.out.println("Site model -  proportion of invariable sites used");
            //pInvParameter = new Parameter.Default(((Double) tree.getAttribute("INV_p")).doubleValue());
            pInvParameter = new Parameter.Default(Double.parseDouble(tree.getAttribute("INV_p").toString()));
        }
        if (siteRatesModels.indexOf("+rate~Gamma(") >= 0) {
            System.out.println("Site model - gamma site rate heterogeneity used");
            categories = Integer.parseInt(siteRatesModels.replaceFirst(".+rate~Gamma\\(", "").replaceFirst("\\).*", ""));
            //double sigmaMu = (Double) tree.getAttribute("gamma_sigma/mu");
            double sigmaMu = Double.parseDouble(tree.getAttribute("gamma_sigma/mu").toString());
            sigmaMu = (1.0 / sigmaMu) * (1.0 / sigmaMu);
            /* BAli-Phy is parameterised by sigma/mu instead of alpha */
            alphaParameter = new Parameter.Default(sigmaMu);
        } else if (siteRatesModels.indexOf("+rate~LogNormal(") >= 0) {
            // TODO implement lognormal site model
            System.out.println("Site model - lognormal site rate heterogeneity used");
            System.err.println("Sorry, lognormal site rates are not yet implemented in BEAST");
            System.exit(0);
            categories = Integer.parseInt(siteRatesModels.replaceFirst(".+rate~LogNormal\\(", "").replaceFirst("\\).*", ""));
            //double sigmaMu = (Double) tree.getAttribute("log-normal_sigma/mu");
            double sigmaMu = Double.parseDouble(tree.getAttribute("log-normal_sigma/mu").toString());
            sigmaMu = (1.0 / sigmaMu) * (1.0 / sigmaMu);
            /* BAli-Phy is parameterised by sigma/mu instead of alpha */
            alphaParameter = new Parameter.Default(sigmaMu);
        } else if (siteRatesModels.indexOf("+GAMMA(") >= 0) {
            /* For BEAST output */
            System.out.println("Site model - gamma site rate heterogeneity used");
            categories = Integer.parseInt(siteRatesModels.replaceFirst(".+GAMMA\\(", "").replaceFirst("\\).*", ""));
            //double sigmaMu = (Double) tree.getAttribute("gamma_sigma/mu");
            double alpha = Double.parseDouble(tree.getAttribute("alpha").toString());
            alphaParameter = new Parameter.Default(alpha);
        }
        //System.out.println("alpha and pinv parameters: " + alphaParameter.getParameterValue(0) + "\t" + pInvParameter.getParameterValue(0));
        //GammaSiteRateModel siteModel = new GammaSiteRateModel(sml.getSubstitutionModel(), new Parameter.Default(1.0), alphaParameter, categories, pInvParameter);
        GammaSiteRateModel siteModel = new GammaSiteRateModel(GammaSiteModelParser.SITE_MODEL, new Parameter.Default(1.0), alphaParameter, categories, pInvParameter);
        siteModel.setSubstitutionModel(sml.getSubstitutionModel());
        //SiteModel siteModel = new GammaSiteModel(sml.getSubstitutionModel(), null, null, 0, null);
        return siteModel;
    }
    /* Default with no gamma or pinv */
    //SiteRateModel siteModel = new GammaSiteRateModel(sml.getSubstitutionModel());
    GammaSiteRateModel siteModel = new GammaSiteRateModel(GammaSiteModelParser.SITE_MODEL);
    siteModel.setSubstitutionModel(sml.getSubstitutionModel());
    return siteModel;
}
Also used : GammaSiteRateModel(dr.evomodel.siteratemodel.GammaSiteRateModel) Parameter(dr.inference.model.Parameter)

Example 20 with Parameter

use of dr.inference.model.Parameter in project beast-mcmc by beast-dev.

the class RecomboGen method main.

public static void main(String[] argv) {
    // Simulate sequences on this tree to generate sequences at the top of the
    // recombination process.
    Parameter kappa = new Parameter.Default(1, 2);
    Parameter freqs = new Parameter.Default(new double[] { 0.25, 0.25, 0.25, 0.25 });
    FrequencyModel freqModel = new FrequencyModel(Nucleotides.INSTANCE, freqs);
    HKY hky = new HKY(kappa, freqModel);
    // create site model
    SiteModel siteModel = new GammaSiteModel(hky);
    // create branch rate model
    Parameter rate = new Parameter.Default(1, 1.0E-4);
    BranchRateModel branchRateModel = new StrictClockBranchRates(rate);
//        RecomboGen recomboGen = new RecomboGen(8.0E-2, 100, 1000, 1.0E-4,
//                new String[] { "taxon1_0", "taxon2_0", "taxon3_10", "taxon4_10", "taxon5_20", "taxon6_20"},
//                new double[] { 0, 0, 10, 10, 20, 20} );
//
//        recomboGen.generate();
}
Also used : FrequencyModel(dr.oldevomodel.substmodel.FrequencyModel) GammaSiteModel(dr.oldevomodel.sitemodel.GammaSiteModel) HKY(dr.oldevomodel.substmodel.HKY) Parameter(dr.inference.model.Parameter) GammaSiteModel(dr.oldevomodel.sitemodel.GammaSiteModel) SiteModel(dr.oldevomodel.sitemodel.SiteModel)

Aggregations

Parameter (dr.inference.model.Parameter)397 TreeModel (dr.evomodel.tree.TreeModel)62 MatrixParameter (dr.inference.model.MatrixParameter)46 ArrayList (java.util.ArrayList)44 FrequencyModel (dr.oldevomodel.substmodel.FrequencyModel)43 FrequencyModel (dr.evomodel.substmodel.FrequencyModel)41 Units (dr.evolution.util.Units)36 XMLUnits (dr.evoxml.util.XMLUnits)36 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)30 Tree (dr.evolution.tree.Tree)25 DataType (dr.evolution.datatype.DataType)24 GammaSiteRateModel (dr.evomodel.siteratemodel.GammaSiteRateModel)23 CompoundParameter (dr.inference.model.CompoundParameter)23 GammaSiteModel (dr.oldevomodel.sitemodel.GammaSiteModel)21 SitePatterns (dr.evolution.alignment.SitePatterns)20 HKY (dr.evomodel.substmodel.nucleotide.HKY)17 Likelihood (dr.inference.model.Likelihood)17 HomogeneousBranchModel (dr.evomodel.branchmodel.HomogeneousBranchModel)16 DefaultBranchRateModel (dr.evomodel.branchratemodel.DefaultBranchRateModel)16 ParametricDistributionModel (dr.inference.distribution.ParametricDistributionModel)16