Skip to content
Snippets Groups Projects
Commit 9b2b88fa authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

migrate compound PK results (fix #17)

Former-commit-id: f198b586ce9d22b1e60e2dfa294e061f24dfa076
parent 51300820
No related branches found
No related tags found
No related merge requests found
......@@ -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()
......
......@@ -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 = (
......
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