All Downloads are FREE. Search and download functionalities are using the official Maven repository.

lphy.base.bmodeltest.bSiteModelFunction Maven / Gradle / Ivy

Go to download

The standard library of LPhy, which contains the required generative distributions and basic functions.

The newest version!
package lphy.base.bmodeltest;

import lphy.base.evolution.sitemodel.SiteModel;
import lphy.core.model.DeterministicFunction;
import lphy.core.model.Value;
import lphy.core.model.annotation.Citation;
import lphy.core.model.annotation.GeneratorCategory;
import lphy.core.model.annotation.GeneratorInfo;
import lphy.core.model.annotation.ParameterInfo;

import java.util.Map;

import static lphy.base.evolution.likelihood.PhyloCTMC.QParamName;
import static lphy.base.evolution.likelihood.PhyloCTMC.siteRatesParamName;
import static lphy.core.model.ValueUtils.doubleValue;

@Citation(
        value = "Bouckaert, R., Drummond, A. bModelTest: Bayesian phylogenetic site model averaging and model comparison. BMC Evol Biol 17, 42 (2017). https://doi.org/10.1186/s12862-017-0890-6",
        title = "bModelTest: Bayesian phylogenetic site model averaging and model comparison",
        authors = {"Bouckaert", "Drummond"},
        year = 2017,
        DOI = "https://doi.org/10.1186/s12862-017-0890-6"
)
public class bSiteModelFunction extends DeterministicFunction {

    public static final String useSiteRatesParamName = "useSiteRates";
    public static final String useProportionInvariableParamName = "usePInv";
    public static final String proportionInvariableParamName = "pInv";

    public bSiteModelFunction(
            @ParameterInfo(name = QParamName, narrativeName = "instantaneous rate matrix", description = "the instantaneous rate matrix.") Value Q,
            @ParameterInfo(name = siteRatesParamName, narrativeName = "site rates", description = "raw site rates.") Value siteRates,
            @ParameterInfo(name = proportionInvariableParamName, narrativeName = "proportion of invariable sites", description = "the proportion of invariable sites parameter") Value proportionInvariable,
            @ParameterInfo(name = useSiteRatesParamName, narrativeName = "site rate heterogeneity indicator", description = "true if the site rates have heterogeneity.") Value useSiteRates,
            @ParameterInfo(name = useProportionInvariableParamName, narrativeName = "proportion invariable indicator", description = "true if the proportion invariable used.") Value useProportionInvariable) {

        setParam(QParamName, Q);
        setParam(siteRatesParamName, siteRates);
        setParam(proportionInvariableParamName, proportionInvariable);
        setParam(useSiteRatesParamName, useSiteRates);
        setParam(useProportionInvariableParamName, useProportionInvariable);

    }

    @GeneratorInfo(name = "bSiteModel", narrativeName = "bModelTest site model", verbClause = "is",
            category = GeneratorCategory.SITE_MODEL, examples = {"simpleBModelTest.lphy"},
            description = "Returns the site model for the given parameters.")
    public Value apply() {

        Map params = getParams();
        Value Q = (Value)params.get(QParamName);

        Value siteRatesParam = (Value)params.get(siteRatesParamName);

        Value proportionInvariableParam = (Value)params.get(proportionInvariableParamName);

        Value useSiteRates = (Value)params.get(useSiteRatesParamName);


        Value useProportionInvariable = (Value)params.get(useProportionInvariableParamName);



        Double[] siteRates = null;
        Double proportionInvariable = 0.0;

        if (useSiteRates.value()) {
            siteRates = siteRatesParam.value();
        }

        if (useProportionInvariable.value()) {
            proportionInvariable = doubleValue(proportionInvariableParam);
        }

        SiteModel siteModel = new SiteModel(Q.value(), siteRates, proportionInvariable);

        return new Value<>(null, siteModel, this);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy