Skip to content

Commit

Permalink
🎨 Fix model relationships (#83)
Browse files Browse the repository at this point in the history
* 🎨 Fix model relationships

* πŸ’š Fix migration

* πŸ’š Fix migration

* πŸ’š Fix guide
  • Loading branch information
sunnyosun authored Dec 12, 2024
1 parent 37e2192 commit a4113bd
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 12 deletions.
10 changes: 5 additions & 5 deletions docs/guide/modeling_perturbations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@
"combination_perturbation = wl.CombinationPerturbation(\n",
" name=\"gefitinib and EGFR/KRAS knockdown combination perturbation subject to smoking\"\n",
").save()\n",
"combination_perturbation.genetics.set([EGFR_kd, KRAS_kd])\n",
"combination_perturbation.compounds.add(gefitinib)\n",
"combination_perturbation.environmentals.add(smoking)"
"combination_perturbation.genetic_perturbations.set([EGFR_kd, KRAS_kd])\n",
"combination_perturbation.compound_perturbations.add(gefitinib)\n",
"combination_perturbation.environmental_perturbations.add(smoking)"
]
},
{
Expand All @@ -259,7 +259,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "lamindb",
"display_name": "py310",
"language": "python",
"name": "python3"
},
Expand All @@ -273,7 +273,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
"version": "3.10.13"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Generated by Django 5.2 on 2024-12-12 16:23

import django.db.models.deletion
import lnschema_core.fields
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("wetlab", "0027_rename_treatment_add_donor"),
]

operations = [
migrations.RemoveField(
model_name="compoundperturbation",
name="compounds",
),
migrations.AddField(
model_name="compoundperturbation",
name="compound",
field=lnschema_core.fields.ForeignKey(
blank=True,
default=None,
null=True,
on_delete=django.db.models.deletion.PROTECT,
to="wetlab.compound",
),
),
migrations.RenameField(
model_name="combinationperturbation",
old_name="environmentals",
new_name="environmental_perturbations",
),
migrations.AlterField(
model_name="combinationperturbation",
name="environmental_perturbations",
field=models.ManyToManyField(
related_name="combination_perturbations",
to="wetlab.environmentalperturbation",
),
),
migrations.RenameField(
model_name="combinationperturbation",
old_name="genetics",
new_name="genetic_perturbations",
),
migrations.AlterField(
model_name="combinationperturbation",
name="genetic_perturbations",
field=models.ManyToManyField(
related_name="combination_perturbations",
to="wetlab.geneticperturbation",
),
),
migrations.RenameField(
model_name="combinationperturbation",
old_name="compounds",
new_name="compound_perturbations",
),
migrations.AlterField(
model_name="combinationperturbation",
name="compound_perturbations",
field=models.ManyToManyField(
related_name="combination_perturbations",
to="wetlab.compoundperturbation",
),
),
migrations.AddField(
model_name="compoundperturbation",
name="description",
field=lnschema_core.fields.TextField(blank=True, default=None, null=True),
),
migrations.AddField(
model_name="environmentalperturbation",
name="description",
field=lnschema_core.fields.TextField(blank=True, default=None, null=True),
),
migrations.AddField(
model_name="geneticperturbation",
name="description",
field=lnschema_core.fields.TextField(blank=True, default=None, null=True),
),
]
20 changes: 13 additions & 7 deletions wetlab/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ class Meta(Record.Meta, TracksRun.Meta, TracksUpdates.Meta):
db_index=True,
)
""":class:`~wetlab.GeneticPerturbationSystem` used for the genetic perturbation."""
description: str | None = TextField(null=True, default=None)
"""Description of the genetic perturbation."""
sequence: str | None = models.TextField(null=True, default=None, db_index=True)
"""Sequence of the perturbation."""
on_target_score: float | None = FloatField(
Expand Down Expand Up @@ -408,6 +410,8 @@ class Meta(Record.Meta, TracksRun.Meta, TracksUpdates.Meta):
"""Universal id, valid across DB instances."""
name: str = CharField(max_length=255, default=None, db_index=True)
"""Name of the compound perturbation."""
description: str | None = TextField(null=True, default=None)
"""Description of the compound perturbation."""
concentration: float = FloatField(null=True, default=None, blank=True)
"""Concentration of the compound."""
concentration_unit: str = CharField(max_length=32, null=True, default=None)
Expand All @@ -418,7 +422,7 @@ class Meta(Record.Meta, TracksRun.Meta, TracksUpdates.Meta):
PerturbationTarget, related_name="compound_targets"
)
"""Targets of the perturbation."""
compounds: Compound = models.ManyToManyField(Compound, related_name="compounds")
compound: Compound | None = ForeignKey("Compound", PROTECT, null=True, default=None)
"""Compounds linked to the perturbation."""
artifacts: Artifact = models.ManyToManyField(
Artifact,
Expand Down Expand Up @@ -484,6 +488,8 @@ class Meta(Record.Meta, TracksRun.Meta, TracksUpdates.Meta):
"""Name of the environmental perturbation."""
ontology_id = CharField(max_length=32, db_index=True, null=True, default=None)
"""Ontology ID (EFO) of the environmental perturbation."""
description: str | None = TextField(null=True, default=None)
"""Description of the environmental perturbation."""
value: float | None = FloatField(null=True, default=None, blank=True)
"""The value of the environmental perturbation such as a temperature."""
unit: str | None = CharField(max_length=32, null=True, default=None)
Expand Down Expand Up @@ -579,16 +585,16 @@ class Meta(Record.Meta, TracksRun.Meta, TracksUpdates.Meta):
max_length=32, db_index=True, null=True, default=None
)
"""Ontology ID of the perturbation."""
genetics: GeneticPerturbation = models.ManyToManyField(
GeneticPerturbation, related_name="genetic_perturbations"
genetic_perturbations: GeneticPerturbation = models.ManyToManyField(
GeneticPerturbation, related_name="combination_perturbations"
)
""":class:`wetlab.GeneticPerturbation` perturbations."""
compounds: CompoundPerturbation = models.ManyToManyField(
CompoundPerturbation, related_name="compound_perturbations"
compound_perturbations: CompoundPerturbation = models.ManyToManyField(
CompoundPerturbation, related_name="combination_perturbations"
)
""":class:`wetlab.CompoundPerturbation` perturbations."""
environmentals: EnvironmentalPerturbation = models.ManyToManyField(
EnvironmentalPerturbation, related_name="environmental_perturbations"
environmental_perturbations: EnvironmentalPerturbation = models.ManyToManyField(
EnvironmentalPerturbation, related_name="combination_perturbations"
)
""":class:`wetlab.EnvironmentalPerturbation` perturbations."""
artifacts: Artifact = models.ManyToManyField(
Expand Down

0 comments on commit a4113bd

Please sign in to comment.