skbio.sequence.SubstitutionMatrix.from_dict#

classmethod SubstitutionMatrix.from_dict(dictionary)[source]#

Create a substitution matrix from a 2D dictionary.

Parameters:
dictionarydict of dict

2D dictionary of substitution scores from outer characters to inner characters.

Returns:
SubstitutionMatrix

Substitution matrix constructed from the dictionary.

Raises:
ValueError

If outer and inner characters are inconsistent.

ValueError

If scores are not numbers.

Examples

>>> from skbio import SubstitutionMatrix
>>> d = {'a': {'a': 1, 'b': 0, 'c': 0},
...      'b': {'a': 0, 'b': 1, 'c': 0},
...      'c': {'a': 0, 'b': 0, 'c': 1}}
>>> mat = SubstitutionMatrix.from_dict(d)
>>> mat.alphabet
('a', 'b', 'c')
>>> mat.scores
array([[ 1.,  0.,  0.],
       [ 0.,  1.,  0.],
       [ 0.,  0.,  1.]])