Commit a806a4e6 authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

create Protein Domain Complex groups

WIP on #9 and #15
parent a276f77c
Pipeline #29358 failed with stages
in 10 minutes and 53 seconds
# Generated by Django 2.2.1 on 2020-04-28 17:17
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('ippidb', '0053_auto_20200424_1936'),
]
operations = [
migrations.CreateModel(
name='ProteinDomainComplexGroup',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('domain', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='ippidb.Domain')),
('protein', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ippidb.Protein')),
],
options={
'verbose_name_plural': 'protein domain complex groups',
},
),
migrations.CreateModel(
name='ProteinDomainBoundComplexGroup',
fields=[
('proteindomaincomplexgroup_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='ippidb.ProteinDomainComplexGroup')),
],
bases=('ippidb.proteindomaincomplexgroup',),
),
migrations.CreateModel(
name='ProteinDomainPartnerComplexGroup',
fields=[
('proteindomaincomplexgroup_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='ippidb.ProteinDomainComplexGroup')),
],
bases=('ippidb.proteindomaincomplexgroup',),
),
migrations.AddField(
model_name='proteindomaincomplex',
name='group',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='ippidb.ProteinDomainComplexGroup'),
),
]
# Generated by Django 2.2.1 on 2020-04-28 17:17
from django.db import migrations, models
import django.db.models.deletion
from ippidb.tasks import generate_protein_domain_complex_groups
def run_generate_protein_domain_complex_groups(apps, schema_editor):
generate_protein_domain_complex_groups()
class Migration(migrations.Migration):
dependencies = [
('ippidb', '0054_auto_20200428_1717'),
]
operations = [
migrations.RunPython(run_generate_protein_domain_complex_groups,reverse_code=migrations.RunPython.noop),
]
......@@ -330,6 +330,28 @@ class Domain(AutoFillableModel):
return f"{self.pfam_acc} ({self.pfam_id}-{self.pfam_description})"
class ProteinDomainComplexGroup(models.Model):
"""
Protein-Domain association group
"""
protein = models.ForeignKey("Protein", models.CASCADE)
domain = models.ForeignKey("Domain", models.CASCADE, null=True, blank=True)
class Meta:
verbose_name_plural = "protein domain complex groups"
def __str__(self):
return "{} {}-{}".format(
self.protein.short_name,
self.protein.uniprot_id,
self.domain.pfam_id if self.domain else "unknow",
)
def name(self):
return str(self)
class ProteinDomainComplex(models.Model):
"""
Protein-Domain association
......@@ -338,19 +360,33 @@ class ProteinDomainComplex(models.Model):
protein = models.ForeignKey("Protein", models.CASCADE)
domain = models.ForeignKey("Domain", models.CASCADE, null=True, blank=True)
ppc_copy_nb = models.IntegerField("Number of copies of the protein in the complex")
group = models.ForeignKey(
"ProteinDomainComplexGroup", models.SET_NULL, null=True, blank=True
)
class Meta:
verbose_name_plural = "complexes"
def __str__(self):
return "{} {}-{}".format(
self.protein.short_name, self.protein_id, self.domain_id
return "{} {}-{} ({})".format(
self.protein.short_name,
self.protein.uniprot_id,
self.domain.pfam_id if self.domain else "unknow",
self.ppc_copy_nb,
)
def name(self):
return self.protein.short_name
class ProteinDomainBoundComplexGroup(ProteinDomainComplexGroup):
"""
Protein-Domain Bound Complexes group
"""
pass
class ProteinDomainBoundComplex(ProteinDomainComplex):
"""
Protein-Domain association with a "bound complex" role
......@@ -361,6 +397,19 @@ class ProteinDomainBoundComplex(ProteinDomainComplex):
class Meta:
verbose_name_plural = "bound complexes"
def set_group(self):
self.group = ProteinDomainBoundComplexGroup.objects.get_or_create(
protein=self.protein, domain=self.domain
)[0]
class ProteinDomainPartnerComplexGroup(ProteinDomainComplexGroup):
"""
Protein-Domain Bound Complexes group
"""
pass
class ProteinDomainPartnerComplex(ProteinDomainComplex):
"""
......@@ -370,6 +419,11 @@ class ProteinDomainPartnerComplex(ProteinDomainComplex):
class Meta:
verbose_name_plural = "partner complexes"
def set_group(self):
self.group = ProteinDomainPartnerComplexGroup.objects.get_or_create(
protein=self.protein, domain=self.domain
)[0]
class Symmetry(models.Model):
"""
......
......@@ -29,6 +29,10 @@ from .models import (
update_compound_cached_properties,
LeLleBiplotData,
PcaBiplotData,
ProteinDomainBoundComplex,
ProteinDomainBoundComplexGroup,
ProteinDomainPartnerComplex,
ProteinDomainPartnerComplexGroup,
)
from .utils import smi2sdf
from .gx import GalaxyCompoundPropertiesRunner
......@@ -55,7 +59,9 @@ def compute_compound_properties(compound_ids, task=None):
fh.write(sdf_string)
fh.close()
if task is not None:
task.write(f"Galaxy input SDF file for compounds {smiles_dict.keys()}: {fh.name}")
task.write(
f"Galaxy input SDF file for compounds {smiles_dict.keys()}: {fh.name}"
)
# run computations on Galaxy
pc_properties = runner.compute_properties_for_sdf_file(fh.name)
pc_properties_dict = {compound["Name"]: compound for compound in pc_properties}
......@@ -167,6 +173,45 @@ def validate(compound_ids):
for contribution in ca.ppi.contribution_set.filter(validated=False):
contribution.validated = True
contribution.save()
for pdbc in ProteinDomainBoundComplex.objects.filter(
ppicomplex__ppi__contribution=contribution
):
pdbc.set_group()
for pdpc in ProteinDomainPartnerComplex.objects.filter(
ppicomplex__ppi__contribution=contribution
):
pdpc.set_group()
def generate_protein_domain_complex_groups():
"""
Generation Protein Domain Complex groups
for all validated contributions
and pre-contribution PPIs
"""
ProteinDomainBoundComplexGroup.objects.all().delete()
ProteinDomainPartnerComplexGroup.objects.all().delete()
for contribution in Contribution.objects.filter(validated=True):
for pdbc in ProteinDomainBoundComplex.objects.filter(
ppicomplex__ppi__contribution=contribution
):
pdbc.set_group()
pdbc.save()
for pdpc in ProteinDomainPartnerComplex.objects.filter(
ppicomplex__ppi__contribution=contribution
):
pdpc.set_group()
pdpc.save()
for pdbc in ProteinDomainBoundComplex.objects.filter(
ppicomplex__ppi__contribution=None
):
pdbc.set_group()
pdbc.save()
for pdpc in ProteinDomainPartnerComplex.objects.filter(
ppicomplex__ppi__contribution=None
):
pdpc.set_group()
pdpc.save()
def generate_le_lle_plot():
......
......@@ -28,6 +28,8 @@ from ippidb.models import (
MolecularFunction,
TestActivityDescription,
create_tanimoto,
ProteinDomainBoundComplexGroup,
ProteinDomainPartnerComplexGroup,
)
from ippidb.ws import convert_iupac_to_smiles, convert_smiles_to_iupac
......@@ -619,17 +621,17 @@ class CompoundListView(ListView):
on_value="uniprot_id",
),
CompoundListFilterHandler(
ProteinDomainBoundComplex,
"compoundaction__ppi_id__ppicomplex__complex",
"ppicomplex__ppi__compoundaction__compound",
ProteinDomainBoundComplexGroup,
"compoundaction__ppi_id__ppicomplex__complex__group",
"proteindomaincomplex__ppicomplex__ppi__compoundaction__compound",
"boundcomplex",
self.filter_context,
self.request.GET,
),
CompoundListFilterHandler(
ProteinDomainPartnerComplex,
"compoundaction__ppi_id__ppicomplex__complex",
"ppicomplex__ppi__compoundaction__compound",
ProteinDomainPartnerComplexGroup,
"compoundaction__ppi_id__ppicomplex__complex__group",
"proteindomaincomplex__ppicomplex__ppi__compoundaction__compound",
"partnercomplex",
self.filter_context,
self.request.GET,
......
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