SimilarityMatrix

class pytrimal.SimilarityMatrix

A similarity matrix for biological sequence characters.

__init__(matrix)

Create a new similarity matrix from the given alphabet and data.

Parameters:
  • alphabet (str) – The alphabet of the similarity matrix.

  • matrix (ArrayLike) – The similarity matrix, as a square matrix indexed by the alphabet characters.

Example

Create a new similarity matrix using the HOXD70 scores by Chiaromonte, Yap and Miller (PMID:11928468):

>>> matrix = SimilarityMatrix(
...     "ATCG",
...     [[  91, -114,  -31, -123],
...      [-114,  100, -125,  -31],
...      [ -31, -125,  100, -114],
...      [-123,  -31, -114,   91]]
... )

Create a new similarity matrix using one of the matrices from the Bio.Align.substitution_matrices module:

>>> jones = Bio.Align.substitution_matrices.load('JONES')
>>> matrix = SimilarityMatrix(jones.alphabet, jones)

New in version 0.1.2.

aa()

Create a default amino-acid similarity matrix (BLOSUM62).

distance(a, b)

Return the distance between two sequence characters.

Example

>>> mx = SimilarityMatrix.nt(degenerated=True)
>>> mx.distance('A', 'A')
0.0
>>> mx.distance('A', 'T')
1.5184...
Raises:
  • ValueError – When a or b is an invalid character or a character that was not defined in the matrix alphabet.

  • TypeError – When a or b is a string containing more than one character.

nt(degenerated=False)

Create a default nucleotide similarity matrix.

Parameters:

degenerated (bool) – Set to True to create a similarity matrix for degenerated nucleotides.

similarity(a, b)

Return the similarity between two sequence characters.

Example

>>> mx = SimilarityMatrix.nt()
>>> mx.similarity('A', 'A')
1.0
>>> mx.similarity('A', 'T')
0.0
Raises:
  • ValueError – When a or b is an invalid character or a character that was not defined in the matrix alphabet.

  • TypeError – When a or b is a string containing more than one character.

New in version 0.1.2.