skbio.sequence.Sequence.distance#
- Sequence.distance(other, metric=None)[source]#
Compute the distance to another sequence.
- Parameters:
- otherstr, Sequence, or 1D np.ndarray (np.uint8 or ‘|S1’)
Sequence to compute the distance to. If
otheris aSequenceobject, it must be the same type as this sequence. Other input types will be converted into aSequenceobject of the same type as this sequence.- metriccallable, optional
Function used to compute the distance between this sequence and
other. By default, Hamming distance will be used (seehamming).metricshould be a function that takes twoSequenceobjects and returns afloat. The sequence objects passed tometricwill be the same type as this sequence. Seeskbio.sequence.distancefor other predefined metrics that can be supplied viametric.
- Returns:
- float
Distance between this and other sequences as defined by
metric.
- Raises:
- TypeError
If
otheris aSequenceobject with a different type than this sequence.
See also
Examples
>>> from skbio import Sequence >>> s = Sequence('GGUC') >>> t = Sequence('AGUC')
Compute Hamming distance (the default metric):
>>> s.distance(t) 0.25
Use a custom metric:
>>> def custom_metric(s1, s2): return 0.42 >>> s.distance(t, custom_metric) 0.42