diff --git a/ippisite/ippidb/management/commands/import_v1_data.py b/ippisite/ippidb/management/commands/import_v1_data.py index 8ef965ceffc3a0e1cbbe2fd500b05e554fd8733d..c988fbe5a58614bcbdde33ba839f504249f558d3 100644 --- a/ippisite/ippidb/management/commands/import_v1_data.py +++ b/ippisite/ippidb/management/commands/import_v1_data.py @@ -6,7 +6,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 + Compound, MDDRCompoundImport, MDDRActivityClass, TestActivityDescription, CellLine, RefCompoundBiblio, \ + CompoundAction, TestCytotoxDescription class MyConverter(mysql.connector.conversion.MySQLConverter): @@ -313,12 +314,14 @@ select distinct protein.NumUniprot, domain.PfamNumAccession , complexe.NbCopy, else: self.stdout.write( self.style.SUCCESS('Successfully inserted {} {}'.format(row[0], row[1]))) + CellLine.objects.all().delete() + self.stdout.write( + self.style.SUCCESS('Successfully flushed cell lines table')) cursor.execute("""SELECT * FROM testActivityDescription""") rows = cursor.fetchall() TestActivityDescription.objects.all().delete() - CellLine.objects.all().delete() self.stdout.write( - self.style.SUCCESS('Successfully flushed test activity descriptions table and cell lines table')) + self.style.SUCCESS('Successfully flushed test activity descriptions table')) for row in rows: try: tad = TestActivityDescription() @@ -348,6 +351,37 @@ select distinct protein.NumUniprot, domain.PfamNumAccession , complexe.NbCopy, else: self.stdout.write( self.style.SUCCESS('Successfully inserted {}'.format(row[2]))) + cursor.execute("""SELECT * FROM testCytotoxDescription""") + rows = cursor.fetchall() + TestCytotoxDescription.objects.all().delete() + self.stdout.write( + self.style.SUCCESS('Successfully flushed test cytotoxicity descriptions table')) + for row in rows: + try: + tcd = TestCytotoxDescription() + cursor.execute( + """select IDSource from biblio where IDBiblio={}""".format(row[1])) + biblio_row = cursor.fetchone() + biblio = Bibliography.objects.get(id_source=biblio_row[0]) + tcd.biblio = biblio + tcd.test_name = row[2] + tcd.compound_concentration = row[4] + if row[3] is not None: + tcd.cell_line, created = CellLine.objects.get_or_create( + name=row[3]) + tcd.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(row[2]))) if options['mddr']: from pybel import readfile MDDRCompoundImport.objects.all().delete()