Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Martin Larralde
peptides.py
Commits
724c30f3
Commit
724c30f3
authored
Oct 26, 2021
by
Martin Larralde
Browse files
Rewrite `Peptide.hydrophobic_moment` to use some vectorized code
parent
d478aea3
Changes
1
Hide whitespace changes
Inline
Side-by-side
peptides/__init__.py
View file @
724c30f3
...
...
@@ -636,21 +636,25 @@ class Peptide(typing.Sequence[str]):
"""
scale
=
tables
.
HYDROPHOBICITY
[
"Eisenberg"
]
lut
=
[
scale
.
get
(
aa
,
0.0
)
for
aa
in
self
.
_CODE1
]
angles
=
[(
angle
*
i
)
%
360
for
i
in
range
(
window
)]
moment
=
0.0
angsin
=
array
([
math
.
sin
(
math
.
radians
(
a
))
for
a
in
angles
])
angcos
=
array
([
math
.
cos
(
math
.
radians
(
a
))
for
a
in
angles
])
maxnorm
=
0.0
for
i
in
range
(
len
(
self
.
sequence
)
-
window
+
1
):
# compute sin and cos of angles
sumsin
=
sum
cos
=
0.0
for
aa
,
theta
in
zip
(
self
.
sequence
[
i
:
i
+
window
]
,
ang
les
):
sumsin
+=
scale
.
get
(
aa
,
0.0
)
*
math
.
sin
(
math
.
radians
(
theta
))
sumcos
+=
scale
.
get
(
aa
,
0.0
)
*
math
.
cos
(
math
.
radians
(
theta
)
)
# compute hydrophobic moment of window
hm
=
math
.
sqrt
(
sumsin
**
2
+
sumcos
**
2
)
/
window
if
hm
>
moment
:
moment
=
hm
return
m
oment
sumsin
=
sum
(
take
(
lut
,
self
.
encoded
[
i
:
i
+
window
])
*
angsin
)
sumcos
=
sum
(
take
(
lut
,
self
.
encoded
[
i
:
i
+
window
]
)
*
ang
cos
)
# compute only the distance component (this way we can avoid
# computing the square root in each iteration
)
norm
=
sumsin
**
2
+
sumcos
**
2
if
norm
>
maxnorm
:
maxnorm
=
norm
# compute the angular moment from the norm
return
m
ath
.
sqrt
(
maxnorm
)
/
window
def
hydrophobicity
(
self
,
scale
:
str
=
"KyteDoolittle"
)
->
float
:
"""Compute the hydrophobicity index of a protein sequence.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment