Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ippidb-web
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
iPPIDB
ippidb-web
Commits
cd607709
Commit
cd607709
authored
6 years ago
by
Hervé MENAGER
Browse files
Options
Downloads
Patches
Plain Diff
fix drugbank similarities computation
see #96 Former-commit-id: 7f0a26180c2fb18638e0293c5ecbc123b4a9271f
parent
400877c3
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ippisite/ippidb/management/commands/import_drugbank.py
+7
-2
7 additions, 2 deletions
ippisite/ippidb/management/commands/import_drugbank.py
ippisite/ippidb/models.py
+1
-17
1 addition, 17 deletions
ippisite/ippidb/models.py
with
8 additions
and
19 deletions
ippisite/ippidb/management/commands/import_drugbank.py
+
7
−
2
View file @
cd607709
...
...
@@ -25,12 +25,13 @@ class Command(BaseCommand):
self
.
stdout
.
write
(
self
.
style
.
SUCCESS
(
'
Successfully flushed DrugBank Compound table
'
))
for
index
,
row
in
df
.
iterrows
():
# insert all drugbank compounds in the DB
try
:
dbc
=
DrugBankCompound
()
dbc
.
id
=
row
.
loc
[
'
DRUGBANK_ID
'
]
dbc
.
common_name
=
row
.
loc
[
'
COMMON_NAME
'
]
dbc
.
canonical_smiles
=
row
.
loc
[
'
CanSmile
'
]
dbc
.
save
(
autofill
=
True
)
dbc
.
save
()
except
Exception
:
self
.
stdout
.
write
(
self
.
style
.
ERROR
(
'
Failed inserting {}
'
.
format
(
row
.
loc
[
'
DRUGBANK_ID
'
])))
...
...
@@ -40,4 +41,8 @@ class Command(BaseCommand):
'
Failed inserting {}
'
.
format
(
row
.
loc
[
'
DRUGBANK_ID
'
]))
else
:
self
.
stdout
.
write
(
self
.
style
.
SUCCESS
(
'
Successfully inserted {}
'
.
format
(
row
.
loc
[
'
DRUGBANK_ID
'
])))
\ No newline at end of file
self
.
style
.
SUCCESS
(
'
Successfully inserted {}
'
.
format
(
row
.
loc
[
'
DRUGBANK_ID
'
])))
for
c
in
Compound
.
objects
.
all
():
# for each iPPI-DB compound compute the most similar drugbank compounds
c
.
save
(
autofill
=
True
)
self
.
stdout
.
write
(
self
.
style
.
SUCCESS
(
'
Successfully computed 15 most similar compounds for {}
'
.
format
(
c
.
id
)))
This diff is collapsed.
Click to expand it.
ippisite/ippidb/models.py
+
1
−
17
View file @
cd607709
...
...
@@ -749,29 +749,13 @@ class RefCompoundBiblio(models.Model):
class
Meta
:
unique_together
=
((
'
compound
'
,
'
bibliography
'
),)
class
DrugBankCompound
(
AutoFillable
Model
):
class
DrugBankCompound
(
models
.
Model
):
id
=
models
.
TextField
(
'
Drugbank ID
'
,
unique
=
True
,
primary_key
=
True
)
common_name
=
models
.
TextField
(
'
Common name
'
)
canonical_smiles
=
models
.
TextField
(
'
Canonical SMILES
'
)
def
autofill
(
self
):
self
.
compute_compound_similarity
()
def
compute_compound_similarity
(
self
):
"""
compute Tanimoto similarity to existing compounds
"""
self
.
save
()
fingerprinter
=
FingerPrinter
(
"
FP4
"
)
#1. compute tanimoto for SMILES query vs all compounds
smiles_dict
=
{
c
.
id
:
c
.
canonical_smile
for
c
in
Compound
.
objects
.
all
()}
tanimoto_dict
=
fingerprinter
.
tanimoto_smiles
(
self
.
canonical_smiles
,
smiles_dict
)
tanimoto_dict
=
dict
(
sorted
(
tanimoto_dict
.
items
(),
key
=
operator
.
itemgetter
(
1
),
reverse
=
True
)[:
15
])
dbcts
=
[]
for
id_
,
tanimoto
in
tanimoto_dict
.
items
():
dbcts
.
append
(
DrugbankCompoundTanimoto
(
compound
=
Compound
.
objects
.
get
(
id
=
id_
),
drugbank_compound
=
self
,
tanimoto
=
tanimoto
))
DrugbankCompoundTanimoto
.
objects
.
bulk_create
(
dbcts
)
class
DrugbankCompoundTanimoto
(
models
.
Model
):
compound
=
models
.
ForeignKey
(
Compound
,
models
.
CASCADE
)
drugbank_compound
=
models
.
ForeignKey
(
DrugBankCompound
,
models
.
CASCADE
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment