skbio.sequence.SubstitutionMatrix.from_dict#
- classmethod SubstitutionMatrix.from_dict(dictionary, dtype='float32')[source]#
- Create a substitution matrix from a 2D dictionary. - Parameters:
- dictionarydict of dict
- 2D dictionary of substitution scores from outer characters to inner characters. 
- dtype{‘float32’, ‘float64’}, optional
- Floating-point data type of the matrix. Default is “float32”. 
 
- 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.]], dtype=float32)