diff --git a/ippisite/ippidb/management/commands/import_v1_data.py b/ippisite/ippidb/management/commands/import_v1_data.py index 8800e291863b70f5b901f7a696f43f6e2ce7bc0e..d2fe65cc676fe3f892c12ba57555ba457832227a 100644 --- a/ippisite/ippidb/management/commands/import_v1_data.py +++ b/ippisite/ippidb/management/commands/import_v1_data.py @@ -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() diff --git a/ippisite/ippidb/models.py b/ippisite/ippidb/models.py index 4b1ec02e2712b76339c264283cb8b7cf223193f9..76a635dfef5f76086205c601d4c766104e82653d 100644 --- a/ippisite/ippidb/models.py +++ b/ippisite/ippidb/models.py @@ -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 = (