Skip to content
Snippets Groups Projects
Commit e77216cc authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

migrate TestPKDescription (fix #29)

Former-commit-id: 1acca29b42cdc5370aeb1b0f13eb6a37f82e440f
parent 4a3bb440
No related branches found
No related tags found
No related merge requests found
......@@ -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()
......
# -*- 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'),
),
]
# -*- 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'),
),
]
......@@ -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)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment