Skip to content

Model

piqtree.Model(submod_type, freq_type=None, rate_model=None, *, invariable_sites=False)

Specification for substitution models.

Stores the substitution model with base frequency settings.

PARAMETER DESCRIPTION
submod_type

The substitution model to use.

TYPE: str | SubstitutionModel

freq_type

State frequency specification, by default None (defaults to empirical base frequencies if not specified by model).

TYPE: str | FreqType | CustomBaseFreq | None DEFAULT: None

rate_model

Rate heterogeneity across sites model, by default None (no Gamma and no FreeRate).

TYPE: str | RateModel | None DEFAULT: None

invariable_sites

Invariable sites, by default False. If a float in the range [0,1), specifies the proportion of invariable sites.

TYPE: bool | float DEFAULT: False

Source code in src/piqtree/model/_model.py
def __init__(
    self,
    submod_type: str | SubstitutionModel,
    freq_type: str | FreqType | CustomBaseFreq | None = None,
    rate_model: str | RateModel | None = None,
    *,
    invariable_sites: bool | float = False,
) -> None:
    """Construct Model class.

    Parameters
    ----------
    submod_type : str | SubstitutionModel
        The substitution model to use.
    freq_type : str | FreqType | CustomBaseFreq | None, optional
        State frequency specification, by default None (defaults
        to empirical base frequencies if not specified by model).
    rate_model : str | RateModel | None, optional
        Rate heterogeneity across sites model, by default None
        (no Gamma and no FreeRate).
    invariable_sites : bool | float, optional
        Invariable sites, by default False.
        If a float in the range [0,1), specifies the proportion of invariable sites.

    """
    self.submod_type = get_substitution_model(submod_type)
    self.freq_type = get_freq_type(freq_type) if freq_type else None
    self.rate_type = (
        get_rate_type(rate_model, invariable_sites=invariable_sites)
        if rate_model is not None or invariable_sites
        else None
    )

invariable_sites property

Whether invariable sites are used.

RETURNS DESCRIPTION
bool

True if invariable sites are used by the model, False otherwise.

proportion_invariable_sites property

The proportion of invariable sites if specified.

RETURNS DESCRIPTION
float | None

The proportion of invariable sites if specified, None otherwise.

rate_model property

The RateModel used, if one is chosen.

RETURNS DESCRIPTION
RateModel | None

The RateModel used by the Model.

__str__()

Convert the model into the IQ-TREE representation.

RETURNS DESCRIPTION
str

The IQ-TREE representation of the model.

Source code in src/piqtree/model/_model.py
def __str__(self) -> str:
    """Convert the model into the IQ-TREE representation.

    Returns
    -------
    str
        The IQ-TREE representation of the model.

    """
    iqtree_extra_args = (
        x for x in (self.freq_type, self.rate_type) if x is not None
    )
    return "+".join(x.iqtree_str() for x in [self.submod_type, *iqtree_extra_args])

Usage

For usage, see "Use different kinds of substitution models".