From f209b66f24041600290a2fc45d6ccd1cfe607bc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20=20MENAGER?= <herve.menager@pasteur.fr> Date: Wed, 7 Mar 2018 14:07:50 +0100 Subject: [PATCH] migrate TestCytotoxicityDescription (fix #28) Former-commit-id: 67806cbeb81fdcc7428cb60b69155b7531f002e7 --- .../management/commands/import_v1_data.py | 40 +++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/ippisite/ippidb/management/commands/import_v1_data.py b/ippisite/ippidb/management/commands/import_v1_data.py index 8ef965ce..c988fbe5 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() -- GitLab