Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🍱 Create the Biologic registry #86

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
# Generated by Django 5.1.3 on 2024-12-16 21:32

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


class Migration(migrations.Migration):
dependencies = [
("bionty", "0041_squashed"),
("lnschema_core", "0069_squashed"),
("wetlab", "0028_remove_combinationperturbation_compounds_and_more"),
]

operations = [
migrations.CreateModel(
name="ArtifactBiologic",
fields=[
(
"created_at",
lnschema_core.fields.DateTimeField(
auto_now_add=True, db_index=True
),
),
("id", models.BigAutoField(primary_key=True, serialize=False)),
(
"label_ref_is_name",
lnschema_core.fields.BooleanField(
blank=True, default=None, null=True
),
),
(
"feature_ref_is_name",
lnschema_core.fields.BooleanField(
blank=True, default=None, null=True
),
),
(
"artifact",
lnschema_core.fields.ForeignKey(
blank=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="links_biologic",
to="lnschema_core.artifact",
),
),
(
"created_by",
lnschema_core.fields.ForeignKey(
blank=True,
default=lnschema_core.users.current_user_id,
on_delete=django.db.models.deletion.PROTECT,
related_name="+",
to="lnschema_core.user",
),
),
(
"feature",
lnschema_core.fields.ForeignKey(
blank=True,
default=None,
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="links_artifactbiologic",
to="lnschema_core.feature",
),
),
(
"run",
lnschema_core.fields.ForeignKey(
blank=True,
default=lnschema_core.models.current_run,
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="+",
to="lnschema_core.run",
),
),
],
options={
"abstract": False,
},
bases=(lnschema_core.models.LinkORM, models.Model),
),
migrations.CreateModel(
name="Biologic",
fields=[
(
"created_at",
lnschema_core.fields.DateTimeField(
auto_now_add=True, db_index=True
),
),
(
"updated_at",
lnschema_core.fields.DateTimeField(auto_now=True, db_index=True),
),
("id", models.AutoField(primary_key=True, serialize=False)),
(
"uid",
lnschema_core.fields.CharField(
blank=True,
default=lnschema_core.ids.base62_12,
max_length=12,
unique=True,
),
),
(
"name",
lnschema_core.fields.CharField(
blank=True, db_index=True, default=None, max_length=256
),
),
(
"abbr",
lnschema_core.fields.CharField(
blank=True,
db_index=True,
default=None,
max_length=32,
null=True,
unique=True,
),
),
(
"synonyms",
lnschema_core.fields.TextField(blank=True, default=None, null=True),
),
(
"description",
lnschema_core.fields.TextField(blank=True, default=None, null=True),
),
(
"_previous_runs",
models.ManyToManyField(related_name="+", to="lnschema_core.run"),
),
(
"artifacts",
models.ManyToManyField(
related_name="biologics",
through="wetlab.ArtifactBiologic",
to="lnschema_core.artifact",
),
),
(
"created_by",
lnschema_core.fields.ForeignKey(
blank=True,
default=lnschema_core.users.current_user_id,
on_delete=django.db.models.deletion.PROTECT,
related_name="+",
to="lnschema_core.user",
),
),
(
"proteins",
models.ManyToManyField(
related_name="biologics", to="bionty.protein"
),
),
(
"run",
lnschema_core.fields.ForeignKey(
blank=True,
default=lnschema_core.models.current_run,
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="+",
to="lnschema_core.run",
),
),
],
options={
"abstract": False,
},
bases=(lnschema_core.models.CanCurate, models.Model),
),
migrations.AddField(
model_name="artifactbiologic",
name="biologic",
field=lnschema_core.fields.ForeignKey(
blank=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="links_artifact",
to="wetlab.biologic",
),
),
]
78 changes: 78 additions & 0 deletions wetlab/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,84 @@
# return ""


class Biologic(CanCurate, TracksRun, TracksUpdates):
"""Proteins, peptides, antibodies, enzymes, growth factors, viral infections.

- Proteins
- Peptides
- Antibodies
- Enzymes
- Growth factors
- Viral infections (they're biological agents causing direct perturbation, different from viral vector which belongs to genetic perturbagen)

Examples:
>>> biologic = wl.Biologic(
... name="IFNG",
... ).save()
"""

class Meta(BioRecord.Meta, TracksRun.Meta, TracksUpdates.Meta):
abstract = False

_name_field: str = "name"

id: int = models.AutoField(primary_key=True)
"""Internal id, valid only in one DB instance."""
uid: str = CharField(unique=True, max_length=12, default=ids.base62_12)
"""A universal id (hash of selected field)."""
name: str = CharField(max_length=256, db_index=True)
"""Name of the compound."""
abbr: str | None = CharField(
max_length=32, db_index=True, unique=True, null=True, default=None
)
"""A unique abbreviation."""
synonyms: str | None = TextField(null=True, default=None)
"""Bar-separated (|) synonyms that correspond to this compound."""
description: str | None = TextField(null=True, default=None)
"""Description of the compound."""
proteins: Protein = models.ManyToManyField(
"bionty.Protein", related_name="biologics"
)
"""Proteins associated with this biologic."""
artifacts: Artifact = models.ManyToManyField(
Artifact, through="ArtifactBiologic", related_name="biologics"
)
"""Artifacts linked to the compound."""

@overload
def __init__(
self,
name: str,
abbr: str | None,
synonyms: str | None,
description: str | None,
): ...

@overload
def __init__(
self,
*db_args,
): ...

def __init__(
self,
*args,
**kwargs,
):
super().__init__(*args, **kwargs)


class ArtifactBiologic(Record, LinkORM, TracksRun):
id: int = models.BigAutoField(primary_key=True)
artifact: Artifact = ForeignKey(Artifact, CASCADE, related_name="links_biologic")
biologic: Biologic = ForeignKey(Biologic, PROTECT, related_name="links_artifact")
feature: Feature = ForeignKey(
Feature, PROTECT, null=True, default=None, related_name="links_artifactbiologic"
)
label_ref_is_name: bool | None = BooleanField(null=True, default=None)
feature_ref_is_name: bool | None = BooleanField(null=True, default=None)


class Compound(BioRecord, TracksRun, TracksUpdates):
"""Models a (chemical) compound such as a drug.

Expand Down
Loading