diff --git a/ippisite/db.sqlite3.REMOVED.git-id b/ippisite/db.sqlite3.REMOVED.git-id index 226017b6055590ffd8776a4cb3d80676752867e5..79d648ce7798093caec89be2388292b4c02d088e 100644 --- a/ippisite/db.sqlite3.REMOVED.git-id +++ b/ippisite/db.sqlite3.REMOVED.git-id @@ -1 +1 @@ -0029ba376cb55048b9799efa8aaeccaaf33d350d \ No newline at end of file +eb310574640f27558fc3118d82ffb14ea7912b79 \ No newline at end of file diff --git a/ippisite/ippidb/management/commands/import_v1_data.py b/ippisite/ippidb/management/commands/import_v1_data.py index 622ede9604849163d251b3b58e0346c84489a549..1b2bf7bbe7bbe5ab0c7bf22e4b5fa179234d0ec2 100644 --- a/ippisite/ippidb/management/commands/import_v1_data.py +++ b/ippisite/ippidb/management/commands/import_v1_data.py @@ -7,7 +7,7 @@ from pybel import readfile from ippidb.models import Bibliography, Protein, Taxonomy, MolecularFunction, \ Domain, ProteinDomainBoundComplex, ProteinDomainPartnerComplex, Symmetry, Ppi, PpiComplex, Disease, \ - Compound, MDDRCompoundImport, MDDRActivityClass + Compound, MDDRCompoundImport, MDDRActivityClass, TestActivityDescription, CellLine class MyConverter(mysql.connector.conversion.MySQLConverter): @@ -75,6 +75,13 @@ class Command(BaseCommand): default=False, help='Flush and migrate compounds', ) + parser.add_argument( + '--test-activity-description', + action='store_true', + dest='test-activity-description', + default=False, + help='Flush and migrate test activity descriptions', + ) parser.add_argument( '--stoponfail', action='store_true', @@ -234,6 +241,35 @@ select distinct protein.NumUniprot, domain.PfamNumAccession , complexe.NbCopy, self.stdout.write(self.style.ERROR('Failed inserting {} {}'.format(row[0], row[1]))) else: self.stdout.write(self.style.SUCCESS('Successfully inserted {} {}'.format(row[0], row[1]))) + 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')) + for row in rows: + try: + tad = TestActivityDescription() + cursor.execute("""select IDSource from biblio where IDBiblio={}""".format(row[2])) + biblio_row = cursor.fetchone() + biblio = Bibliography.objects.get(id_source=biblio_row[0]) + tad.biblio = biblio + Ppi.objects.get(id=ppi_ids_mapping[row[3]]) + tad.test_name = row[4] + tad.test_type = row[7].upper() + tad.test_modulation_type = row[8][0] + tad.nb_active_compounds = row[9] + if row[16] is not None: + tad.cell_line, created = CellLine.objects.get_or_create(name=row[16]) + tad.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']: MDDRCompoundImport.objects.all().delete() MDDRActivityClass.objects.all().delete() diff --git a/ippisite/ippidb/migrations/0024_auto_20170523_2000.py b/ippisite/ippidb/migrations/0024_auto_20170523_2000.py new file mode 100644 index 0000000000000000000000000000000000000000..d107a840d0bc9cda5e69578a73dcba995c0968a0 --- /dev/null +++ b/ippisite/ippidb/migrations/0024_auto_20170523_2000.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.1 on 2017-05-23 20:00 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('ippidb', '0023_auto_20170523_1858'), + ] + + operations = [ + migrations.AlterField( + model_name='testactivitydescription', + name='cell_line', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='ippidb.CellLine'), + ), + ] diff --git a/ippisite/ippidb/models.py b/ippisite/ippidb/models.py index f012c911d8dfe41344a50c71ce54c4f64a04f750..8ca9305e6a428425237ef19233fc9de593d9b02d 100644 --- a/ippisite/ippidb/models.py +++ b/ippisite/ippidb/models.py @@ -314,7 +314,7 @@ class TestActivityDescription(models.Model): test_type = models.CharField('Test type', max_length=5, choices=TEST_TYPES) test_modulation_type = models.CharField('Test modulation type', max_length=1, choices=TEST_MODULATION_TYPES) nb_active_compounds = models.IntegerField('Total number of active compounds') - cell_line = models.ForeignKey(CellLine) + cell_line = models.ForeignKey(CellLine, blank=True, null=True) def get_complexes(self): """