Commit 32066979 authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

make sure Compound-Drugbank similarities does not allow duplicates

- add unique constraint in the model
- remove existing similarity entries before to recompute

FIX #206
parent 4a8b249d
Pipeline #28621 failed with stages
in 8 minutes and 4 seconds
# Generated by Django 2.2.1 on 2020-04-17 10:01
from django.db import migrations
def remove_compound_drugbank_duplicates(apps, schema_editor):
DrugbankCompoundTanimoto = apps.get_model("ippidb", "DrugbankCompoundTanimoto")
db_alias = schema_editor.connection.alias
last = None, None
for dct in DrugbankCompoundTanimoto.objects.using(db_alias).order_by('compound','drugbank_compound'):
if dct.compound == last[0] and dct.drugbank_compound == last[1]:
dct.delete()
else:
last = (dct.compound, dct.drugbank_compound)
class Migration(migrations.Migration):
dependencies = [
('ippidb', '0047_auto_20200416_1359'),
]
operations = [
migrations.RunPython(remove_compound_drugbank_duplicates),
migrations.AlterUniqueTogether(
name='drugbankcompoundtanimoto',
unique_together={('compound', 'drugbank_compound')},
),
]
......@@ -836,6 +836,7 @@ class Compound(AutoFillableModel):
tanimoto=tanimoto,
)
)
DrugbankCompoundTanimoto.objects.filter(compound=self).delete()
DrugbankCompoundTanimoto.objects.bulk_create(dbcts)
@property
......@@ -1285,6 +1286,8 @@ class DrugbankCompoundTanimoto(models.Model):
compound = models.ForeignKey(Compound, models.CASCADE)
drugbank_compound = models.ForeignKey(DrugBankCompound, models.CASCADE)
tanimoto = models.DecimalField("Tanimoto value", max_digits=5, decimal_places=4)
class Meta:
unique_together = (("compound", "drugbank_compound"),)
class Contribution(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