Package lib :: Package sequence_alignment :: Module substitution_matrices
[hide private]
[frames] | no frames]

Source Code for Module lib.sequence_alignment.substitution_matrices

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2015 Edward d'Auvergne                                        # 
  4  #                                                                             # 
  5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  6  #                                                                             # 
  7  # This program is free software: you can redistribute it and/or modify        # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation, either version 3 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # This program is distributed in the hope that it will be useful,             # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 19  #                                                                             # 
 20  ############################################################################### 
 21   
 22  # Module docstring. 
 23  """Substitution matrices for use in sequence alignment.""" 
 24   
 25  # Python module imports. 
 26  from numpy import array, int16 
 27   
 28   
 29  SIMILARITY_DNA_SEQ = 'AGCT' 
 30  SIMILARITY_DNA = array([ 
 31      [ 1, -1, -1, -1], 
 32      [-1,  1, -1, -1], 
 33      [-1, -1,  1, -1], 
 34      [-1, -1, -1,  1] 
 35  ], int16) 
 36   
 37   
 38  # This matrix was created by Todd Lowe   12/10/92 
 39  # 
 40  # Uses ambiguous nucleotide codes, probabilities rounded to 
 41  #  nearest integer 
 42  # 
 43  # Lowest score = -4, Highest score = 5 
 44  # 
 45  # Taken from ftp://ftp.ncbi.nih.gov/blast/matrices/NUC.4.4. 
 46  NUC_4_4_SEQ = 'ATGCSWRYKMBVHDNU' 
 47  NUC_4_4 = array([ 
 48      # A,   T,   G,   C,   S,   W,   R,   Y,   K,   M,   B,   V,   H,   D,   N,   U 
 49      [ 5,  -4,  -4,  -4,  -4,   1,   1,  -4,  -4,   1,  -4,  -1,  -1,  -1,  -2,  -4],  # A 
 50      [-4,   5,  -4,  -4,  -4,   1,  -4,   1,   1,  -4,  -1,  -4,  -1,  -1,  -2,   5],  # T 
 51      [-4,  -4,   5,  -4,   1,  -4,   1,  -4,   1,  -4,  -1,  -1,  -4,  -1,  -2,  -4],  # G 
 52      [-4,  -4,  -4,   5,   1,  -4,  -4,   1,  -4,   1,  -1,  -1,  -1,  -4,  -2,  -4],  # C 
 53      [-4,  -4,   1,   1,  -1,  -4,  -2,  -2,  -2,  -2,  -1,  -1,  -3,  -3,  -1,  -4],  # S 
 54      [ 1,   1,  -4,  -4,  -4,  -1,  -2,  -2,  -2,  -2,  -3,  -3,  -1,  -1,  -1,   1],  # W 
 55      [ 1,  -4,   1,  -4,  -2,  -2,  -1,  -4,  -2,  -2,  -3,  -1,  -3,  -1,  -1,  -4],  # R 
 56      [-4,   1,  -4,   1,  -2,  -2,  -4,  -1,  -2,  -2,  -1,  -3,  -1,  -3,  -1,   1],  # Y 
 57      [-4,   1,   1,  -4,  -2,  -2,  -2,  -2,  -1,  -4,  -1,  -3,  -3,  -1,  -1,   1],  # K 
 58      [ 1,  -4,  -4,   1,  -2,  -2,  -2,  -2,  -4,  -1,  -3,  -1,  -1,  -3,  -1,  -4],  # M 
 59      [-4,  -1,  -1,  -1,  -1,  -3,  -3,  -1,  -1,  -3,  -1,  -2,  -2,  -2,  -1,  -1],  # B 
 60      [-1,  -4,  -1,  -1,  -1,  -3,  -1,  -3,  -3,  -1,  -2,  -1,  -2,  -2,  -1,  -4],  # V 
 61      [-1,  -1,  -4,  -1,  -3,  -1,  -3,  -1,  -3,  -1,  -2,  -2,  -1,  -2,  -1,  -1],  # H 
 62      [-1,  -1,  -1,  -4,  -3,  -1,  -1,  -3,  -1,  -3,  -2,  -2,  -2,  -1,  -1,  -1],  # D 
 63      [-2,  -2,  -2,  -2,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -2],  # N 
 64      [-4,   5,  -4,  -4,  -4,   1,  -4,   1,   1,  -4,  -1,  -4,  -1,  -1,  -2,   5],  # U 
 65  ], int16) 
 66   
 67   
 68  #  Matrix made by matblas from blosum62.iij 
 69  #  * column uses minimum score 
 70  #  BLOSUM Clustered Scoring Matrix in 1/2 Bit Units 
 71  #  Blocks Database = /data/blocks_5.0/blocks.dat 
 72  #  Cluster Percentage: >= 62 
 73  #  Entropy =   0.6979, Expected =  -0.5209 
 74  # 
 75  # Taken from ftp://ftp.ncbi.nih.gov/blast/matrices/BLOSUM62. 
 76  BLOSUM62_SEQ = 'ARNDCQEGHILKMFPSTWYVBZX*' 
 77  BLOSUM62 = array([ 
 78      # A,  R,  N,  D,  C,  Q,  E,  G,  H,  I,  L,  K,  M,  F,  P,  S,  T,  W,  Y,  V,  B,  Z,  X,  * 
 79      [ 4, -1, -2, -2,  0, -1, -1,  0, -2, -1, -1, -1, -1, -2, -1,  1,  0, -3, -2,  0, -2, -1,  0, -4],     # A 
 80      [-1,  5,  0, -2, -3,  1,  0, -2,  0, -3, -2,  2, -1, -3, -2, -1, -1, -3, -2, -3, -1,  0, -1, -4],     # R 
 81      [-2,  0,  6,  1, -3,  0,  0,  0,  1, -3, -3,  0, -2, -3, -2,  1,  0, -4, -2, -3,  3,  0, -1, -4],     # N 
 82      [-2, -2,  1,  6, -3,  0,  2, -1, -1, -3, -4, -1, -3, -3, -1,  0, -1, -4, -3, -3,  4,  1, -1, -4],     # D 
 83      [ 0, -3, -3, -3,  9, -3, -4, -3, -3, -1, -1, -3, -1, -2, -3, -1, -1, -2, -2, -1, -3, -3, -2, -4],     # C 
 84      [-1,  1,  0,  0, -3,  5,  2, -2,  0, -3, -2,  1,  0, -3, -1,  0, -1, -2, -1, -2,  0,  3, -1, -4],     # Q 
 85      [-1,  0,  0,  2, -4,  2,  5, -2,  0, -3, -3,  1, -2, -3, -1,  0, -1, -3, -2, -2,  1,  4, -1, -4],     # E 
 86      [ 0, -2,  0, -1, -3, -2, -2,  6, -2, -4, -4, -2, -3, -3, -2,  0, -2, -2, -3, -3, -1, -2, -1, -4],     # G 
 87      [-2,  0,  1, -1, -3,  0,  0, -2,  8, -3, -3, -1, -2, -1, -2, -1, -2, -2,  2, -3,  0,  0, -1, -4],     # H 
 88      [-1, -3, -3, -3, -1, -3, -3, -4, -3,  4,  2, -3,  1,  0, -3, -2, -1, -3, -1,  3, -3, -3, -1, -4],     # I 
 89      [-1, -2, -3, -4, -1, -2, -3, -4, -3,  2,  4, -2,  2,  0, -3, -2, -1, -2, -1,  1, -4, -3, -1, -4],     # L 
 90      [-1,  2,  0, -1, -3,  1,  1, -2, -1, -3, -2,  5, -1, -3, -1,  0, -1, -3, -2, -2,  0,  1, -1, -4],     # K 
 91      [-1, -1, -2, -3, -1,  0, -2, -3, -2,  1,  2, -1,  5,  0, -2, -1, -1, -1, -1,  1, -3, -1, -1, -4],     # M 
 92      [-2, -3, -3, -3, -2, -3, -3, -3, -1,  0,  0, -3,  0,  6, -4, -2, -2,  1,  3, -1, -3, -3, -1, -4],     # F 
 93      [-1, -2, -2, -1, -3, -1, -1, -2, -2, -3, -3, -1, -2, -4,  7, -1, -1, -4, -3, -2, -2, -1, -2, -4],     # P 
 94      [ 1, -1,  1,  0, -1,  0,  0,  0, -1, -2, -2,  0, -1, -2, -1,  4,  1, -3, -2, -2,  0,  0,  0, -4],     # S 
 95      [ 0, -1,  0, -1, -1, -1, -1, -2, -2, -1, -1, -1, -1, -2, -1,  1,  5, -2, -2,  0, -1, -1,  0, -4],     # T 
 96      [-3, -3, -4, -4, -2, -2, -3, -2, -2, -3, -2, -3, -1,  1, -4, -3, -2, 11,  2, -3, -4, -3, -2, -4],     # W 
 97      [-2, -2, -2, -3, -2, -1, -2, -3,  2, -1, -1, -2, -1,  3, -3, -2, -2,  2,  7, -1, -3, -2, -1, -4],     # Y 
 98      [ 0, -3, -3, -3, -1, -2, -2, -3, -3,  3,  1, -2,  1, -1, -2, -2,  0, -3, -1,  4, -3, -2, -1, -4],     # V 
 99      [-2, -1,  3,  4, -3,  0,  1, -1,  0, -3, -4,  0, -3, -3, -2,  0, -1, -4, -3, -3,  4,  1, -1, -4],     # B 
100      [-1,  0,  0,  1, -3,  3,  4, -2,  0, -3, -3,  1, -1, -3, -1,  0, -1, -3, -2, -2,  1,  4, -1, -4],     # Z 
101      [ 0, -1, -1, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2,  0,  0, -2, -1, -1, -1, -1, -1, -4],     # X 
102      [-4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,  1]      # * 
103  ], int16) 
104   
105   
106  # This matrix was produced by "pam" Version 1.0.6 [28-Jul-93] 
107  # 
108  # PAM 250 substitution matrix, scale = ln(2)/3 = 0.231049 
109  # 
110  # Expected score = -0.844, Entropy = 0.354 bits 
111  # 
112  # Lowest score = -8, Highest score = 17 
113  # 
114  # Taken from ftp://ftp.ncbi.nih.gov/blast/matrices/PAM250. 
115  PAM250_SEQ = 'ARNDCQEGHILKMFPSTWYVBZX*' 
116  PAM250 = array([ 
117      # A,  R,  N,  D,  C,  Q,  E,  G,  H,  I,  L,  K,  M,  F,  P,  S,  T,  W,  Y , V,  B,  Z,  X,  * 
118      [ 2, -2,  0,  0, -2,  0,  0,  1, -1, -1, -2, -1, -1, -3,  1,  1,  1, -6, -3 , 0,  0,  0,  0, -8],     #A 
119      [-2,  6,  0, -1, -4,  1, -1, -3,  2, -2, -3,  3,  0, -4,  0,  0, -1,  2, -4 ,-2, -1,  0, -1, -8],     #R 
120      [ 0,  0,  2,  2, -4,  1,  1,  0,  2, -2, -3,  1, -2, -3,  0,  1,  0, -4, -2 ,-2,  2,  1,  0, -8],     #N 
121      [ 0, -1,  2,  4, -5,  2,  3,  1,  1, -2, -4,  0, -3, -6, -1,  0,  0, -7, -4 ,-2,  3,  3, -1, -8],     #D 
122      [-2, -4, -4, -5, 12, -5, -5, -3, -3, -2, -6, -5, -5, -4, -3,  0, -2, -8,  0 ,-2, -4, -5, -3, -8],     #C 
123      [ 0,  1,  1,  2, -5,  4,  2, -1,  3, -2, -2,  1, -1, -5,  0, -1, -1, -5, -4 ,-2,  1,  3, -1, -8],     #Q 
124      [ 0, -1,  1,  3, -5,  2,  4,  0,  1, -2, -3,  0, -2, -5, -1,  0,  0, -7, -4 ,-2,  3,  3, -1, -8],     #E 
125      [ 1, -3,  0,  1, -3, -1,  0,  5, -2, -3, -4, -2, -3, -5,  0,  1,  0, -7, -5 ,-1,  0,  0, -1, -8],     #G 
126      [-1,  2,  2,  1, -3,  3,  1, -2,  6, -2, -2,  0, -2, -2,  0, -1, -1, -3,  0 ,-2,  1,  2, -1, -8],     #H 
127      [-1, -2, -2, -2, -2, -2, -2, -3, -2,  5,  2, -2,  2,  1, -2, -1,  0, -5, -1 , 4, -2, -2, -1, -8],     #I 
128      [-2, -3, -3, -4, -6, -2, -3, -4, -2,  2,  6, -3,  4,  2, -3, -3, -2, -2, -1 , 2, -3, -3, -1, -8],     #L 
129      [-1,  3,  1,  0, -5,  1,  0, -2,  0, -2, -3,  5,  0, -5, -1,  0,  0, -3, -4 ,-2,  1,  0, -1, -8],     #K 
130      [-1,  0, -2, -3, -5, -1, -2, -3, -2,  2,  4,  0,  6,  0, -2, -2, -1, -4, -2 , 2, -2, -2, -1, -8],     #M 
131      [-3, -4, -3, -6, -4, -5, -5, -5, -2,  1,  2, -5,  0,  9, -5, -3, -3,  0,  7 ,-1, -4, -5, -2, -8],     #F 
132      [ 1,  0,  0, -1, -3,  0, -1,  0,  0, -2, -3, -1, -2, -5,  6,  1,  0, -6, -5 ,-1, -1,  0, -1, -8],     #P 
133      [ 1,  0,  1,  0,  0, -1,  0,  1, -1, -1, -3,  0, -2, -3,  1,  2,  1, -2, -3 ,-1,  0,  0,  0, -8],     #S 
134      [ 1, -1,  0,  0, -2, -1,  0,  0, -1,  0, -2,  0, -1, -3,  0,  1,  3, -5, -3 , 0,  0, -1,  0, -8],     #T 
135      [-6,  2, -4, -7, -8, -5, -7, -7, -3, -5, -2, -3, -4,  0, -6, -2, -5, 17,  0 ,-6, -5, -6, -4, -8],     #W 
136      [-3, -4, -2, -4,  0, -4, -4, -5,  0, -1, -1, -4, -2,  7, -5, -3, -3,  0, 10 ,-2, -3, -4, -2, -8],     #Y 
137      [ 0, -2, -2, -2, -2, -2, -2, -1, -2,  4,  2, -2,  2, -1, -1, -1,  0, -6, -2 , 4, -2, -2, -1, -8],     #V 
138      [ 0, -1,  2,  3, -4,  1,  3,  0,  1, -2, -3,  1, -2, -4, -1,  0,  0, -5, -3 ,-2,  3,  2, -1, -8],     #B 
139      [ 0,  0,  1,  3, -5,  3,  3,  0,  2, -2, -3,  0, -2, -5,  0,  0, -1, -6, -4 ,-2,  2,  3, -1, -8],     #Z 
140      [ 0, -1,  0, -1, -3, -1, -1, -1, -1, -1, -1, -1, -1, -2, -1,  0,  0, -4, -2 ,-1, -1, -1, -1, -8],     #X 
141      [-8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -8 ,-8, -8, -8, -8,  1],     #* 
142  ], int16) 
143