Skip to content

jc_distances

piqtree.jc_distances(aln, num_threads=None)

Compute pairwise JC distances for a given alignment.

PARAMETER DESCRIPTION
aln

The alignment to compute pairwise JC distances for.

TYPE: Alignment

num_threads

Number of threads for IQ-TREE to use, by default None (uses all available threads).

TYPE: int | None DEFAULT: None

RETURNS DESCRIPTION
DistanceMatrix

Pairwise JC distance matrix.

Source code in src/piqtree/iqtree/_jc_distance.py
def jc_distances(
    aln: Alignment,
    num_threads: int | None = None,
) -> DistanceMatrix:
    """Compute pairwise JC distances for a given alignment.

    Parameters
    ----------
    aln : Alignment
        The alignment to compute pairwise JC distances for.
    num_threads: int | None, optional
        Number of threads for IQ-TREE to use,
        by default None (uses all available threads).

    Returns
    -------
    DistanceMatrix
        Pairwise JC distance matrix.

    """
    if num_threads is None:
        num_threads = 0

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

    distances = np.array(iq_jc_distances(names, seqs, num_threads)).reshape(
        (len(names), len(names)),
    )
    return _dists_to_distmatrix(distances, names)

Usage

For usage, see "Calculate pairwise Jukes-Cantor distances".