diff --git a/ippisite/ippidb/management/commands/import_v1_data.py b/ippisite/ippidb/management/commands/import_v1_data.py index c14585e2f37096a0fdb676baa204aa38fffd7062..42c45eb73b2de83feda8777e049bd0aa1cbf0246 100644 --- a/ippisite/ippidb/management/commands/import_v1_data.py +++ b/ippisite/ippidb/management/commands/import_v1_data.py @@ -7,7 +7,7 @@ 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 + CompoundAction, TestCytotoxDescription, TestPKDescription class MyConverter(mysql.connector.conversion.MySQLConverter): @@ -61,7 +61,7 @@ class Command(BaseCommand): action='store_true', dest='ppi', default=False, - help='Flush and migrate ppis and complexes', + help='Flush and migrate ppis, complexes, and tests', ) parser.add_argument( '--mddr', @@ -84,13 +84,6 @@ class Command(BaseCommand): default=False, help='Flush and migrate compounds-bibliography', ) - 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', @@ -392,6 +385,47 @@ select distinct protein.NumUniprot, domain.PfamNumAccession , complexe.NbCopy, else: self.stdout.write( self.style.SUCCESS('Successfully inserted {}'.format(row[2]))) + cursor.execute("""SELECT * FROM testPKDescription""") + rows = cursor.fetchall() + TestPKDescription.objects.all().delete() + self.stdout.write( + self.style.SUCCESS('Successfully flushed test PK descriptions table')) + for row in rows: + try: + tpd = TestPKDescription() + cursor.execute( + """select IDSource from biblio where IDBiblio={}""".format(row[1])) + biblio_row = cursor.fetchone() + biblio = Bibliography.objects.get(id_source=biblio_row[0]) + tpd.biblio = biblio + tpd.test_name = row[2] + #tcd.compound_concentration = row[4] + try: + taxonomy = Taxonomy.objects.get(taxonomy_id=10090) + except Taxonomy.DoesNotExist: + taxonomy = Taxonomy() + taxonomy.taxonomy_id = 10090 + # dirty hack: all organisms in this table are "mice", + # hence assuming Mus musculus + taxonomy.save(autofill=True) + tpd.organism = taxonomy + tpd.administration_mode = row[4] + tpd.concentration = row[5] + tpd.dose = round(row[6], 4) + tpd.dose_interval = row[7] + tpd.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() diff --git a/ippisite/ippidb/migrations/0029_auto_20180308_1935.py b/ippisite/ippidb/migrations/0029_auto_20180308_1935.py new file mode 100644 index 0000000000000000000000000000000000000000..7e2c9f63d1ea437868a3ba0fcfc0f9dd447772c2 --- /dev/null +++ b/ippisite/ippidb/migrations/0029_auto_20180308_1935.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2018-03-08 19:35 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ippidb', '0028_auto_20180307_1405'), + ] + + operations = [ + migrations.AlterField( + model_name='testpkdescription', + name='dose', + field=models.DecimalField(blank=True, decimal_places=4, max_digits=9, null=True, verbose_name='Dose in mg/kg'), + ), + ] diff --git a/ippisite/ippidb/migrations/0030_testpkdescription_concentration.py b/ippisite/ippidb/migrations/0030_testpkdescription_concentration.py new file mode 100644 index 0000000000000000000000000000000000000000..3522e6e9a652babd407d09456834ed536a57e330 --- /dev/null +++ b/ippisite/ippidb/migrations/0030_testpkdescription_concentration.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2018-03-08 19:45 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ippidb', '0029_auto_20180308_1935'), + ] + + operations = [ + migrations.AddField( + model_name='testpkdescription', + name='concentration', + field=models.DecimalField(blank=True, decimal_places=3, max_digits=7, null=True, verbose_name='Concentration in mg/l'), + ), + ] diff --git a/ippisite/ippidb/models.py b/ippisite/ippidb/models.py index 55e9612ffd1e4930d6fadaf1cfa5fb187c46a721..f9d77052c58549d6f55463ca89dc38fab2cb5e51 100644 --- a/ippisite/ippidb/models.py +++ b/ippisite/ippidb/models.py @@ -514,8 +514,10 @@ class TestPKDescription(models.Model): organism = models.ForeignKey(Taxonomy, models.CASCADE) administration_mode = models.CharField( 'Administration mode', max_length=2, choices=ADMINISTRATION_MODES, blank=True, null=True) + concentration = models.DecimalField( + 'Concentration in mg/l', max_digits=7, decimal_places=3, blank=True, null=True) dose = models.DecimalField( - 'Dose in mg/kg', max_digits=7, decimal_places=4, blank=True, null=True) + 'Dose in mg/kg', max_digits=9, decimal_places=4, blank=True, null=True) dose_interval = models.IntegerField( 'Dose interval, in hours', blank=True, null=True)