skbio.alignment.Alignment.distances

Alignment.distances(distance_fn=None)[source]

Compute distances between all pairs of sequences

Parameters:

distance_fn : function, optional

Function for computing the distance between a pair of sequences. This must take two sequences as input (as skbio.sequence.BiologicalSequence objects) and return a single integer or float value. Defaults to scipy.spatial.distance.hamming.

Returns:

skbio.DistanceMatrix

Matrix containing the distances between all pairs of sequences.

Raises:

skbio.util.exception.BiologicalSequenceError

If len(self) != len(other) and distance_fn == scipy.spatial.distance.hamming.

See also

skbio.DistanceMatrix, scipy.spatial.distance.hamming

Examples

>>> from skbio.alignment import Alignment
>>> from skbio.sequence import DNA
>>> seqs = [DNA("A-CCGGG", id="s1"),
...         DNA("ATCC--G", id="s2"),
...         DNA("ATCCGGA", id="s3")]
>>> a1 = Alignment(seqs)
>>> print(a1.distances())
3x3 distance matrix
IDs:
s1, s2, s3
Data:
[[ 0.          0.42857143  0.28571429]
 [ 0.42857143  0.          0.42857143]
 [ 0.28571429  0.42857143  0.        ]]