Commit 4555c122 authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

add drugbank_id to compound and inchikey to drugbankcompound

the linking is based on the InChiKey identity
WIP on #220
parent de63e9a2
# Generated by Django 2.2.1 on 2020-05-21 18:58
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ippidb', '0059_auto_20200430_1926'),
]
operations = [
migrations.AddField(
model_name='compound',
name='drugbank_id',
field=models.TextField(blank=True, null=True, unique=True, verbose_name='Drugbank ID'),
),
migrations.AlterField(
model_name='compoundpkresult',
name='voldistribution_av',
field=models.BooleanField(verbose_name='Volume distribution (Vd) available'),
),
]
# Generated by Django 2.2.1 on 2020-05-22 08:13
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ippidb', '0060_auto_20200521_1858'),
]
operations = [
migrations.AlterField(
model_name='compound',
name='drugbank_id',
field=models.TextField(blank=True, null=True, verbose_name='Drugbank ID'),
),
]
# Generated by Django 2.2.1 on 2020-05-22 18:29
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ippidb', '0061_auto_20200522_0813'),
]
operations = [
migrations.AddField(
model_name='drugbankcompound',
name='inchikey',
field=models.TextField(blank=True, null=True, verbose_name='InChiKey'),
),
]
# Generated by Django 2.2.1 on 2020-04-28 17:17
from django.db import migrations, models
import django.db.models.deletion
from ippidb.models import Compound, DrugBankCompound
def run_generate_drugbank_inchikey(apps, schema_editor):
for drugbank_compound in DrugBankCompound.objects.all():
drugbank_compound.save(autofill=True)
def set_compound_drugbank_links(apps, schema_editor):
for compound in Compound.objects.all():
compound.set_drugbank_link()
compound.save()
class Migration(migrations.Migration):
dependencies = [
('ippidb', '0062_drugbankcompound_inchikey'),
]
operations = [
migrations.RunPython(run_generate_drugbank_inchikey, reverse_code=migrations.RunPython.noop),
migrations.RunPython(set_compound_drugbank_links, reverse_code=migrations.RunPython.noop),
]
......@@ -785,6 +785,7 @@ class Compound(AutoFillableModel):
)
iupac_name = models.TextField(verbose_name="IUPAC name", blank=True, null=True)
ligand_id = models.CharField("PDB Ligand ID", max_length=3, blank=True, null=True)
drugbank_id = models.TextField("Drugbank ID", blank=True, null=True)
pubs = models.IntegerField(
verbose_name="Number of publications", null=True, blank=True
)
......@@ -994,6 +995,15 @@ class Compound(AutoFillableModel):
self.inchi = smi2inchi(self.canonical_smile)
self.inchikey = smi2inchikey(self.canonical_smile)
self.compute_drugbank_compound_similarity()
self.set_drugbank_link()
self.save()
def set_drugbank_link(self):
drugbank_qs = DrugBankCompound.objects.filter(inchikey=self.inchikey)
if drugbank_qs.count() > 0:
self.drugbank_id = drugbank_qs[0].id
else:
self.drugbank_id = None
def compute_fsp3(self):
"""
......@@ -1370,7 +1380,7 @@ class RefCompoundBiblio(models.Model):
return "Ref. {} on {}".format(self.bibliography, self.compound)
class DrugBankCompound(models.Model):
class DrugBankCompound(AutoFillableModel):
"""
Drugbank compound
"""
......@@ -1378,6 +1388,14 @@ 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")
inchikey = models.TextField(verbose_name="InChiKey", blank=True, null=True)
def autofill(self):
"""
Computing InChiKey
"""
# compute InChiKey
self.inchikey = smi2inchikey(self.canonical_smiles)
class DrugbankCompoundTanimoto(models.Model):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment