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 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 = [
field=models.TextField(blank=True, null=True, verbose_name='PPI name'),
......@@ -211,22 +211,21 @@ class PpiFamily(models.Model):
class Ppi(models.Model):
class Ppi(AutoFillableModel):
pdb_id = models.CharField('PDB ID', max_length=4, null=True, blank=True)
pockets_nb = models.IntegerField(
'Total number of pockets in the complex', default=1)
symmetry = models.ForeignKey(Symmetry, models.CASCADE)
diseases = models.ManyToManyField(Disease)
family = models.ForeignKey(PpiFamily, models.CASCADE, null=True, blank=True)
name = models.TextField('PPI name', null=True, blank=True)
def __str__(self):
return '{} PPI, PDB:{}'.format(self.symmetry.description, self.pdb_id or 'unknown')
def get_ppi_complexes(self):
return all ppi complexes belonging to this ppi
return PpiComplex.objects.filter(ppi=self)
def autofill(self):
# name is denormalized and stored in the database to reduce SQL queries in query mode = self.compute_name_from_protein_names()
def get_ppi_bound_complexes(self):
......@@ -235,10 +234,9 @@ class Ppi(models.Model):
# this is the less efficient query ever seen, FIXME
return PpiComplex.objects.filter(ppi=self, complex__in=ProteinDomainBoundComplex.objects.all())
def name(self):
def compute_name_from_protein_names(self):
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(
[ppi_complex.complex.protein.short_name for ppi_complex in self.get_ppi_bound_complexes()])
partner_protein_names = all_protein_names - bound_protein_names
......@@ -614,7 +612,7 @@ class TestActivityDescription(models.Model):
depends on the modulation type
if self.test_modulation_type == 'I':
return self.ppi.get_ppi_complexes()
return self.ppi.ppicomplex_set.all()
return self.ppi.get_ppi_bound_complexes()
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