Commit 14d8c81b authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

missing contents for commit 3689e89d

parent 3689e89d
No preview for this file type
......@@ -2,7 +2,7 @@ from django.core.management import BaseCommand, CommandError
import mysql.connector
from ippidb.models import Bibliography, Protein, Taxonomy, MolecularFunction, \
Domain, ProteinDomainBoundComplex, ProteinDomainPartnerComplex, Symmetry, Ppi, PpiComplex
Domain, ProteinDomainBoundComplex, ProteinDomainPartnerComplex, Symmetry, Ppi, PpiComplex, Disease
class Command(BaseCommand):
......@@ -148,25 +148,29 @@ class Command(BaseCommand):
self.stdout.write(self.style.SUCCESS('Successfully inserted {} {}'.format(row[0], row[1])))
if options['ppi']:
sql_request_string = '''
select distinct protein.NumUniprot, domain.PfamNumAccession, complexe.NbCopy, cmpdAction.IDComplexeBound, bindingSiteEvidence.CodePDB, 'part1', ppi.IDPPI from bindingSite inner join ppi on (bindingSite.IDBindingSite=ppi.IDBindingSite1) inner join complexe on (ppi.IDComplexe1=complexe.IDComplexe) left outer join cmpdAction on (complexe.IDComplexe=cmpdAction.IDComplexeBound) inner join protein on (bindingSite.IDProtein=protein.IDProtein) inner join domain on (bindingSite.IDDomain=domain.IDDomain) left outer join bindingSiteEvidence on (ppi.IDPPI=bindingSiteEvidence.IDPPI)
select distinct protein.NumUniprot, domain.PfamNumAccession, complexe.NbCopy, cmpdAction.IDComplexeBound, bindingSiteEvidence.CodePDB, 'part1', ppi.IDPPI, disease.Disease from bindingSite inner join ppi on (bindingSite.IDBindingSite=ppi.IDBindingSite1) inner join complexe on (ppi.IDComplexe1=complexe.IDComplexe) left outer join cmpdAction on (complexe.IDComplexe=cmpdAction.IDComplexeBound) inner join protein on (bindingSite.IDProtein=protein.IDProtein) inner join domain on (bindingSite.IDDomain=domain.IDDomain) inner join disease on (disease.IDPPI=ppi.IDPPI) left outer join bindingSiteEvidence on (ppi.IDPPI=bindingSiteEvidence.IDPPI)
union
select distinct protein.NumUniprot, domain.PfamNumAccession , complexe.NbCopy, cmpdAction.IDComplexeBound, null, 'part2', ppi.IDPPI from bindingSite inner join ppi on (bindingSite.IDBindingSite=ppi.IDBindingSite2) inner join complexe on (ppi.IDComplexe2=complexe.IDComplexe) left outer join cmpdAction on (complexe.IDComplexe=cmpdAction.IDComplexeBound) inner join protein on (bindingSite.IDProtein=protein.IDProtein) inner join domain on (bindingSite.IDDomain=domain.IDDomain)'''
select distinct protein.NumUniprot, domain.PfamNumAccession , complexe.NbCopy, cmpdAction.IDComplexeBound, null, 'part2', ppi.IDPPI, disease.Disease from bindingSite inner join ppi on (bindingSite.IDBindingSite=ppi.IDBindingSite2) inner join complexe on (ppi.IDComplexe2=complexe.IDComplexe) left outer join cmpdAction on (complexe.IDComplexe=cmpdAction.IDComplexeBound) inner join protein on (bindingSite.IDProtein=protein.IDProtein) inner join domain on (bindingSite.IDDomain=domain.IDDomain) inner join disease on (disease.IDPPI=ppi.IDPPI)'''
cursor.execute(sql_request_string)
rows = cursor.fetchall()
ProteinDomainBoundComplex.objects.all().delete()
ProteinDomainPartnerComplex.objects.all().delete()
Disease.objects.all().delete()
Ppi.objects.all().delete()
PpiComplex.objects.all().delete()
self.stdout.write(self.style.SUCCESS('Successfully flushed protein domain complex tables and Ppi'))
self.stdout.write(self.style.SUCCESS('Successfully flushed protein domain complex, PPI, and disease tables'))
ppi_ids_mapping = {}
for row in rows:
try:
# create or retrieve Ppi object
if row[5]=='part1':
ppi = Ppi()
disease, created = Disease.objects.get_or_create(name=row[7])
ppi.pdb_id = row[4]
ppi.symmetry = Symmetry.objects.get(code='AS')
ppi.save()
ppi.diseases.add(disease)
ppi.save()
ppi_ids_mapping[row[6]]=ppi.id
else:
ppi = Ppi.objects.get(id=ppi_ids_mapping[row[6]])
......
......@@ -149,9 +149,17 @@ class Symmetry(models.Model):
def __str__(self):
return '{} ({})'.format(self.code, self.description)
class Disease(models.Model):
name = models.CharField('Disease', max_length=30, unique=True) # is there any database/nomenclature for diseases?
def __str__(self):
return self.name
class Ppi(models.Model):
pdb_id = models.CharField('PDB ID', max_length=4, null=True)
symmetry = models.ForeignKey(Symmetry)
diseases = models.ManyToManyField(Disease)
def __str__(self):
return '{} PPI, PDB:{}'.format(self.symmetry.description, self.pdb_id or 'unknown')
......@@ -169,6 +177,7 @@ class Ppi(models.Model):
#this is the less efficient query ever seen, FIXME
return PpiComplex.objects.filter(ppi=self, complex__in=ProteinDomainBoundComplex.objects.all())
class PpiComplex(models.Model):
ppi = models.ForeignKey(Ppi)
complex = models.ForeignKey(ProteinDomainComplex)
......@@ -180,10 +189,6 @@ class PpiComplex(models.Model):
def __str__(self):
return 'PPI {}, Complex {} ({})'.format(self.ppi, self.complex, self.cc_nb)
class Disease(models.Model):
ppi = models.ForeignKey(Ppi)
disease_name = models.CharField('Disease', max_length=30) # is there any database/nomenclature for diseases?
class Compound(models.Model):
canonical_smile = models.CharField('Canonical Smile', unique=True, max_length=500)
......
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