Skip to content
Snippets Groups Projects
Commit 3987b15e authored by Hélène  BORGES's avatar Hélène BORGES
Browse files

Merge branch 'master' of gitlab.pasteur.fr:odoppelt/iPPIDB

parents e5dbe1a3 affa17a6
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,14 @@ from django.apps import apps
class BibliographyAdmin(admin.ModelAdmin):
list_display = ('authors_list', 'title', 'journal_name', 'biblio_year', 'id_source')
@admin.register(Protein)
class ProteinAdmin(admin.ModelAdmin):
list_display = ('uniprot_id', 'recommended_name_long')
@admin.register(Taxonomy)
class TaxonomyAdmin(admin.ModelAdmin):
list_display = ('taxonomy_id', 'name')
for model in apps.get_app_config('ippidb').models.values():
try:
admin.site.register(model)
......
from django.core.management import BaseCommand
from django.core.management import BaseCommand, CommandError
import mysql.connector
from ippidb.models import Bibliography, Protein
from ippidb.models import Bibliography, Protein, Taxonomy
class Command(BaseCommand):
......@@ -21,6 +22,14 @@ class Command(BaseCommand):
default=False,
help='Flush and migrate proteins',
)
parser.add_argument(
'--stoponfail',
action='store_true',
dest='stoponfail',
default=False,
help='Stop on fail',
)
def handle(self, *args, **options):
conn = mysql.connector.connect(host="localhost",user="root",password="ippidb", database="ippidb")
......@@ -48,13 +57,20 @@ class Command(BaseCommand):
rows = cursor.fetchall()
Protein.objects.all().delete()
self.stdout.write(self.style.SUCCESS('Successfully flushed protein table'))
Taxonomy.objects.all().delete()
self.stdout.write(self.style.SUCCESS('Successfully flushed taxonomy table'))
for row in rows:
try:
p = Protein()
p.uniprot_id = row[1]
p.save()
except Exception as e:
self.stdout.write(self.style.ERROR('Failed inserting {} {}'.format(row[1], row[2])))
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])))
......@@ -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
from .ws import get_pubmed_info, get_epo_info, get_uniprot_info, get_taxonomy_info
class Bibliography(models.Model):
"""
......@@ -50,8 +50,14 @@ class BibliographyForm(ModelForm):
exclude = ['title','journal_name', 'authors_list', 'biblio_year']
class Taxonomy(models.Model):
taxonomy_id = models.DecimalField('NCBI TaxID', unique=True, max_digits=4, decimal_places=0)
taxonomy_id = models.DecimalField('NCBI TaxID', unique=True, max_digits=9, decimal_places=0)
name = models.CharField('Organism name', max_length=200)
def save(self, *args, **kwargs):
info = get_taxonomy_info(self.taxonomy_id)
self.name = info['scientific_name']
super(Taxonomy, self).save(*args, **kwargs)
class Meta:
verbose_name_plural = "taxonomies"
......@@ -69,9 +75,18 @@ class Protein(models.Model):
molecular_functions = models.ManyToManyField(MolecularFunction)
def save(self, *args, **kwargs):
info = get_epo_info(self.id_source)
info = get_uniprot_info(self.uniprot_id)
self.recommended_name_long = info['recommended_name']
self.organism = info['organism']
self.gene_name = info['gene']
self.entry_name = info['entry_name']
try:
taxonomy = Taxonomy.objects.get(taxonomy_id=info['organism'])
except Taxonomy.DoesNotExist:
tax_info = get_taxonomy_info(info['organism'])
taxonomy = Taxonomy()
taxonomy.taxonomy_id = info['organism']
taxonomy.save()
self.organism = taxonomy
super(Protein, self).save(*args, **kwargs)
class Domain(models.Model):
......@@ -191,6 +206,7 @@ class MDDRCompoundImport(models.Model):
# 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'),)
verbose_name_plural = "MDDR compound imports"
class MDDRCompoundActivityClass(models.Model):
......@@ -199,6 +215,7 @@ class MDDRCompoundActivityClass(models.Model):
class Meta:
unique_together = (('mddr_compound_id', 'activity_class'),)
verbose_name_plural = "MDDR compound activity classes"
class MDDRSimilarity(models.Model):
......@@ -208,6 +225,7 @@ class MDDRSimilarity(models.Model):
class Meta:
unique_together = (('canonical_smile_ippidb', 'canonical_smile_mddr'),)
verbose_name_plural = "MDDR similarities"
"""
class TestActivityDescription(models.Model):
......
......@@ -36,10 +36,20 @@ def get_epo_info(patent_number):
'authors_list': authors}
def get_uniprot_info(uniprot_id):
uniprot_client = Uniprot()
uniprot_client = UniProt()
resp = uniprot_client.retrieve(uniprot_id)
recommended_name = res.root.findall('{http://uniprot.org/uniprot}entry/{http://uniprot.org/uniprot}protein/{http://uniprot.org/uniprot}recommendedName/{http://uniprot.org/uniprot}fullName')[0].text
organism = res.root.findall('{http://uniprot.org/uniprot}entry/{http://uniprot.org/uniprot}organism/{http://uniprot.org/uniprot}dbReference[@type="NCBI Taxonomy"]/@id')
recommended_name = resp.root.findall('{http://uniprot.org/uniprot}entry/{http://uniprot.org/uniprot}protein/{http://uniprot.org/uniprot}recommendedName/{http://uniprot.org/uniprot}fullName')[0].text
organism = resp.root.findall('{http://uniprot.org/uniprot}entry/{http://uniprot.org/uniprot}organism/{http://uniprot.org/uniprot}dbReference[@type="NCBI Taxonomy"]')[0].attrib['id']
gene = resp.root.findall('{http://uniprot.org/uniprot}entry/{http://uniprot.org/uniprot}gene/{http://uniprot.org/uniprot}name[@type="primary"]')[0].text
entry_name = resp.root.findall('{http://uniprot.org/uniprot}entry/{http://uniprot.org/uniprot}name')[0].text
return {'recommended_name': recommended_name,
'organism': organism
}
'organism': int(organism),
'gene': gene,
'entry_name': entry_name
}
def get_taxonomy_info(taxonomy_id):
eu = EUtils()
r = eu.EFetch('taxonomy', taxonomy_id, retmode='dict')
scientific_name = r['TaxaSet']['Taxon']['ScientificName']
return {'scientific_name': scientific_name}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment