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

migrate TestActivityDescription and CellLine

- CellLine is an optional field in TestActivityDescription
- fixes #12, fixes #27


Former-commit-id: 0d2cf5154164153b3047befd87a46a1b6885b60c
parent 84a8469a
No related branches found
No related tags found
No related merge requests found
0029ba376cb55048b9799efa8aaeccaaf33d350d
\ No newline at end of file
eb310574640f27558fc3118d82ffb14ea7912b79
\ No newline at end of file
......@@ -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()
......
# -*- 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'),
),
]
......@@ -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):
"""
......
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