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

migrate compound-bibliography data

Former-commit-id: b315278b18e80d3ccb5947e6bb6ad27f96c7a241
parent dafb5340
No related branches found
No related tags found
No related merge requests found
...@@ -3,11 +3,10 @@ import glob ...@@ -3,11 +3,10 @@ import glob
from django.utils import timezone from django.utils import timezone
from django.core.management import BaseCommand, CommandError from django.core.management import BaseCommand, CommandError
import mysql.connector import mysql.connector
from pybel import readfile
from ippidb.models import Bibliography, Protein, Taxonomy, MolecularFunction, \ from ippidb.models import Bibliography, Protein, Taxonomy, MolecularFunction, \
Domain, ProteinDomainBoundComplex, ProteinDomainPartnerComplex, Symmetry, Ppi, PpiComplex, Disease, \ Domain, ProteinDomainBoundComplex, ProteinDomainPartnerComplex, Symmetry, Ppi, PpiComplex, Disease, \
Compound, MDDRCompoundImport, MDDRActivityClass, TestActivityDescription, CellLine Compound, MDDRCompoundImport, MDDRActivityClass, TestActivityDescription, CellLine, RefCompoundBiblio
class MyConverter(mysql.connector.conversion.MySQLConverter): class MyConverter(mysql.connector.conversion.MySQLConverter):
...@@ -77,6 +76,13 @@ class Command(BaseCommand): ...@@ -77,6 +76,13 @@ class Command(BaseCommand):
default=False, default=False,
help='Flush and migrate compounds', help='Flush and migrate compounds',
) )
parser.add_argument(
'--compound-biblio',
action='store_true',
dest='compoundbiblio',
default=False,
help='Flush and migrate compounds-bibliography',
)
parser.add_argument( parser.add_argument(
'--test-activity-description', '--test-activity-description',
action='store_true', action='store_true',
...@@ -301,6 +307,7 @@ select distinct protein.NumUniprot, domain.PfamNumAccession , complexe.NbCopy, ...@@ -301,6 +307,7 @@ select distinct protein.NumUniprot, domain.PfamNumAccession , complexe.NbCopy,
self.stdout.write( self.stdout.write(
self.style.SUCCESS('Successfully inserted {}'.format(row[2]))) self.style.SUCCESS('Successfully inserted {}'.format(row[2])))
if options['mddr']: if options['mddr']:
from pybel import readfile
MDDRCompoundImport.objects.all().delete() MDDRCompoundImport.objects.all().delete()
MDDRActivityClass.objects.all().delete() MDDRActivityClass.objects.all().delete()
self.stdout.write( self.stdout.write(
...@@ -409,3 +416,30 @@ select distinct protein.NumUniprot, domain.PfamNumAccession , complexe.NbCopy, ...@@ -409,3 +416,30 @@ select distinct protein.NumUniprot, domain.PfamNumAccession , complexe.NbCopy,
else: else:
self.stdout.write( self.stdout.write(
self.style.SUCCESS('Successfully inserted {} {}'.format(row[1], row[2]))) self.style.SUCCESS('Successfully inserted {} {}'.format(row[1], row[2])))
if options['compoundbiblio']:
cursor.execute("""select r.CmpdNameInBiblio, c.CanonicalSmile, b.IDSource from refCmpdBiblio as r inner join compound as c on r.IDCompound=c.IDCompound inner join biblio as b on r.IDBiblio=b.IDBiblio;""")
rows = cursor.fetchall()
RefCompoundBiblio.objects.all().delete()
self.stdout.write(
self.style.SUCCESS('Successfully flushed compound-biblio table'))
for row in rows:
try:
c = Compound.objects.get(canonical_smile=row[1])
b = Bibliography.objects.get(id_source=row[2])
r = RefCompoundBiblio()
r.compound_id = c.id
r.bibliography_id = b.id
r.compound_name = row[0]
r.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])))
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