Skip to content

Commit

Permalink
Autopep8: E1 Indentions
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Lecher <[email protected]>
  • Loading branch information
jlec committed Jul 4, 2014
1 parent 4a6537b commit 52c52df
Show file tree
Hide file tree
Showing 75 changed files with 11,262 additions and 11,279 deletions.
152 changes: 76 additions & 76 deletions aaindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
aaindex2b
pmf
'''

import sys, os

_aaindex = dict()
_pymol_auto_arg_update = lambda: None

def search(pattern, searchtitle=True, casesensitive=False):
'''
Search for pattern in description and title (optional) of all records and
Expand All @@ -29,15 +29,15 @@ def search(pattern, searchtitle=True, casesensitive=False):
if pattern in whatcase(record.desc) or searchtitle and pattern in whatcase(record.title):
matches.append(record)
return matches

def grep(pattern):
'''
Search for pattern in title and description of all records (case
insensitive) and print results on standard output.
'''
for record in search(pattern):
print record

class Record:
'''
Amino acid index (AAindex) Record
Expand Down Expand Up @@ -72,7 +72,7 @@ def median(self):
def __str__(self):
desc = self.desc.replace('\n', ' ').strip()
return '%s(%s: %s)' % (self.__class__.__name__, self.key, desc)

class MatrixRecord(Record):
'''
Matrix record for mutation matrices or pair-wise contact potentials
Expand Down Expand Up @@ -107,20 +107,20 @@ def median(self):
if len(x) % 2 == 1:
return x[len(x)/2]
return sum(x[len(x)/2-1:len(x)/2+1])/2.0

def get(key):
'''
Get record for key
'''
if len(_aaindex) == 0:
init()
return _aaindex[key]

def _float_or_None(x):
if x == 'NA' or x == '-':
return None
return float(x)

def init(path=None, index='13'):
'''
Read in the aaindex files. You need to run this (once) before you can
Expand All @@ -141,10 +141,10 @@ def init(path=None, index='13'):
if '3' in index:
_parse(path + '/aaindex3', MatrixRecord)
_pymol_auto_arg_update()

def init_from_file(filename, type=Record):
_parse(filename, type)

def _parse(filename, rec, quiet=True):
'''
Parse aaindex input file. `rec` must be `Record` for aaindex1 and
Expand All @@ -157,15 +157,15 @@ def _parse(filename, rec, quiet=True):
filename = urllib.urlretrieve(url, filename)[0]
print 'Saved to "%s"' % (filename)
f = open(filename)

current = rec()
lastkey = None

for line in f:
key = line[0:2]
if key[0] == ' ':
key = lastkey

if key == '//':
_aaindex[current.key] = current
current = rec()
Expand Down Expand Up @@ -217,63 +217,63 @@ def _parse(filename, rec, quiet=True):
current.extend(map(_float_or_None, a))
elif not quiet:
print 'Warning: line starts with "%s"' % (key)

lastkey = key

########## PYMOL ###########

# from Bio.SCOP.Raf import to_one_letter_code
# See also http://www.pymolwiki.org/index.php/Aa_codes
to_one_letter_code = {'PAQ': 'Y', 'AGM': 'R', 'ILE': 'I', 'PR3': 'C',
'GLN': 'Q', 'DVA': 'V', 'CCS': 'C', 'ACL': 'R', 'GLX': 'Z', 'GLY': 'G',
'GLZ': 'G', 'DTH': 'T', 'OAS': 'S', 'C6C': 'C', 'NEM': 'H', 'DLY': 'K',
'MIS': 'S', 'SMC': 'C', 'GLU': 'E', 'NEP': 'H', 'BCS': 'C', 'ASQ': 'D',
'ASP': 'D', 'SCY': 'C', 'SER': 'S', 'LYS': 'K', 'SAC': 'S', 'PRO': 'P',
'ASX': 'B', 'DGN': 'Q', 'DGL': 'E', 'MHS': 'H', 'ASB': 'D', 'ASA': 'D',
'NLE': 'L', 'DCY': 'C', 'ASK': 'D', 'GGL': 'E', 'STY': 'Y', 'SEL': 'S',
'CGU': 'E', 'ASN': 'N', 'ASL': 'D', 'LTR': 'W', 'DAR': 'R', 'VAL': 'V',
'CHG': 'A', 'TPO': 'T', 'CLE': 'L', 'GMA': 'E', 'HAC': 'A', 'AYA': 'A',
'THR': 'T', 'TIH': 'A', 'SVA': 'S', 'MVA': 'V', 'SAR': 'G', 'LYZ': 'K',
'BNN': 'A', '5HP': 'E', 'IIL': 'I', 'SHR': 'K', 'HAR': 'R', 'FME': 'M',
'PYX': 'C', 'ALO': 'T', 'PHI': 'F', 'ALM': 'A', 'PHL': 'F', 'MEN': 'N',
'TPQ': 'A', 'GSC': 'G', 'PHE': 'F', 'ALA': 'A', 'MAA': 'A', 'MET': 'M',
'UNK': 'X', 'LEU': 'L', 'ALY': 'K', 'SET': 'S', 'GL3': 'G', 'TRG': 'K',
'CXM': 'M', 'TYR': 'Y', 'SCS': 'C', 'DIL': 'I', 'TYQ': 'Y', '3AH': 'H',
'DPR': 'P', 'PRR': 'A', 'CME': 'C', 'IYR': 'Y', 'CY1': 'C', 'TYY': 'Y',
'HYP': 'P', 'DTY': 'Y', '2AS': 'D', 'DTR': 'W', 'FLA': 'A', 'DPN': 'F',
'DIV': 'V', 'PCA': 'E', 'MSE': 'M', 'MSA': 'G', 'AIB': 'A', 'CYS': 'C',
'NLP': 'L', 'CYQ': 'C', 'HIS': 'H', 'DLE': 'L', 'CEA': 'C', 'DAL': 'A',
'LLP': 'K', 'DAH': 'F', 'HMR': 'R', 'TRO': 'W', 'HIC': 'H', 'CYG': 'C',
'BMT': 'T', 'DAS': 'D', 'TYB': 'Y', 'BUC': 'C', 'PEC': 'C', 'BUG': 'L',
'CYM': 'C', 'NLN': 'L', 'CY3': 'C', 'HIP': 'H', 'CSO': 'C', 'TPL': 'W',
'LYM': 'K', 'DHI': 'H', 'MLE': 'L', 'CSD': 'A', 'HPQ': 'F', 'MPQ': 'G',
'LLY': 'K', 'DHA': 'A', 'DSN': 'S', 'SOC': 'C', 'CSX': 'C', 'OMT': 'M',
'DSP': 'D', 'PTR': 'Y', 'TRP': 'W', 'CSW': 'C', 'EFC': 'C', 'CSP': 'C',
'CSS': 'C', 'SCH': 'C', 'OCS': 'C', 'NMC': 'G', 'SEP': 'S', 'BHD': 'D',
'KCX': 'K', 'SHC': 'C', 'C5C': 'C', 'HTR': 'W', 'ARG': 'R', 'TYS': 'Y',
'ARM': 'R', 'DNP': 'A'}
'GLN': 'Q', 'DVA': 'V', 'CCS': 'C', 'ACL': 'R', 'GLX': 'Z', 'GLY': 'G',
'GLZ': 'G', 'DTH': 'T', 'OAS': 'S', 'C6C': 'C', 'NEM': 'H', 'DLY': 'K',
'MIS': 'S', 'SMC': 'C', 'GLU': 'E', 'NEP': 'H', 'BCS': 'C', 'ASQ': 'D',
'ASP': 'D', 'SCY': 'C', 'SER': 'S', 'LYS': 'K', 'SAC': 'S', 'PRO': 'P',
'ASX': 'B', 'DGN': 'Q', 'DGL': 'E', 'MHS': 'H', 'ASB': 'D', 'ASA': 'D',
'NLE': 'L', 'DCY': 'C', 'ASK': 'D', 'GGL': 'E', 'STY': 'Y', 'SEL': 'S',
'CGU': 'E', 'ASN': 'N', 'ASL': 'D', 'LTR': 'W', 'DAR': 'R', 'VAL': 'V',
'CHG': 'A', 'TPO': 'T', 'CLE': 'L', 'GMA': 'E', 'HAC': 'A', 'AYA': 'A',
'THR': 'T', 'TIH': 'A', 'SVA': 'S', 'MVA': 'V', 'SAR': 'G', 'LYZ': 'K',
'BNN': 'A', '5HP': 'E', 'IIL': 'I', 'SHR': 'K', 'HAR': 'R', 'FME': 'M',
'PYX': 'C', 'ALO': 'T', 'PHI': 'F', 'ALM': 'A', 'PHL': 'F', 'MEN': 'N',
'TPQ': 'A', 'GSC': 'G', 'PHE': 'F', 'ALA': 'A', 'MAA': 'A', 'MET': 'M',
'UNK': 'X', 'LEU': 'L', 'ALY': 'K', 'SET': 'S', 'GL3': 'G', 'TRG': 'K',
'CXM': 'M', 'TYR': 'Y', 'SCS': 'C', 'DIL': 'I', 'TYQ': 'Y', '3AH': 'H',
'DPR': 'P', 'PRR': 'A', 'CME': 'C', 'IYR': 'Y', 'CY1': 'C', 'TYY': 'Y',
'HYP': 'P', 'DTY': 'Y', '2AS': 'D', 'DTR': 'W', 'FLA': 'A', 'DPN': 'F',
'DIV': 'V', 'PCA': 'E', 'MSE': 'M', 'MSA': 'G', 'AIB': 'A', 'CYS': 'C',
'NLP': 'L', 'CYQ': 'C', 'HIS': 'H', 'DLE': 'L', 'CEA': 'C', 'DAL': 'A',
'LLP': 'K', 'DAH': 'F', 'HMR': 'R', 'TRO': 'W', 'HIC': 'H', 'CYG': 'C',
'BMT': 'T', 'DAS': 'D', 'TYB': 'Y', 'BUC': 'C', 'PEC': 'C', 'BUG': 'L',
'CYM': 'C', 'NLN': 'L', 'CY3': 'C', 'HIP': 'H', 'CSO': 'C', 'TPL': 'W',
'LYM': 'K', 'DHI': 'H', 'MLE': 'L', 'CSD': 'A', 'HPQ': 'F', 'MPQ': 'G',
'LLY': 'K', 'DHA': 'A', 'DSN': 'S', 'SOC': 'C', 'CSX': 'C', 'OMT': 'M',
'DSP': 'D', 'PTR': 'Y', 'TRP': 'W', 'CSW': 'C', 'EFC': 'C', 'CSP': 'C',
'CSS': 'C', 'SCH': 'C', 'OCS': 'C', 'NMC': 'G', 'SEP': 'S', 'BHD': 'D',
'KCX': 'K', 'SHC': 'C', 'C5C': 'C', 'HTR': 'W', 'ARG': 'R', 'TYS': 'Y',
'ARM': 'R', 'DNP': 'A'}

def aaindex2b(key='KYTJ820101', selection='(all)', quiet=0, var='b'):
'''
DESCRIPTION
"aaindex" looks up the Amino Acid Index from
http://www.genome.jp/aaindex/
for the given key and assignes b-factors to the given selection. Unknown
residues get the average index value assigned.
USAGE
aaindex2b [key [, selection]]
ARGUMENTS
key = string: Key of AAindex entry
selection = string: atoms to assign b-factors {default: (all)}
EXAMPLE
# Hydropathy index by Kyte-Doolittle
aaindex2b KYTJ820101
spectrumany b, white yellow forest
Expand All @@ -282,49 +282,49 @@ def aaindex2b(key='KYTJ820101', selection='(all)', quiet=0, var='b'):
from pymol import cmd, stored
entry = get(key)
median = entry.median()

if int(quiet) != 0:
print entry.desc.strip()

def lookup(resn):
one_letter = to_one_letter_code.get(resn, 'X')
value = entry.get(one_letter)
if value is None:
return median
return value
stored.aaindex = lookup

cmd.alter(selection, var + '=stored.aaindex(resn)')

def pmf(key, cutoff=7.0, selection1='(name CB)', selection2='', state=1, quiet=1):
'''
DESCRIPTION
Potential of Mean Force
ARGUMENTS
key = string: aaindex key
cutoff = float: distance cutoff {default: 7.0}
cutoff = (float, float): distance shell
selection1 = string: atom selection {default: (name CB)}
selection2 = string: atom selection {default: selection1}
NOTES
Does also support a list of keys and a list of cutoffs to deal with
multiple distance shells.
EXAMPLES
# distance dependent c-beta contact potentials
pmf SIMK990101, 5, /2x19//A//CB
pmf SIMK990102, [5, 7.5], /2x19//A//CB
pmf [SIMK990101, SIMK990102, SIMK990103], [0, 5, 7.5, 10], /2x19//A//CB
# interface potential
sidechaincenters 2x19_scc, 2x19
pmf KESO980102, 7.0, /2x19_scc//A, /2x19_scc//B
Expand Down Expand Up @@ -354,21 +354,21 @@ def pmf(key, cutoff=7.0, selection1='(name CB)', selection2='', state=1, quiet=1
print 'Distance shells:'
for i in range(len(key)):
print '%s %.1f-%.1f' % (key[i], cutoff[i], cutoff[i+1])

idmap = dict()
cmd.iterate_state(state, '(%s) or (%s)' % (selection1, selection2),
'idmap[model,index] = [(resn,name),(x,y,z)]', space={'idmap': idmap})
'idmap[model,index] = [(resn,name),(x,y,z)]', space={'idmap': idmap})
twoN = cmd.count_atoms(selection1) + cmd.count_atoms(selection2)
pairs = cmd.find_pairs(selection1, selection2, cutoff=max(cutoff),
state1=state, state2=state)
state1=state, state2=state)
if len(pairs) == 0:
print 'Empty pair list'
return 0.0

matrix = map(get, key)
for i in matrix:
assert isinstance(i, MatrixRecord)

i_list = range(len(key))
u_sum = 0
count = 0
Expand All @@ -385,12 +385,12 @@ def pmf(key, cutoff=7.0, selection1='(name CB)', selection2='', state=1, quiet=1
count += 1
except:
print 'Failed for', a1[0], a2[0]

value = float(u_sum) / twoN
if not quiet:
print 'PMF: %.4f (%d contacts, %d residues)' % (value, count, twoN)
return value

try:
from pymol import cmd
cmd.extend('aaindex2b', aaindex2b)
Expand All @@ -413,5 +413,5 @@ def pymol_auto_arg_update():
_pymol_auto_arg_update = pymol_auto_arg_update
except:
pass

# vi: ts=4:sw=4:smarttab:expandtab
Loading

0 comments on commit 52c52df

Please sign in to comment.