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

denormalize ppi name to improve compound query performance

Former-commit-id: efe273eac847d110d0b8791fa2eb89191d212ffa
parent 77ebf4d0
No related branches found
No related tags found
No related merge requests found
a95c9b99cc69a1cae8a8fa13dfa234ef88d45f4e 487393aa0af165ca4ce78c99486b57039379f535
\ No newline at end of file \ No newline at end of file
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2018-07-29 10:13
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ippidb', '0008_auto_20180727_0845'),
]
operations = [
migrations.AddField(
model_name='ppi',
name='name',
field=models.TextField(blank=True, null=True, verbose_name='PPI name'),
),
]
...@@ -211,22 +211,21 @@ class PpiFamily(models.Model): ...@@ -211,22 +211,21 @@ class PpiFamily(models.Model):
return self.name return self.name
class Ppi(models.Model): class Ppi(AutoFillableModel):
pdb_id = models.CharField('PDB ID', max_length=4, null=True, blank=True) pdb_id = models.CharField('PDB ID', max_length=4, null=True, blank=True)
pockets_nb = models.IntegerField( pockets_nb = models.IntegerField(
'Total number of pockets in the complex', default=1) 'Total number of pockets in the complex', default=1)
symmetry = models.ForeignKey(Symmetry, models.CASCADE) symmetry = models.ForeignKey(Symmetry, models.CASCADE)
diseases = models.ManyToManyField(Disease) diseases = models.ManyToManyField(Disease)
family = models.ForeignKey(PpiFamily, models.CASCADE, null=True, blank=True) family = models.ForeignKey(PpiFamily, models.CASCADE, null=True, blank=True)
name = models.TextField('PPI name', null=True, blank=True)
def __str__(self): def __str__(self):
return '{} PPI, PDB:{}'.format(self.symmetry.description, self.pdb_id or 'unknown') return '{} PPI, PDB:{}'.format(self.symmetry.description, self.pdb_id or 'unknown')
def get_ppi_complexes(self): def autofill(self):
""" # name is denormalized and stored in the database to reduce SQL queries in query mode
return all ppi complexes belonging to this ppi self.name = self.compute_name_from_protein_names()
"""
return PpiComplex.objects.filter(ppi=self)
def get_ppi_bound_complexes(self): def get_ppi_bound_complexes(self):
""" """
...@@ -235,10 +234,9 @@ class Ppi(models.Model): ...@@ -235,10 +234,9 @@ class Ppi(models.Model):
# this is the less efficient query ever seen, FIXME # this is the less efficient query ever seen, FIXME
return PpiComplex.objects.filter(ppi=self, complex__in=ProteinDomainBoundComplex.objects.all()) return PpiComplex.objects.filter(ppi=self, complex__in=ProteinDomainBoundComplex.objects.all())
@property def compute_name_from_protein_names(self):
def name(self):
all_protein_names = set( all_protein_names = set(
[ppi_complex.complex.protein.short_name for ppi_complex in self.get_ppi_complexes()]) [ppi_complex.complex.protein.short_name for ppi_complex in self.ppicomplex_set.all()])
bound_protein_names = set( bound_protein_names = set(
[ppi_complex.complex.protein.short_name for ppi_complex in self.get_ppi_bound_complexes()]) [ppi_complex.complex.protein.short_name for ppi_complex in self.get_ppi_bound_complexes()])
partner_protein_names = all_protein_names - bound_protein_names partner_protein_names = all_protein_names - bound_protein_names
...@@ -614,7 +612,7 @@ class TestActivityDescription(models.Model): ...@@ -614,7 +612,7 @@ class TestActivityDescription(models.Model):
depends on the modulation type depends on the modulation type
""" """
if self.test_modulation_type == 'I': if self.test_modulation_type == 'I':
return self.ppi.get_ppi_complexes() return self.ppi.ppicomplex_set.all()
else: else:
return self.ppi.get_ppi_bound_complexes() return self.ppi.get_ppi_bound_complexes()
......
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