Skip to content
Snippets Groups Projects
Commit 51300820 authored by Rachel TORCHET's avatar Rachel TORCHET
Browse files

Merge branch 'master' of https://gitlab.pasteur.fr/hub/iPPIDB

Former-commit-id: 369978eed018bc4620897adf2a1117c869f41a5e
parents c35e40d0 13fb0c8d
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,8 @@ import mysql.connector
from ippidb.models import Bibliography, Protein, Taxonomy, MolecularFunction, \
Domain, ProteinDomainBoundComplex, ProteinDomainPartnerComplex, Symmetry, Ppi, PpiComplex, Disease, \
Compound, MDDRCompoundImport, MDDRActivityClass, TestActivityDescription, CellLine, RefCompoundBiblio, \
CompoundAction, TestCytotoxDescription
CompoundAction, TestCytotoxDescription, TestPKDescription, CompoundActivityResult, \
CompoundCytotoxicityResult, CompoundPKResult
class MyConverter(mysql.connector.conversion.MySQLConverter):
......@@ -61,7 +62,7 @@ class Command(BaseCommand):
action='store_true',
dest='ppi',
default=False,
help='Flush and migrate ppis and complexes',
help='Flush and migrate ppis, complexes, and tests',
)
parser.add_argument(
'--mddr',
......@@ -84,13 +85,6 @@ class Command(BaseCommand):
default=False,
help='Flush and migrate compounds-bibliography',
)
parser.add_argument(
'--test-activity-description',
action='store_true',
dest='test-activity-description',
default=False,
help='Flush and migrate test activity descriptions',
)
parser.add_argument(
'--stoponfail',
action='store_true',
......@@ -326,6 +320,7 @@ select distinct protein.NumUniprot, domain.PfamNumAccession , complexe.NbCopy,
TestActivityDescription.objects.all().delete()
self.stdout.write(
self.style.SUCCESS('Successfully flushed test activity descriptions table'))
tad_id_mapping = {}
for row in rows:
try:
tad = TestActivityDescription()
......@@ -349,6 +344,7 @@ select distinct protein.NumUniprot, domain.PfamNumAccession , complexe.NbCopy,
tad.cell_line, created = CellLine.objects.get_or_create(
name=row[16])
tad.save()
tad_id_mapping[row[0]] = tad.id
except Exception as e:
if options['stoponfail']:
import traceback
......@@ -361,11 +357,39 @@ select distinct protein.NumUniprot, domain.PfamNumAccession , complexe.NbCopy,
else:
self.stdout.write(
self.style.SUCCESS('Successfully inserted {}'.format(row[2])))
cursor.execute("""select c.CanonicalSmile, r.IDTestActivity, r.ActivityType, r.Activity, r.PourcentInhib from cmpdActiveResult as r inner join compound as c on r.IDCompound = c.IDCompound;""")
rows = cursor.fetchall()
CompoundActivityResult.objects.all().delete()
self.stdout.write(
self.style.SUCCESS('Successfully flushed compound activity result table'))
for row in rows:
try:
car = CompoundActivityResult()
car.test_activity_description = TestActivityDescription.objects.get(id=tad_id_mapping[row[1]])
car.compound = Compound.objects.get(canonical_smile=row[0])
car.activity_type = row[2]
car.activity = row[3]
car.inhibition_percentage = row[4]
car.modulation_type = 'I' # because previous DB is only about inhibitors
car.save()
except Exception as e:
if options['stoponfail']:
import traceback
self.stderr.write(traceback.format_exc())
raise CommandError(
'Failed inserting {} {}'.format(row[1], row[2]))
else:
self.stdout.write(
self.style.ERROR('Failed inserting {} {}'.format(row[1], row[2])))
else:
self.stdout.write(
self.style.SUCCESS('Successfully inserted {}'.format(str(car))))
cursor.execute("""SELECT * FROM testCytotoxDescription""")
rows = cursor.fetchall()
TestCytotoxDescription.objects.all().delete()
self.stdout.write(
self.style.SUCCESS('Successfully flushed test cytotoxicity descriptions table'))
tcd_id_mapping = {}
for row in rows:
try:
tcd = TestCytotoxDescription()
......@@ -380,6 +404,74 @@ select distinct protein.NumUniprot, domain.PfamNumAccession , complexe.NbCopy,
tcd.cell_line, created = CellLine.objects.get_or_create(
name=row[3])
tcd.save()
tcd_id_mapping[row[0]] = tcd.id
except Exception as e:
if options['stoponfail']:
import traceback
self.stderr.write(traceback.format_exc())
raise CommandError(
'Failed inserting {} {}'.format(row[1], row[2]))
else:
self.stdout.write(
self.style.ERROR('Failed inserting {} {}'.format(row[1], row[2])))
else:
self.stdout.write(
self.style.SUCCESS('Successfully inserted {}'.format(row[2])))
cursor.execute("""select c.CanonicalSmile, r.IDTestCytotox, r.IDTestCytotox from cmpdCytotoxResult as r inner join compound as c on r.IDCompound = c.IDCompound;""")
rows = cursor.fetchall()
CompoundCytotoxicityResult.objects.all().delete()
self.stdout.write(
self.style.SUCCESS('Successfully flushed compound cytotoxicity result table'))
for row in rows:
try:
ccr = CompoundCytotoxicityResult()
ccr.test_cytotoxicity_description = TestCytotoxDescription.objects.get(id=tcd_id_mapping[row[1]])
ccr.compound = Compound.objects.get(canonical_smile=row[0])
ccr.toxicity = row[2] == 'Y'
ccr.save()
except Exception as e:
if options['stoponfail']:
import traceback
self.stderr.write(traceback.format_exc())
raise CommandError(
'Failed inserting {} {}'.format(row[1], row[2]))
else:
import traceback
self.stderr.write(traceback.format_exc())
self.stdout.write(
self.style.ERROR('Failed inserting {} {}'.format(row[1], row[2])))
else:
self.stdout.write(
self.style.SUCCESS('Successfully inserted {}'.format(str(ccr))))
cursor.execute("""SELECT * FROM testPKDescription""")
rows = cursor.fetchall()
TestPKDescription.objects.all().delete()
self.stdout.write(
self.style.SUCCESS('Successfully flushed test PK descriptions table'))
for row in rows:
try:
tpd = TestPKDescription()
cursor.execute(
"""select IDSource from biblio where IDBiblio={}""".format(row[1]))
biblio_row = cursor.fetchone()
biblio = Bibliography.objects.get(id_source=biblio_row[0])
tpd.biblio = biblio
tpd.test_name = row[2]
#tcd.compound_concentration = row[4]
try:
taxonomy = Taxonomy.objects.get(taxonomy_id=10090)
except Taxonomy.DoesNotExist:
taxonomy = Taxonomy()
taxonomy.taxonomy_id = 10090
# dirty hack: all organisms in this table are "mice",
# hence assuming Mus musculus
taxonomy.save(autofill=True)
tpd.organism = taxonomy
tpd.administration_mode = row[4]
tpd.concentration = row[5]
tpd.dose = round(row[6], 4)
tpd.dose_interval = row[7]
tpd.save()
except Exception as e:
if options['stoponfail']:
import traceback
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2018-03-08 19:35
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ippidb', '0028_auto_20180307_1405'),
]
operations = [
migrations.AlterField(
model_name='testpkdescription',
name='dose',
field=models.DecimalField(blank=True, decimal_places=4, max_digits=9, null=True, verbose_name='Dose in mg/kg'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2018-03-08 19:45
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ippidb', '0029_auto_20180308_1935'),
]
operations = [
migrations.AddField(
model_name='testpkdescription',
name='concentration',
field=models.DecimalField(blank=True, decimal_places=3, max_digits=7, null=True, verbose_name='Concentration in mg/l'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2018-03-08 21:12
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ippidb', '0030_testpkdescription_concentration'),
]
operations = [
migrations.AddField(
model_name='compoundactivityresult',
name='inhibition_percentage',
field=models.DecimalField(decimal_places=0, max_digits=3, null=True, verbose_name='Inhibition percentage'),
),
]
......@@ -477,6 +477,8 @@ class CompoundActivityResult(models.Model):
'Activity type', max_length=5, choices=ACTIVITY_TYPES)
activity = models.DecimalField(
'Activity', max_digits=12, decimal_places=10)
inhibition_percentage = models.DecimalField(
'Inhibition percentage', max_digits=3, decimal_places=0, null=True)
modulation_type = models.CharField(
'Modulation type', max_length=1, choices=MODULATION_TYPES)
......@@ -484,6 +486,8 @@ class CompoundActivityResult(models.Model):
unique_together = (
('compound', 'test_activity_description', 'activity_type'),)
def __str__(self):
return 'Compound activity result for {} test {} on {}'.format(self.activity_type, self.test_activity_description.id, self.compound.id)
class TestCytotoxDescription(models.Model):
biblio = models.ForeignKey(Bibliography, models.CASCADE)
......@@ -501,6 +505,9 @@ class CompoundCytotoxicityResult(models.Model):
class Meta:
unique_together = (('compound', 'test_cytotoxicity_description'),)
def __str__(self):
return 'Compound cytotoxicity result for test {} on {}'.format(self.test_cytotoxicity_description.id, self.compound.id)
class TestPKDescription(models.Model):
ADMINISTRATION_MODES = (
......@@ -514,8 +521,10 @@ class TestPKDescription(models.Model):
organism = models.ForeignKey(Taxonomy, models.CASCADE)
administration_mode = models.CharField(
'Administration mode', max_length=2, choices=ADMINISTRATION_MODES, blank=True, null=True)
concentration = models.DecimalField(
'Concentration in mg/l', max_digits=7, decimal_places=3, blank=True, null=True)
dose = models.DecimalField(
'Dose in mg/kg', max_digits=7, decimal_places=4, blank=True, null=True)
'Dose in mg/kg', max_digits=9, decimal_places=4, blank=True, null=True)
dose_interval = models.IntegerField(
'Dose interval, in hours', blank=True, null=True)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment