forked from njohner/ost_pymodules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hydrophobicity.py
157 lines (140 loc) · 7.27 KB
/
hydrophobicity.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#------------------------------------------------------------------------------------------------
#This file is part of the ost_pymodules project (https://github.com/njohner/ost_pymodules).
#
#Copyright 2015 Niklaus Johner
#
#ost_pymodules is free software: you can redistribute it and/or modify
#it under the terms of the GNU Lesser General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#ost_pymodules is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU Lesser General Public License for more details.
#
#You should have received a copy of the GNU Lesser General Public License
#along with ost_pymodules. If not, see <http://www.gnu.org/licenses/>.
#------------------------------------------------------------------------------------------------
"""
.. codeauthor:: Niklaus Johner <[email protected]>
This module contains function to calculate hydrophobicity and hydrophobic
moments from different hydrophobic scales.
"""
try:
from ost import *
import math,sys
import entity_alg
except:
print 'could not import at least on of the following modules: ost,math,sys,entity_alg'
__all__=('CalculateCharge','CalculateChargeWithSlidingWindow','GetResidueHydrophobicity',\
'CalculateHydrophobicMoment','CalculateHydrophobicMoment2','CalculateHydrophobicMoment3'\
,'CalculateHydrophobicMomentWithSlidingWindow','CalculateHydrophobicity'\
,'CalculateHydrophobicityWithSlidingWindow','DetermineAmphipathicity','AnalyzeHydrophobicMoment')
hydrophobicity_dict_kyte={'A':1.8,'C':2.5,'D':-3.5,'E':-3.5,'F':2.8,'G':-0.4,'H':-3.2,'I':4.5,'K':-3.9,'L':3.8,'M':1.9,'N':-3.5,'P':-1.6,'Q':-3.5,'R':-4.5,'S':-0.8,'T':-0.7,'V':4.2,'W':-0.9,'Y':-1.3}
hydrophobicity_dict_eisenberg={'A':0.62,'C':0.29,'D':-0.9,'E':-0.74,'F':1.19,'G':0.48,'H':-0.4,'I':1.38,'K':-1.5,'L':1.06,'M':0.64,'N':-0.78,'P':0.12,'Q':-0.85,'R':-2.53,'S':-0.18,'T':-0.05,'V':1.08,'W':0.81,'Y':0.26}
residue_charge_dict={'A':0,'C':0,'D':-1,'E':-1,'F':0,'G':0,'H':0,'I':0,'K':1,'L':0,'M':0,'N':0,'P':0,'Q':0,'R':1,'S':0,'T':0,'V':0,'W':0,'Y':0}
def CalculateCharge(sequence):
if type(sequence)==type(seq.SequenceHandle()):sequence=sequence.GetGaplessString()
elif type(sequence)!=type(str()):sequence=entity_alg.CreateSequenceFromView(sequence,'temp').GetGaplessString()
c=0
for s in sequence:
c+=residue_charge_dict[s]
return c
def CalculateChargeWithSlidingWindow(sequence,w=11):
if type(sequence)==type(seq.SequenceHandle()):sequence=sequence.GetGaplessString()
elif type(sequence)!=type(str()):sequence=entity_alg.CreateSequenceFromView(sequence,'temp').GetGaplessString()
charge_list=[]
before=int(w/2.)
after=w-before
n=len(sequence)
for i in range(n):
b=max(0,i-before)
e=min(n,i+after)
l=float(e-b)
charge_list.append(CalculateCharge(sequence[b:e])/l)
return charge_list
def GetResidueHydrophobicity(res,hydrophobicity_dict=hydrophobicity_dict_eisenberg):
return hydrophobicity_dict(res.GetOneLetterCode())
def CalculateHydrophobicMoment(sequence,angle=100./180.*math.pi,hydrophobicity_dict=hydrophobicity_dict_eisenberg):
if type(sequence)==type(seq.SequenceHandle()):sequence=sequence.GetGaplessString()
elif type(sequence)!=type(str()):sequence=entity_alg.CreateSequenceFromView(sequence,'temp').GetGaplessString()
v=geom.Rotate(geom.Vec2(1.0,0.0),-angle)
moment=geom.Vec2()
for r in sequence:
v=geom.Rotate(v,angle)
moment+=hydrophobicity_dict[r]*v
return geom.Length(moment)
def CalculateHydrophobicMoment2(sequence,angle=100./180.*math.pi,hydrophobicity_dict=hydrophobicity_dict_eisenberg):
if type(sequence)==type(seq.SequenceHandle()):sequence=sequence.GetGaplessString()
elif type(sequence)!=type(str()):sequence=entity_alg.CreateSequenceFromView(sequence,'temp').GetGaplessString()
v=geom.Rotate(geom.Vec2(1.0,0.0),-angle)
moment=geom.Vec2()
hm=CalculateHydrophobicity(sequence,hydrophobicity_dict)
for r in sequence:
v=geom.Rotate(v,angle)
moment+=(hydrophobicity_dict[r]-hm)*v
return geom.Length(moment)
def CalculateHydrophobicMoment3(sequence,angle=100./180.*math.pi,hydrophobicity_dict=hydrophobicity_dict_eisenberg):
if type(sequence)==type(seq.SequenceHandle()):sequence=sequence.GetGaplessString()
elif type(sequence)!=type(str()):sequence=entity_alg.CreateSequenceFromView(sequence,'temp').GetGaplessString()
v=geom.Rotate(geom.Vec2(1.0,0.0),-angle)
moment=geom.Vec2()
for r in sequence:
v=geom.Rotate(v,angle)
moment+=hydrophobicity_dict[r]*v
vm=moment/geom.Length(moment)
m_max=moment
for i in range(-3,4):
v=geom.Rotate(geom.Vec2(1.0,0.0),-angle)
moment=geom.Vec2()
for r in sequence:
v=geom.Rotate(v,angle)
v2=v-0.2*i*vm
v2=geom.Dot(v2,vm)/geom.Length(v2)*vm
moment+=hydrophobicity_dict[r]*v2
if geom.Length(moment)>geom.Length(m_max):m_max=moment
return geom.Length(m_max)
def CalculateHydrophobicMomentWithSlidingWindow(sequence,w=11,angle=100./180.*math.pi,hydrophobicity_dict=hydrophobicity_dict_eisenberg):
if type(sequence)==type(seq.SequenceHandle()):sequence=sequence.GetGaplessString()
elif type(sequence)!=type(str()):sequence=entity_alg.CreateSequenceFromView(sequence,'temp').GetGaplessString()
moment_list=[]
before=int(w/2.)
after=w-before
n=len(sequence)
for i in range(n):
b=max(0,i-before)
e=min(n,i+after)
l=float(e-b)
moment_list.append(CalculateHydrophobicMoment3(sequence[b:e],angle,hydrophobicity_dict)/l)
return moment_list
def CalculateHydrophobicity(sequence,hydrophobicity_dict=hydrophobicity_dict_eisenberg):
if type(sequence)==type(seq.SequenceHandle()):sequence=sequence.GetGaplessString()
elif type(sequence)!=type(str()):sequence=entity_alg.CreateSequenceFromView(sequence,'temp').GetGaplessString()
hydrophobicity=0.0
for r in sequence:
hydrophobicity+=hydrophobicity_dict[r]
return hydrophobicity
def CalculateHydrophobicityWithSlidingWindow(sequence,w=11,hydrophobicity_dict=hydrophobicity_dict_eisenberg):
if type(sequence)==type(seq.SequenceHandle()):sequence=sequence.GetGaplessString()
elif type(sequence)!=type(str()):sequence=entity_alg.CreateSequenceFromView(sequence,'temp').GetGaplessString()
hydrophobicity_list=[]
before=int(w/2.)
after=w-before
n=len(sequence)
for i in range(n):
b=max(0,i-before)
e=min(n,i+after)
l=float(e-b)
hydrophobicity_list.append(CalculateHydrophobicity(sequence[b:e],hydrophobicity_dict_eisenberg)/l)
return hydrophobicity_list
def DetermineAmphipathicity(sequence,w=11,angle=100./180.*math.pi):
hydrophobicity_list=CalculateHydrophobicityWithSlidingWindow(sequence,w,hydrophobicity_dict_eisenberg)
moment_list=CalculateHydrophobicMomentWithSlidingWindow(sequence,w,angle,hydrophobicity_dict_eisenberg)
#return [m/w for m,h in zip(moment_list,hydrophobicity_list)]
return [m-0.6-0.382*h for m,h in zip(moment_list,hydrophobicity_list)]
def AnalyzeHydrophobicMoment(sequence,w=11,angle_min=1.39,angle_max=3.14,step=0.1,hydrophobicity_dict=hydrophobicity_dict_eisenberg):
moment_list=[]
for a in npy.arange(angle_min,angle_max,step):
moment_list.append(CalculateHydrophobicMomentWithSlidingWindow(sequence,w,a,hydrophobicity_dict_eisenberg))
return moment_list