diff --git a/ippisite/ippidb/management/commands/import_v1_data.py b/ippisite/ippidb/management/commands/import_v1_data.py
index d2fe65cc676fe3f892c12ba57555ba457832227a..a5bbdfb8e0141af3fc6c49fa3fb53f34371c5dce 100644
--- a/ippisite/ippidb/management/commands/import_v1_data.py
+++ b/ippisite/ippidb/management/commands/import_v1_data.py
@@ -448,6 +448,7 @@ select distinct protein.NumUniprot, domain.PfamNumAccession , complexe.NbCopy,
TestPKDescription.objects.all().delete()
self.stdout.write(
self.style.SUCCESS('Successfully flushed test PK descriptions table'))
+ tpd_id_mapping = {}
for row in rows:
try:
tpd = TestPKDescription()
@@ -472,6 +473,7 @@ select distinct protein.NumUniprot, domain.PfamNumAccession , complexe.NbCopy,
tpd.dose = round(row[6], 4)
tpd.dose_interval = row[7]
tpd.save()
+ tpd_id_mapping[row[0]] = tpd.id
except Exception as e:
if options['stoponfail']:
import traceback
@@ -484,6 +486,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.IDTestPK, r.Tolerated, r.AUC, r.Clearance, r.Cmax, r.OralBioavailability, r.Tdemi, r.Tmax, r.VolDistribution from cmpdPKResult as r inner join compound as c on r.IDCompound = c.IDCompound;""")
+ rows = cursor.fetchall()
+ CompoundPKResult.objects.all().delete()
+ self.stdout.write(
+ self.style.SUCCESS('Successfully flushed compound cytotoxicity PK table'))
+ for row in rows:
+ try:
+ cpr = CompoundPKResult()
+ cpr.test_pk_description = TestPKDescription.objects.get(id=tpd_id_mapping[row[1]])
+ cpr.compound = Compound.objects.get(canonical_smile=row[0])
+ cpr.tolerated = row[2] == 'Y'
+ cpr.auc = row[3]
+ cpr.clearance = row[4]
+ cpr.cmax = row[5]
+ cpr.oral_bioavailability = row[6]
+ cpr.t_demi = row[7]
+ cpr.t_max = row[8]
+ cpr.voldistribution = row[9]
+ cpr.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(cpr))))
if options['mddr']:
from pybel import readfile
MDDRCompoundImport.objects.all().delete()
diff --git a/ippisite/ippidb/models.py b/ippisite/ippidb/models.py
index 76a635dfef5f76086205c601d4c766104e82653d..161b8dba6577142e93b5c0485c170a4c89c25e99 100644
--- a/ippisite/ippidb/models.py
+++ b/ippisite/ippidb/models.py
@@ -549,6 +549,9 @@ class CompoundPKResult(models.Model):
class Meta:
unique_together = (('compound', 'test_pk_description'),)
+ def __str__(self):
+ return 'Compound PK result for test {} on {}'.format(self.test_pk_description.id, self.compound.id)
+
class CompoundAction(models.Model):
ACTIVATION_MODES = (