scirpy.ir_dist.sequence_dist#
- scirpy.ir_dist.sequence_dist(seqs, seqs2=None, *, metric='identity', cutoff=None, n_jobs=-1, **kwargs)#
Calculate a sequence x sequence distance matrix.
Calculates the full pairwise distance matrix.
Important
Distances are offset by 1 to allow efficient use of sparse matrices ().
That means, a
distance > cutoffis represented as0, adistance == 0is represented as1, adistance == 1is represented as2and so on.Only returns distances
<= cutoff. Larger distances are eliminated from the sparse matrix.Distances are non-negative.
When
seqsorseqs2includes non-unique values, the function internally uses only unique sequences to calculate the distances. Note that, if the input arrays contain large numbers of duplicated values (i.e. hundreds each), this will lead to large “dense” blocks in the sparse matrix. This will result in slow processing and high memory usage.- Parameters:
seqs (
Sequence[str]) – Numpy array of nucleotide or amino acid sequences. Note that not all distance metrics support nucleotide sequences.seqs2 (
Sequence[str] |None(default:None)) – Second array sequences. When omitted,sequence_distcomputes the square matrix ofunique_seqs.metric (
Union[Literal['alignment','fastalignment','identity','levenshtein','hamming','gpu_haming','normalized_hamming','tcrdist'],DistanceCalculator] (default:'identity')) –- You can choose one of the following metrics:
identity– 1 for identical sequences, 0 otherwise. SeeIdentityDistanceCalculator. This metric implies a cutoff of 0.levenshtein– Levenshtein edit distance. SeeLevenshteinDistanceCalculator.tcrdist– Distance based on pairwise sequence alignments between TCR CDR3 sequences based on the tcrdist metric. SeeTCRdistDistanceCalculator.hamming– Hamming distance for CDR3 sequences of equal length. SeeHammingDistanceCalculator.gpu_hamming– Hamming distance for CDR3 sequences of equal length calculated with a GPU. SeeGPUHammingDistanceCalculator.normalized_hamming– Normalized Hamming distance (in percent) for CDR3 sequences of equal length. SeeHammingDistanceCalculator.alignment– Distance based on pairwise sequence alignments using the BLOSUM62 matrix. This option is incompatible with nucleotide sequences. SeeFastAlignmentDistanceCalculator.fastalignment– Distance based on pairwise sequence alignments using the BLOSUM62 matrix. Faster implementation ofalignmentwith some loss. This option is incompatible with nucleotide sequences. SeeFastAlignmentDistanceCalculator.any instance of
DistanceCalculator.
cutoff (
None|int(default:None)) – All distances> cutoffwill be replaced by0and eliminated from the sparse matrix. A sensible cutoff depends on the distance metric, you can find information in the corresponding docs. If set toNone, the cutoff will be10for thealignmentandfastalignmentmetric, and2forlevenshteinandhamming. For the identity metric, the cutoff is ignored and always set to0.n_jobs (
int(default:-1)) –Number of CPU cores to use when running a DistanceCalculator that supports paralellization.
A cutoff of 0 implies the
identitymetric.kwargs – Additional parameters passed to the
DistanceCalculator.
- Return type:
- Returns:
Symmetrical, sparse pairwise distance matrix.