Skip to content
Snippets Groups Projects
Commit bd2274af authored by Olivia Doppelt-Azeroual's avatar Olivia Doppelt-Azeroual
Browse files
parents 3da94f3c bb36e427
No related branches found
No related tags found
No related merge requests found
......@@ -32,6 +32,14 @@ class ProteinDomainPartnerComplexAdmin(admin.ModelAdmin):
class Symmetry(admin.ModelAdmin):
list_display = ('code', 'description')
@admin.register(MDDRCompoundImport)
class MDDRCompoundImport(admin.ModelAdmin):
list_display = ('mddr_name', 'dvpmt_phase', 'canonical_smile')
@admin.register(Compound)
class Compound(admin.ModelAdmin):
list_display = ('iupac_name', 'common_name', 'canonical_smile')
for model in apps.get_app_config('ippidb').models.values():
try:
admin.site.register(model)
......
import glob
from django.utils import timezone
from django.core.management import BaseCommand, CommandError
import mysql.connector
from pybel import readfile
from ippidb.models import Bibliography, Protein, Taxonomy, MolecularFunction, \
Domain, ProteinDomainBoundComplex, ProteinDomainPartnerComplex, Symmetry, Ppi, PpiComplex, Disease, \
Compound
Compound, MDDRCompoundImport, MDDRActivityClass
class Command(BaseCommand):
......@@ -45,6 +49,13 @@ class Command(BaseCommand):
default=False,
help='Flush and migrate ppis and complexes',
)
parser.add_argument(
'--mddr',
action='store_true',
dest='mddr',
default=False,
help='Flush and import MDDR database',
)
parser.add_argument(
'--compound',
action='store_true',
......@@ -211,6 +222,32 @@ 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])))
if options['mddr']:
MDDRCompoundImport.objects.all().delete()
MDDRActivityClass.objects.all().delete()
self.stdout.write(self.style.SUCCESS('Successfully flushed MDDR Compound and Activity class tables'))
for sdf_file in glob.glob('/home/hmenager/iPPIDB/mddr20151_2d.sdf/*.sdf'):
for item in readfile("sdf", sdf_file):
try:
m = MDDRCompoundImport()
m.mddr_name = item.data['MOLNAME']
m.canonical_smile = str(item)
m.dvpmt_phase = item.data['PHASE']
m.db_import_date = timezone.now()
m.save()
for activity_class_name in item.data['ACTIV_CLASS'].split(','):
activity_class, created = MDDRActivityClass.objects.get_or_create(name=activity_class_name)
m.activity_classes.add(activity_class)
m.save()
except Exception as e:
if options['stoponfail']:
import traceback
self.stderr.write(traceback.format_exc())
raise CommandError('Failed inserting {}'.format(str(item)))
else:
self.stdout.write(self.style.ERROR('Failed inserting {}'.format(str(item))))
else:
self.stdout.write(self.style.SUCCESS('Successfully inserted {} {}'.format(item.data['MOLNAME'], str(item))))
if options['compound']:
cursor.execute("""SELECT * FROM compound""")
rows = cursor.fetchall()
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.1 on 2017-05-22 19:31
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ippidb', '0018_auto_20170522_1501'),
]
operations = [
migrations.AlterField(
model_name='mddrcompoundimport',
name='db_import_date',
field=models.DateTimeField(verbose_name='MDDR release year/month'),
),
migrations.AlterUniqueTogether(
name='mddrcompoundimport',
unique_together=set([('mddr_name', 'dvpmt_phase', 'canonical_smile')]),
),
migrations.RemoveField(
model_name='mddrcompoundimport',
name='mddr_compound_id',
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.1 on 2017-05-22 19:45
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('ippidb', '0019_auto_20170522_1931'),
]
operations = [
migrations.RenameField(
model_name='mddractivityclass',
old_name='activity_class',
new_name='name',
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.1 on 2017-05-22 19:49
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ippidb', '0020_auto_20170522_1945'),
]
operations = [
migrations.AlterField(
model_name='mddrcompoundimport',
name='canonical_smile',
field=models.CharField(blank=True, max_length=500, null=True, verbose_name='Canonical Smile'),
),
]
......@@ -244,27 +244,26 @@ class Compound(models.Model):
class MDDRActivityClass(models.Model):
activity_class = models.CharField('Activity Class', max_length=100, unique=True)
name = models.CharField('Activity Class', max_length=100, unique=True)
class Meta:
verbose_name_plural = "MDDR activity classes"
def __str__(self):
return self.activity_class
return self.name
class MDDRCompoundImport(models.Model):
mddr_compound_id = models.IntegerField('MDDR compound ID')
mddr_name = models.CharField('MDDR name', max_length=40)
dvpmt_phase = models.CharField('Development phase', max_length=20)
canonical_smile = models.CharField('Canonical Smile', max_length=500, unique=True, blank=True, null=True)
canonical_smile = models.CharField('Canonical Smile', max_length=500, blank=True, null=True)
#TODO index this table on canonical_smile
db_import_date = models.DecimalField('MDDR release year/month', max_digits=6, decimal_places=0)
db_import_date = models.DateTimeField('MDDR release year/month')
activity_classes = models.ManyToManyField(MDDRActivityClass)
class Meta:
# over multiple releases of the MDDR database, the same compound can evolve in its development phase
# the same compound can have different names and development phases in the same MDDR release
unique_together = (('mddr_compound_id', 'mddr_name', 'dvpmt_phase'),)
unique_together = (('mddr_name', 'dvpmt_phase', 'canonical_smile'),)
verbose_name_plural = "MDDR compound imports"
class MDDRSimilarity(models.Model):
......
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