Search in sources :

Example 16 with PatternList

use of dr.evolution.alignment.PatternList in project beast-mcmc by beast-dev.

the class MultiPartitionDataLikelihoodDelegate method setPartials.

/**
     * Sets the partials from a sequence in an alignment.
     *
     * @param beagle        beagle
     * @param patternLists  patternLists
     * @param taxonId       taxonId
     * @param nodeIndex     nodeIndex
     */
private final void setPartials(Beagle beagle, List<PatternList> patternLists, String taxonId, int nodeIndex) throws TaxonList.MissingTaxonException {
    double[] partials = new double[totalPatternCount * stateCount * categoryCount];
    int v = 0;
    for (PatternList patternList : patternLists) {
        int sequenceIndex = patternList.getTaxonIndex(taxonId);
        if (sequenceIndex == -1) {
            throw new TaxonList.MissingTaxonException("Taxon, " + taxonId + ", not found in patternList, " + patternList.getId());
        }
        boolean[] stateSet;
        for (int i = 0; i < patternList.getPatternCount(); i++) {
            int state = patternList.getPatternState(sequenceIndex, i);
            stateSet = dataType.getStateSet(state);
            for (int j = 0; j < stateCount; j++) {
                if (stateSet[j]) {
                    partials[v] = 1.0;
                } else {
                    partials[v] = 0.0;
                }
                v++;
            }
        }
    }
    // if there is more than one category then replicate the partials for each
    int n = totalPatternCount * stateCount;
    int k = n;
    for (int i = 1; i < categoryCount; i++) {
        System.arraycopy(partials, 0, partials, k, n);
        k += n;
    }
    beagle.setPartials(nodeIndex, partials);
}
Also used : PatternList(dr.evolution.alignment.PatternList)

Example 17 with PatternList

use of dr.evolution.alignment.PatternList in project beast-mcmc by beast-dev.

the class ImportanceNarrowExchangeParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    final TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
    final PatternList patterns = (PatternList) xo.getChild(PatternList.class);
    final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    final double epsilon = xo.getAttribute(EPSILON, 0.1);
    try {
        return new ImportanceNarrowExchange(treeModel, patterns, epsilon, weight);
    } catch (Exception e) {
        throw new XMLParseException(e.getMessage());
    }
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) PatternList(dr.evolution.alignment.PatternList) ImportanceNarrowExchange(dr.evomodel.operators.ImportanceNarrowExchange)

Example 18 with PatternList

use of dr.evolution.alignment.PatternList in project beast-mcmc by beast-dev.

the class ALSTreeLikelihoodParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    boolean useAmbiguities = false;
    boolean storePartials = true;
    if (xo.hasAttribute(TreeLikelihoodParser.USE_AMBIGUITIES)) {
        useAmbiguities = xo.getBooleanAttribute(TreeLikelihoodParser.USE_AMBIGUITIES);
    }
    if (xo.hasAttribute(TreeLikelihoodParser.STORE_PARTIALS)) {
        storePartials = xo.getBooleanAttribute(TreeLikelihoodParser.STORE_PARTIALS);
    }
    boolean integrateGainRate = xo.getBooleanAttribute(INTEGRATE_GAIN_RATE);
    //AbstractObservationProcess observationProcess = (AbstractObservationProcess) xo.getChild(AbstractObservationProcess.class);
    PatternList patternList = (PatternList) xo.getChild(PatternList.class);
    TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
    SiteModel siteModel = (SiteModel) xo.getChild(SiteModel.class);
    BranchRateModel branchRateModel = (BranchRateModel) xo.getChild(BranchRateModel.class);
    Parameter mu = ((MutationDeathModel) siteModel.getSubstitutionModel()).getDeathParameter();
    Parameter lam;
    if (!integrateGainRate) {
        lam = (Parameter) xo.getElementFirstChild(IMMIGRATION_RATE);
    } else {
        lam = new Parameter.Default("gainRate", 1.0, 0.001, 1.999);
    }
    AbstractObservationProcess observationProcess = null;
    Logger.getLogger("dr.evolution").info("\n ---------------------------------\nCreating ALSTreeLikelihood model.");
    for (int i = 0; i < xo.getChildCount(); ++i) {
        Object cxo = xo.getChild(i);
        if (cxo instanceof XMLObject && ((XMLObject) cxo).getName().equals(OBSERVATION_PROCESS)) {
            if (((XMLObject) cxo).getStringAttribute(OBSERVATION_TYPE).equals("singleTip")) {
                String taxonName = ((XMLObject) cxo).getStringAttribute(OBSERVATION_TAXON);
                Taxon taxon = treeModel.getTaxon(treeModel.getTaxonIndex(taxonName));
                observationProcess = new SingleTipObservationProcess(treeModel, patternList, siteModel, branchRateModel, mu, lam, taxon);
                Logger.getLogger("dr.evolution").info("All traits are assumed extant in " + taxonName);
            } else {
                // "anyTip" observation process
                observationProcess = new AnyTipObservationProcess(ANY_TIP, treeModel, patternList, siteModel, branchRateModel, mu, lam);
                Logger.getLogger("dr.evolution").info("Observed traits are assumed to be extant in at least one tip node.");
            }
            observationProcess.setIntegrateGainRate(integrateGainRate);
        }
    }
    Logger.getLogger("dr.evolution").info("\tIf you publish results using Acquisition-Loss-Mutation (ALS) Model likelihood, please reference Alekseyenko, Lee and Suchard (2008) Syst. Biol 57: 772-784.\n---------------------------------\n");
    boolean forceRescaling = xo.getAttribute(FORCE_RESCALING, false);
    return new ALSTreeLikelihood(observationProcess, patternList, treeModel, siteModel, branchRateModel, useAmbiguities, storePartials, forceRescaling);
}
Also used : Taxon(dr.evolution.util.Taxon) AnyTipObservationProcess(dr.oldevomodel.MSSD.AnyTipObservationProcess) PatternList(dr.evolution.alignment.PatternList) MutationDeathModel(dr.oldevomodel.substmodel.MutationDeathModel) SiteModel(dr.oldevomodel.sitemodel.SiteModel) ALSTreeLikelihood(dr.oldevomodel.MSSD.ALSTreeLikelihood) TreeModel(dr.evomodel.tree.TreeModel) SingleTipObservationProcess(dr.oldevomodel.MSSD.SingleTipObservationProcess) BranchRateModel(dr.evomodel.branchratemodel.BranchRateModel) AbstractObservationProcess(dr.oldevomodel.MSSD.AbstractObservationProcess) Parameter(dr.inference.model.Parameter)

Example 19 with PatternList

use of dr.evolution.alignment.PatternList in project beast-mcmc by beast-dev.

the class ALSTreeLikelihoodParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    boolean useAmbiguities = false;
    boolean storePartials = true;
    if (xo.hasAttribute(TreeLikelihoodParser.USE_AMBIGUITIES)) {
        useAmbiguities = xo.getBooleanAttribute(TreeLikelihoodParser.USE_AMBIGUITIES);
    }
    if (xo.hasAttribute(TreeLikelihoodParser.STORE_PARTIALS)) {
        storePartials = xo.getBooleanAttribute(TreeLikelihoodParser.STORE_PARTIALS);
    }
    boolean integrateGainRate = xo.getBooleanAttribute(INTEGRATE_GAIN_RATE);
    //AbstractObservationProcess observationProcess = (AbstractObservationProcess) xo.getChild(AbstractObservationProcess.class);
    PatternList patternList = (PatternList) xo.getChild(PatternList.class);
    TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
    SiteModel siteModel = (SiteModel) xo.getChild(SiteModel.class);
    BranchRateModel branchRateModel = (BranchRateModel) xo.getChild(BranchRateModel.class);
    Parameter mu = ((MutationDeathModel) siteModel.getSubstitutionModel()).getDeathParameter();
    Parameter lam;
    if (!integrateGainRate) {
        lam = (Parameter) xo.getElementFirstChild(IMMIGRATION_RATE);
    } else {
        lam = new Parameter.Default("gainRate", 1.0, 0.001, 1.999);
    }
    AbstractObservationProcess observationProcess = null;
    Logger.getLogger("dr.evolution").info("\n ---------------------------------\nCreating ALSTreeLikelihood model.");
    for (int i = 0; i < xo.getChildCount(); ++i) {
        Object cxo = xo.getChild(i);
        if (cxo instanceof XMLObject && ((XMLObject) cxo).getName().equals(OBSERVATION_PROCESS)) {
            if (((XMLObject) cxo).getStringAttribute(OBSERVATION_TYPE).equals("singleTip")) {
                String taxonName = ((XMLObject) cxo).getStringAttribute(OBSERVATION_TAXON);
                Taxon taxon = treeModel.getTaxon(treeModel.getTaxonIndex(taxonName));
                observationProcess = new SingleTipObservationProcess(treeModel, patternList, siteModel, branchRateModel, mu, lam, taxon);
                Logger.getLogger("dr.evolution").info("All traits are assumed extant in " + taxonName);
            } else {
                // "anyTip" observation process
                observationProcess = new AnyTipObservationProcess(ANY_TIP, treeModel, patternList, siteModel, branchRateModel, mu, lam);
                Logger.getLogger("dr.evolution").info("Observed traits are assumed to be extant in at least one tip node.");
            }
            observationProcess.setIntegrateGainRate(integrateGainRate);
        }
    }
    Logger.getLogger("dr.evolution").info("\tIf you publish results using Acquisition-Loss-Mutation (ALS) Model likelihood, please reference Alekseyenko, Lee and Suchard (2008) Syst. Biol 57: 772-784.\n---------------------------------\n");
    boolean forceRescaling = xo.getAttribute(FORCE_RESCALING, false);
    return new ALSTreeLikelihood(observationProcess, patternList, treeModel, siteModel, branchRateModel, useAmbiguities, storePartials, forceRescaling);
}
Also used : Taxon(dr.evolution.util.Taxon) AnyTipObservationProcess(dr.oldevomodel.MSSD.AnyTipObservationProcess) PatternList(dr.evolution.alignment.PatternList) MutationDeathModel(dr.oldevomodel.substmodel.MutationDeathModel) SiteModel(dr.oldevomodel.sitemodel.SiteModel) ALSTreeLikelihood(dr.oldevomodel.MSSD.ALSTreeLikelihood) TreeModel(dr.evomodel.tree.TreeModel) SingleTipObservationProcess(dr.oldevomodel.MSSD.SingleTipObservationProcess) BranchRateModel(dr.evomodel.branchratemodel.BranchRateModel) AbstractObservationProcess(dr.oldevomodel.MSSD.AbstractObservationProcess) Parameter(dr.inference.model.Parameter)

Example 20 with PatternList

use of dr.evolution.alignment.PatternList in project beast-mcmc by beast-dev.

the class AnyTipObservationProcessParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Parameter mu = (Parameter) xo.getElementFirstChild(DEATH_RATE);
    Parameter lam = (Parameter) xo.getElementFirstChild(IMMIGRATION_RATE);
    TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
    PatternList patterns = (PatternList) xo.getChild(PatternList.class);
    SiteModel siteModel = (SiteModel) xo.getChild(SiteModel.class);
    BranchRateModel branchRateModel = (BranchRateModel) xo.getChild(BranchRateModel.class);
    Logger.getLogger("dr.evomodel.MSSD").info("Creating AnyTipObservationProcess model. Observed traits are assumed to be extant in at least one tip node. Initial mu = " + mu.getParameterValue(0) + " initial lam = " + lam.getParameterValue(0));
    return new AnyTipObservationProcess(MODEL_NAME, treeModel, patterns, siteModel, branchRateModel, mu, lam);
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) BranchRateModel(dr.evomodel.branchratemodel.BranchRateModel) AnyTipObservationProcess(dr.oldevomodel.MSSD.AnyTipObservationProcess) PatternList(dr.evolution.alignment.PatternList) Parameter(dr.inference.model.Parameter) SiteModel(dr.oldevomodel.sitemodel.SiteModel)

Aggregations

PatternList (dr.evolution.alignment.PatternList)22 TreeModel (dr.evomodel.tree.TreeModel)14 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)12 Parameter (dr.inference.model.Parameter)11 GammaSiteRateModel (dr.evomodel.siteratemodel.GammaSiteRateModel)7 FrequencyModel (dr.evomodel.substmodel.FrequencyModel)7 BranchModel (dr.evomodel.branchmodel.BranchModel)6 HomogeneousBranchModel (dr.evomodel.branchmodel.HomogeneousBranchModel)6 ArrayList (java.util.ArrayList)6 TipStatesModel (dr.evomodel.tipstatesmodel.TipStatesModel)5 Patterns (dr.evolution.alignment.Patterns)4 SitePatterns (dr.evolution.alignment.SitePatterns)4 Taxon (dr.evolution.util.Taxon)4 DefaultBranchRateModel (dr.evomodel.branchratemodel.DefaultBranchRateModel)4 SiteRateModel (dr.evomodel.siteratemodel.SiteRateModel)4 SubstitutionModel (dr.evomodel.substmodel.SubstitutionModel)4 BeagleTreeLikelihood (dr.evomodel.treelikelihood.BeagleTreeLikelihood)4 PartialsRescalingScheme (dr.evomodel.treelikelihood.PartialsRescalingScheme)4 SiteModel (dr.oldevomodel.sitemodel.SiteModel)4 DataType (dr.evolution.datatype.DataType)3