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

migrate Compound cytotoxicity results (fix #16)

Former-commit-id: cf03962fb888e7a55f9339b784c83b754c46a5c1
parent cf66a659
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, TestPKDescription, CompoundActivityResult
CompoundAction, TestCytotoxDescription, TestPKDescription, CompoundActivityResult, \
CompoundCytotoxicityResult, CompoundPKResult
class MyConverter(mysql.connector.conversion.MySQLConverter):
......@@ -388,6 +389,7 @@ select distinct protein.NumUniprot, domain.PfamNumAccession , complexe.NbCopy,
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()
......@@ -402,6 +404,7 @@ 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
......@@ -414,6 +417,32 @@ 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.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()
......
......@@ -505,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 = (
......
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