Skip to content

model_finder

piqtree.model_finder(aln, model_set=None, freq_set=None, rate_set=None, rand_seed=None, num_threads=None, other_options='')

Find the models of best fit for an alignment using ModelFinder.

PARAMETER DESCRIPTION
aln

The alignment to find the model of best fit for.

TYPE: Alignment

model_set

Search space for models. Equivalent to IQ-TREE's mset parameter, by default None

TYPE: Iterable[str] | None DEFAULT: None

freq_set

Search space for frequency types. Equivalent to IQ-TREE's mfreq parameter, by default None

TYPE: Iterable[str] | None DEFAULT: None

rate_set

Search space for rate heterogeneity types. Equivalent to IQ-TREE's mrate parameter, by default None

TYPE: Iterable[str] | None DEFAULT: None

rand_seed

The random seed - None means no seed is used, by default None.

TYPE: int | None DEFAULT: None

num_threads

Number of threads for IQ-TREE to use, by default None (single-threaded). If 0 is specified, IQ-TREE attempts to find the optimal number of threads.

TYPE: int | None DEFAULT: None

other_options

Additional command line options for IQ-TREE.

TYPE: str DEFAULT: ''

RETURNS DESCRIPTION
ModelFinderResult

Collection of data returned from IQ-TREE's ModelFinder.

Source code in src/piqtree/iqtree/_model_finder.py
def model_finder(
    aln: Alignment,
    model_set: Iterable[str] | None = None,
    freq_set: Iterable[str] | None = None,
    rate_set: Iterable[str] | None = None,
    rand_seed: int | None = None,
    num_threads: int | None = None,
    other_options: str = "",
) -> ModelFinderResult:
    """Find the models of best fit for an alignment using ModelFinder.

    Parameters
    ----------
    aln : Alignment
        The alignment to find the model of best fit for.
    model_set : Iterable[str] | None, optional
        Search space for models.
        Equivalent to IQ-TREE's mset parameter, by default None
    freq_set : Iterable[str] | None, optional
        Search space for frequency types.
        Equivalent to IQ-TREE's mfreq parameter, by default None
    rate_set : Iterable[str] | None, optional
        Search space for rate heterogeneity types.
        Equivalent to IQ-TREE's mrate parameter, by default None
    rand_seed : int | None, optional
        The random seed - None means no seed is used, by default None.
    num_threads: int | None, optional
        Number of threads for IQ-TREE to use, by default None (single-threaded).
        If 0 is specified, IQ-TREE attempts to find the optimal number of threads.
    other_options: str, optional
        Additional command line options for IQ-TREE.

    Returns
    -------
    ModelFinderResult
        Collection of data returned from IQ-TREE's ModelFinder.

    """
    validate_other_options(other_options, INVALID_MODEL_FINDER_PARAMS)

    source = cast("str", aln.info.source)

    rand_seed = process_rand_seed_nonzero(rand_seed)

    if num_threads is None:
        num_threads = 1

    if model_set is None:
        model_set = set()
    if freq_set is None:
        freq_set = set()
    if rate_set is None:
        rate_set = set()

    names = aln.names
    seqs = [str(seq) for seq in aln.iter_seqs(names)]

    raw = yaml.safe_load(
        iq_model_finder(
            names,
            seqs,
            rand_seed,
            ",".join(model_set),
            ",".join(freq_set),
            ",".join(rate_set),
            num_threads,
            other_options,
        ),
    )
    return ModelFinderResult(raw_data=raw, source=source)

Usage

For usage, see "Find the model of best fit with ModelFinder".