Commit a0f5ef19 authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

Domain corrections and migration

correct Domain model, use PFAM service, add migration command
and update database.
parent f9dede09
No preview for this file type
from django.core.management import BaseCommand, CommandError
import mysql.connector
from ippidb.models import Bibliography, Protein, Taxonomy, MolecularFunction
from ippidb.models import Bibliography, Protein, Taxonomy, MolecularFunction, Domain
class Command(BaseCommand):
......@@ -22,6 +22,13 @@ class Command(BaseCommand):
default=False,
help='Flush and migrate proteins',
)
parser.add_argument(
'--domains',
action='store_true',
dest='domains',
default=False,
help='Flush and migrate domains',
)
parser.add_argument(
'--stoponfail',
action='store_true',
......@@ -75,4 +82,24 @@ class Command(BaseCommand):
self.stdout.write(self.style.ERROR('Failed inserting {} {}'.format(row[1], row[2])))
else:
self.stdout.write(self.style.SUCCESS('Successfully inserted {} {}'.format(row[1], row[2])))
if options['domains']:
cursor.execute("""SELECT * FROM domain""")
rows = cursor.fetchall()
Domain.objects.all().delete()
self.stdout.write(self.style.SUCCESS('Successfully flushed domain table'))
for row in rows:
try:
p = Domain()
p.pfam_acc = row[2]
p.domain_family = row[4]
p.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[1], row[2])))
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-03-28 20:45
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('ippidb', '0006_auto_20170327_1439'),
]
operations = [
migrations.RenameField(
model_name='domain',
old_name='domainfamily',
new_name='domain_family',
),
]
......@@ -3,7 +3,7 @@ from __future__ import unicode_literals
from django.db import models
from django.forms import ModelForm
from .ws import get_pubmed_info, get_epo_info, get_uniprot_info, get_taxonomy_info, get_go_info
from .ws import get_pubmed_info, get_epo_info, get_uniprot_info, get_taxonomy_info, get_go_info, get_pfam_info
class Bibliography(models.Model):
"""
......@@ -111,7 +111,13 @@ class Domain(models.Model):
pfam_acc = models.CharField('Pfam Accession', max_length=10, unique=True)
pfam_id = models.CharField('Pfam Family Identifier', max_length=20)
pfam_description = models.CharField('Pfam Description', max_length=100)
domainfamily = models.CharField('Domain family', max_length=25) #TODO: what is this field? check database contents
domain_family = models.CharField('Domain family', max_length=25) #TODO: what is this field? check database contents
def save(self, *args, **kwargs):
info = get_pfam_info(self.pfam_acc)
self.pfam_id = info['id']
self.pfam_description = info['description']
super(Domain, self).save(*args, **kwargs)
class ProteinDomainComplex(models.Model):
protein_id = models.ForeignKey('Protein')
......
Supports Markdown
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