9
9
aaindex2b
10
10
pmf
11
11
'''
12
-
12
+
13
13
import sys , os
14
-
14
+
15
15
_aaindex = dict ()
16
16
_pymol_auto_arg_update = lambda : None
17
-
17
+
18
18
def search (pattern , searchtitle = True , casesensitive = False ):
19
19
'''
20
20
Search for pattern in description and title (optional) of all records and
@@ -29,15 +29,15 @@ def search(pattern, searchtitle=True, casesensitive=False):
29
29
if pattern in whatcase (record .desc ) or searchtitle and pattern in whatcase (record .title ):
30
30
matches .append (record )
31
31
return matches
32
-
32
+
33
33
def grep (pattern ):
34
34
'''
35
35
Search for pattern in title and description of all records (case
36
36
insensitive) and print results on standard output.
37
37
'''
38
38
for record in search (pattern ):
39
39
print record
40
-
40
+
41
41
class Record :
42
42
'''
43
43
Amino acid index (AAindex) Record
@@ -72,7 +72,7 @@ def median(self):
72
72
def __str__ (self ):
73
73
desc = self .desc .replace ('\n ' , ' ' ).strip ()
74
74
return '%s(%s: %s)' % (self .__class__ .__name__ , self .key , desc )
75
-
75
+
76
76
class MatrixRecord (Record ):
77
77
'''
78
78
Matrix record for mutation matrices or pair-wise contact potentials
@@ -107,20 +107,20 @@ def median(self):
107
107
if len (x ) % 2 == 1 :
108
108
return x [len (x )/ 2 ]
109
109
return sum (x [len (x )/ 2 - 1 :len (x )/ 2 + 1 ])/ 2.0
110
-
110
+
111
111
def get (key ):
112
112
'''
113
113
Get record for key
114
114
'''
115
115
if len (_aaindex ) == 0 :
116
116
init ()
117
117
return _aaindex [key ]
118
-
118
+
119
119
def _float_or_None (x ):
120
120
if x == 'NA' or x == '-' :
121
121
return None
122
122
return float (x )
123
-
123
+
124
124
def init (path = None , index = '13' ):
125
125
'''
126
126
Read in the aaindex files. You need to run this (once) before you can
@@ -141,10 +141,10 @@ def init(path=None, index='13'):
141
141
if '3' in index :
142
142
_parse (path + '/aaindex3' , MatrixRecord )
143
143
_pymol_auto_arg_update ()
144
-
144
+
145
145
def init_from_file (filename , type = Record ):
146
146
_parse (filename , type )
147
-
147
+
148
148
def _parse (filename , rec , quiet = True ):
149
149
'''
150
150
Parse aaindex input file. `rec` must be `Record` for aaindex1 and
@@ -157,15 +157,15 @@ def _parse(filename, rec, quiet=True):
157
157
filename = urllib .urlretrieve (url , filename )[0 ]
158
158
print 'Saved to "%s"' % (filename )
159
159
f = open (filename )
160
-
160
+
161
161
current = rec ()
162
162
lastkey = None
163
-
163
+
164
164
for line in f :
165
165
key = line [0 :2 ]
166
166
if key [0 ] == ' ' :
167
167
key = lastkey
168
-
168
+
169
169
if key == '//' :
170
170
_aaindex [current .key ] = current
171
171
current = rec ()
@@ -217,63 +217,63 @@ def _parse(filename, rec, quiet=True):
217
217
current .extend (map (_float_or_None , a ))
218
218
elif not quiet :
219
219
print 'Warning: line starts with "%s"' % (key )
220
-
220
+
221
221
lastkey = key
222
-
222
+
223
223
########## PYMOL ###########
224
-
224
+
225
225
# from Bio.SCOP.Raf import to_one_letter_code
226
226
# See also http://www.pymolwiki.org/index.php/Aa_codes
227
227
to_one_letter_code = {'PAQ' : 'Y' , 'AGM' : 'R' , 'ILE' : 'I' , 'PR3' : 'C' ,
228
- 'GLN' : 'Q' , 'DVA' : 'V' , 'CCS' : 'C' , 'ACL' : 'R' , 'GLX' : 'Z' , 'GLY' : 'G' ,
229
- 'GLZ' : 'G' , 'DTH' : 'T' , 'OAS' : 'S' , 'C6C' : 'C' , 'NEM' : 'H' , 'DLY' : 'K' ,
230
- 'MIS' : 'S' , 'SMC' : 'C' , 'GLU' : 'E' , 'NEP' : 'H' , 'BCS' : 'C' , 'ASQ' : 'D' ,
231
- 'ASP' : 'D' , 'SCY' : 'C' , 'SER' : 'S' , 'LYS' : 'K' , 'SAC' : 'S' , 'PRO' : 'P' ,
232
- 'ASX' : 'B' , 'DGN' : 'Q' , 'DGL' : 'E' , 'MHS' : 'H' , 'ASB' : 'D' , 'ASA' : 'D' ,
233
- 'NLE' : 'L' , 'DCY' : 'C' , 'ASK' : 'D' , 'GGL' : 'E' , 'STY' : 'Y' , 'SEL' : 'S' ,
234
- 'CGU' : 'E' , 'ASN' : 'N' , 'ASL' : 'D' , 'LTR' : 'W' , 'DAR' : 'R' , 'VAL' : 'V' ,
235
- 'CHG' : 'A' , 'TPO' : 'T' , 'CLE' : 'L' , 'GMA' : 'E' , 'HAC' : 'A' , 'AYA' : 'A' ,
236
- 'THR' : 'T' , 'TIH' : 'A' , 'SVA' : 'S' , 'MVA' : 'V' , 'SAR' : 'G' , 'LYZ' : 'K' ,
237
- 'BNN' : 'A' , '5HP' : 'E' , 'IIL' : 'I' , 'SHR' : 'K' , 'HAR' : 'R' , 'FME' : 'M' ,
238
- 'PYX' : 'C' , 'ALO' : 'T' , 'PHI' : 'F' , 'ALM' : 'A' , 'PHL' : 'F' , 'MEN' : 'N' ,
239
- 'TPQ' : 'A' , 'GSC' : 'G' , 'PHE' : 'F' , 'ALA' : 'A' , 'MAA' : 'A' , 'MET' : 'M' ,
240
- 'UNK' : 'X' , 'LEU' : 'L' , 'ALY' : 'K' , 'SET' : 'S' , 'GL3' : 'G' , 'TRG' : 'K' ,
241
- 'CXM' : 'M' , 'TYR' : 'Y' , 'SCS' : 'C' , 'DIL' : 'I' , 'TYQ' : 'Y' , '3AH' : 'H' ,
242
- 'DPR' : 'P' , 'PRR' : 'A' , 'CME' : 'C' , 'IYR' : 'Y' , 'CY1' : 'C' , 'TYY' : 'Y' ,
243
- 'HYP' : 'P' , 'DTY' : 'Y' , '2AS' : 'D' , 'DTR' : 'W' , 'FLA' : 'A' , 'DPN' : 'F' ,
244
- 'DIV' : 'V' , 'PCA' : 'E' , 'MSE' : 'M' , 'MSA' : 'G' , 'AIB' : 'A' , 'CYS' : 'C' ,
245
- 'NLP' : 'L' , 'CYQ' : 'C' , 'HIS' : 'H' , 'DLE' : 'L' , 'CEA' : 'C' , 'DAL' : 'A' ,
246
- 'LLP' : 'K' , 'DAH' : 'F' , 'HMR' : 'R' , 'TRO' : 'W' , 'HIC' : 'H' , 'CYG' : 'C' ,
247
- 'BMT' : 'T' , 'DAS' : 'D' , 'TYB' : 'Y' , 'BUC' : 'C' , 'PEC' : 'C' , 'BUG' : 'L' ,
248
- 'CYM' : 'C' , 'NLN' : 'L' , 'CY3' : 'C' , 'HIP' : 'H' , 'CSO' : 'C' , 'TPL' : 'W' ,
249
- 'LYM' : 'K' , 'DHI' : 'H' , 'MLE' : 'L' , 'CSD' : 'A' , 'HPQ' : 'F' , 'MPQ' : 'G' ,
250
- 'LLY' : 'K' , 'DHA' : 'A' , 'DSN' : 'S' , 'SOC' : 'C' , 'CSX' : 'C' , 'OMT' : 'M' ,
251
- 'DSP' : 'D' , 'PTR' : 'Y' , 'TRP' : 'W' , 'CSW' : 'C' , 'EFC' : 'C' , 'CSP' : 'C' ,
252
- 'CSS' : 'C' , 'SCH' : 'C' , 'OCS' : 'C' , 'NMC' : 'G' , 'SEP' : 'S' , 'BHD' : 'D' ,
253
- 'KCX' : 'K' , 'SHC' : 'C' , 'C5C' : 'C' , 'HTR' : 'W' , 'ARG' : 'R' , 'TYS' : 'Y' ,
254
- 'ARM' : 'R' , 'DNP' : 'A' }
255
-
228
+ 'GLN' : 'Q' , 'DVA' : 'V' , 'CCS' : 'C' , 'ACL' : 'R' , 'GLX' : 'Z' , 'GLY' : 'G' ,
229
+ 'GLZ' : 'G' , 'DTH' : 'T' , 'OAS' : 'S' , 'C6C' : 'C' , 'NEM' : 'H' , 'DLY' : 'K' ,
230
+ 'MIS' : 'S' , 'SMC' : 'C' , 'GLU' : 'E' , 'NEP' : 'H' , 'BCS' : 'C' , 'ASQ' : 'D' ,
231
+ 'ASP' : 'D' , 'SCY' : 'C' , 'SER' : 'S' , 'LYS' : 'K' , 'SAC' : 'S' , 'PRO' : 'P' ,
232
+ 'ASX' : 'B' , 'DGN' : 'Q' , 'DGL' : 'E' , 'MHS' : 'H' , 'ASB' : 'D' , 'ASA' : 'D' ,
233
+ 'NLE' : 'L' , 'DCY' : 'C' , 'ASK' : 'D' , 'GGL' : 'E' , 'STY' : 'Y' , 'SEL' : 'S' ,
234
+ 'CGU' : 'E' , 'ASN' : 'N' , 'ASL' : 'D' , 'LTR' : 'W' , 'DAR' : 'R' , 'VAL' : 'V' ,
235
+ 'CHG' : 'A' , 'TPO' : 'T' , 'CLE' : 'L' , 'GMA' : 'E' , 'HAC' : 'A' , 'AYA' : 'A' ,
236
+ 'THR' : 'T' , 'TIH' : 'A' , 'SVA' : 'S' , 'MVA' : 'V' , 'SAR' : 'G' , 'LYZ' : 'K' ,
237
+ 'BNN' : 'A' , '5HP' : 'E' , 'IIL' : 'I' , 'SHR' : 'K' , 'HAR' : 'R' , 'FME' : 'M' ,
238
+ 'PYX' : 'C' , 'ALO' : 'T' , 'PHI' : 'F' , 'ALM' : 'A' , 'PHL' : 'F' , 'MEN' : 'N' ,
239
+ 'TPQ' : 'A' , 'GSC' : 'G' , 'PHE' : 'F' , 'ALA' : 'A' , 'MAA' : 'A' , 'MET' : 'M' ,
240
+ 'UNK' : 'X' , 'LEU' : 'L' , 'ALY' : 'K' , 'SET' : 'S' , 'GL3' : 'G' , 'TRG' : 'K' ,
241
+ 'CXM' : 'M' , 'TYR' : 'Y' , 'SCS' : 'C' , 'DIL' : 'I' , 'TYQ' : 'Y' , '3AH' : 'H' ,
242
+ 'DPR' : 'P' , 'PRR' : 'A' , 'CME' : 'C' , 'IYR' : 'Y' , 'CY1' : 'C' , 'TYY' : 'Y' ,
243
+ 'HYP' : 'P' , 'DTY' : 'Y' , '2AS' : 'D' , 'DTR' : 'W' , 'FLA' : 'A' , 'DPN' : 'F' ,
244
+ 'DIV' : 'V' , 'PCA' : 'E' , 'MSE' : 'M' , 'MSA' : 'G' , 'AIB' : 'A' , 'CYS' : 'C' ,
245
+ 'NLP' : 'L' , 'CYQ' : 'C' , 'HIS' : 'H' , 'DLE' : 'L' , 'CEA' : 'C' , 'DAL' : 'A' ,
246
+ 'LLP' : 'K' , 'DAH' : 'F' , 'HMR' : 'R' , 'TRO' : 'W' , 'HIC' : 'H' , 'CYG' : 'C' ,
247
+ 'BMT' : 'T' , 'DAS' : 'D' , 'TYB' : 'Y' , 'BUC' : 'C' , 'PEC' : 'C' , 'BUG' : 'L' ,
248
+ 'CYM' : 'C' , 'NLN' : 'L' , 'CY3' : 'C' , 'HIP' : 'H' , 'CSO' : 'C' , 'TPL' : 'W' ,
249
+ 'LYM' : 'K' , 'DHI' : 'H' , 'MLE' : 'L' , 'CSD' : 'A' , 'HPQ' : 'F' , 'MPQ' : 'G' ,
250
+ 'LLY' : 'K' , 'DHA' : 'A' , 'DSN' : 'S' , 'SOC' : 'C' , 'CSX' : 'C' , 'OMT' : 'M' ,
251
+ 'DSP' : 'D' , 'PTR' : 'Y' , 'TRP' : 'W' , 'CSW' : 'C' , 'EFC' : 'C' , 'CSP' : 'C' ,
252
+ 'CSS' : 'C' , 'SCH' : 'C' , 'OCS' : 'C' , 'NMC' : 'G' , 'SEP' : 'S' , 'BHD' : 'D' ,
253
+ 'KCX' : 'K' , 'SHC' : 'C' , 'C5C' : 'C' , 'HTR' : 'W' , 'ARG' : 'R' , 'TYS' : 'Y' ,
254
+ 'ARM' : 'R' , 'DNP' : 'A' }
255
+
256
256
def aaindex2b (key = 'KYTJ820101' , selection = '(all)' , quiet = 0 , var = 'b' ):
257
257
'''
258
258
DESCRIPTION
259
-
259
+
260
260
"aaindex" looks up the Amino Acid Index from
261
261
http://www.genome.jp/aaindex/
262
262
for the given key and assignes b-factors to the given selection. Unknown
263
263
residues get the average index value assigned.
264
-
264
+
265
265
USAGE
266
-
266
+
267
267
aaindex2b [key [, selection]]
268
-
268
+
269
269
ARGUMENTS
270
-
270
+
271
271
key = string: Key of AAindex entry
272
-
272
+
273
273
selection = string: atoms to assign b-factors {default: (all)}
274
-
274
+
275
275
EXAMPLE
276
-
276
+
277
277
# Hydropathy index by Kyte-Doolittle
278
278
aaindex2b KYTJ820101
279
279
spectrumany b, white yellow forest
@@ -282,49 +282,49 @@ def aaindex2b(key='KYTJ820101', selection='(all)', quiet=0, var='b'):
282
282
from pymol import cmd , stored
283
283
entry = get (key )
284
284
median = entry .median ()
285
-
285
+
286
286
if int (quiet ) != 0 :
287
287
print entry .desc .strip ()
288
-
288
+
289
289
def lookup (resn ):
290
290
one_letter = to_one_letter_code .get (resn , 'X' )
291
291
value = entry .get (one_letter )
292
292
if value is None :
293
293
return median
294
294
return value
295
295
stored .aaindex = lookup
296
-
296
+
297
297
cmd .alter (selection , var + '=stored.aaindex(resn)' )
298
-
298
+
299
299
def pmf (key , cutoff = 7.0 , selection1 = '(name CB)' , selection2 = '' , state = 1 , quiet = 1 ):
300
300
'''
301
301
DESCRIPTION
302
-
302
+
303
303
Potential of Mean Force
304
-
304
+
305
305
ARGUMENTS
306
-
306
+
307
307
key = string: aaindex key
308
-
308
+
309
309
cutoff = float: distance cutoff {default: 7.0}
310
310
cutoff = (float, float): distance shell
311
-
311
+
312
312
selection1 = string: atom selection {default: (name CB)}
313
-
313
+
314
314
selection2 = string: atom selection {default: selection1}
315
-
315
+
316
316
NOTES
317
-
317
+
318
318
Does also support a list of keys and a list of cutoffs to deal with
319
319
multiple distance shells.
320
-
320
+
321
321
EXAMPLES
322
-
322
+
323
323
# distance dependent c-beta contact potentials
324
324
pmf SIMK990101, 5, /2x19//A//CB
325
325
pmf SIMK990102, [5, 7.5], /2x19//A//CB
326
326
pmf [SIMK990101, SIMK990102, SIMK990103], [0, 5, 7.5, 10], /2x19//A//CB
327
-
327
+
328
328
# interface potential
329
329
sidechaincenters 2x19_scc, 2x19
330
330
pmf KESO980102, 7.0, /2x19_scc//A, /2x19_scc//B
@@ -354,21 +354,21 @@ def pmf(key, cutoff=7.0, selection1='(name CB)', selection2='', state=1, quiet=1
354
354
print 'Distance shells:'
355
355
for i in range (len (key )):
356
356
print '%s %.1f-%.1f' % (key [i ], cutoff [i ], cutoff [i + 1 ])
357
-
357
+
358
358
idmap = dict ()
359
359
cmd .iterate_state (state , '(%s) or (%s)' % (selection1 , selection2 ),
360
- 'idmap[model,index] = [(resn,name),(x,y,z)]' , space = {'idmap' : idmap })
360
+ 'idmap[model,index] = [(resn,name),(x,y,z)]' , space = {'idmap' : idmap })
361
361
twoN = cmd .count_atoms (selection1 ) + cmd .count_atoms (selection2 )
362
362
pairs = cmd .find_pairs (selection1 , selection2 , cutoff = max (cutoff ),
363
- state1 = state , state2 = state )
363
+ state1 = state , state2 = state )
364
364
if len (pairs ) == 0 :
365
365
print 'Empty pair list'
366
366
return 0.0
367
-
367
+
368
368
matrix = map (get , key )
369
369
for i in matrix :
370
370
assert isinstance (i , MatrixRecord )
371
-
371
+
372
372
i_list = range (len (key ))
373
373
u_sum = 0
374
374
count = 0
@@ -385,12 +385,12 @@ def pmf(key, cutoff=7.0, selection1='(name CB)', selection2='', state=1, quiet=1
385
385
count += 1
386
386
except :
387
387
print 'Failed for' , a1 [0 ], a2 [0 ]
388
-
388
+
389
389
value = float (u_sum ) / twoN
390
390
if not quiet :
391
391
print 'PMF: %.4f (%d contacts, %d residues)' % (value , count , twoN )
392
392
return value
393
-
393
+
394
394
try :
395
395
from pymol import cmd
396
396
cmd .extend ('aaindex2b' , aaindex2b )
@@ -413,5 +413,5 @@ def pymol_auto_arg_update():
413
413
_pymol_auto_arg_update = pymol_auto_arg_update
414
414
except :
415
415
pass
416
-
416
+
417
417
# vi: ts=4:sw=4:smarttab:expandtab
0 commit comments