Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
🔥 Remove Modality
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnyosun committed Nov 13, 2023
1 parent a45dd5e commit 06ef5a3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 100 deletions.
1 change: 0 additions & 1 deletion lnschema_core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
FeatureSet,
File,
HasParents,
Modality,
Registry,
Run,
Storage,
Expand Down
22 changes: 16 additions & 6 deletions lnschema_core/migrations/0022_migrate_to_integer_pks.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@

def create_new_ids(apps, schema_editor):
response = input(
"\nDo you want to migrate your instance to integer primary keys? You will need to re-initialize your instance with `lamin init` after a data export. This is more"
" cumbersome than a regular migration. (y/n)"
"\nDo you want to migrate your instance to integer primary keys? You will need"
" to re-initialize your instance with `lamin init` after a data export. This is"
" more cumbersome than a regular migration. (y/n)"
)
if response != "y":
raise SystemExit
Expand All @@ -45,7 +46,13 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name="dataset",
name="transform",
field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, related_name="output_datasets", to="lnschema_core.transform"),
field=models.ForeignKey(
default=None,
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="output_datasets",
to="lnschema_core.transform",
),
),
]

Expand All @@ -67,7 +74,7 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name=model_name,
name="id",
field=models.BigIntegerField(editable=False, null=True) if big else models.IntegerField(editable=False, null=True),
field=(models.BigIntegerField(editable=False, null=True) if big else models.IntegerField(editable=False, null=True)),
preserve_default=False,
)
)
Expand All @@ -81,7 +88,7 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name=model_name,
name="id",
field=models.BigIntegerField(editable=False, unique=True) if big else models.IntegerField(editable=False, unique=True),
field=(models.BigIntegerField(editable=False, unique=True) if big else models.IntegerField(editable=False, unique=True)),
preserve_default=False,
)
)
Expand Down Expand Up @@ -128,7 +135,10 @@ def populate_tmp_column_foreign_keys(orm):

# populate temporary fields
for model_name in CORE_MODELS.keys():
registry = getattr(lnschema_core.models, model_name)
try:
registry = getattr(lnschema_core.models, model_name)
except AttributeError:
continue
Migration.operations += populate_tmp_column_foreign_keys(registry)


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.1 on 2023-11-13 15:30

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("lnschema_core", "0028_alter_dataset_visibility_alter_file_visibility"),
]

operations = [
migrations.RemoveField(
model_name="feature",
name="modality",
),
migrations.RemoveField(
model_name="featureset",
name="modality",
),
migrations.DeleteModel(
name="Modality",
),
]
93 changes: 0 additions & 93 deletions lnschema_core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,80 +1013,6 @@ def __init__(
pass


class Modality(Registry, HasParents, CanValidate):
"""Measurement types of features.
.. note::
This will soon borrow readout-related records from the experimental factor
ontology, see :class:`~lnschema_bionty.ExperimentalFactor`.
Args:
name: `str` A name.
ontology_id: `Optional[str]` A public ontology ID.
abbr: `Optional[str]` An abbreviation.
description: `Optional[str]` A description.
"""

id = models.AutoField(primary_key=True)
"""Internal id, valid only in one DB instance."""
uid = CharField(unique=True, db_index=True, max_length=8, default=base62_8)
"""Universal id, valid across DB instances."""
name = CharField(max_length=256, db_index=True)
"""Name of the modality (required)."""
ontology_id = CharField(max_length=32, db_index=True, null=True, default=None)
"""Ontology ID of the modality."""
abbr = CharField(max_length=32, db_index=True, unique=True, null=True, default=None)
"""A unique abbreviation for the modality (optional)."""
synonyms = TextField(null=True, default=None)
"""Bar-separated (|) synonyms that correspond to this modality."""
description = TextField(null=True, default=None)
"""Description."""
molecule = TextField(null=True, default=None, db_index=True)
"""Molecular experimental factor, parsed from EFO."""
instrument = TextField(null=True, default=None, db_index=True)
"""Instrument used to measure, parsed from EFO."""
measurement = TextField(null=True, default=None, db_index=True)
"""Phenotypic experimental factor, parsed from EFO."""
parents = models.ManyToManyField("self", symmetrical=False, related_name="children")
"""Parents."""
created_at = models.DateTimeField(auto_now_add=True, db_index=True)
"""Time of creation of record."""
updated_at = models.DateTimeField(auto_now=True, db_index=True)
"""Time of last update to record."""
created_by = models.ForeignKey(
User,
models.PROTECT,
default=current_user_id,
related_name="created_modalities",
)
"""Creator of record, a :class:`~lamindb.User`."""

@overload
def __init__(
self,
name: str,
ontology_id: str,
abbr: Optional[str],
description: Optional[str],
):
...

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

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


class Feature(Registry, CanValidate):
"""Dimensions of measurement.
Expand Down Expand Up @@ -1151,8 +1077,6 @@ class Feature(Registry, CanValidate):
If "category", consider managing categories with :class:`~lamindb.ULabel` or
another Registry for managing labels.
"""
modality = models.ForeignKey(Modality, PROTECT, null=True, default=None, related_name="features")
"""The measurement modality, e.g., "RNA", "Protein", "Gene Module", "pathway" (:class:`~lamindb.Modality`)."""
unit = CharField(max_length=30, db_index=True, null=True, default=None)
"""Unit of measure, ideally SI (`m`, `s`, `kg`, etc.) or 'normalized' etc. (optional)."""
description = TextField(db_index=True, null=True, default=None)
Expand Down Expand Up @@ -1213,8 +1137,6 @@ class FeatureSet(Registry):
Create from values.
:meth:`~lamindb.FeatureSet.from_df`
Create from dataframe columns.
:class:`~lamindb.Modality`
Type of measurement.
Note:
Expand All @@ -1234,7 +1156,6 @@ class FeatureSet(Registry):
type: `Optional[Union[Type, str]] = None` The simple type. Defaults to
`None` if reference Registry is :class:`~lamindb.Feature`, defaults to
`"float"` otherwise.
modality: `Optional[str] = None` A name or id for :class:`~lamindb.Modality`.
name: `Optional[str] = None` A name.
Examples:
Expand Down Expand Up @@ -1267,8 +1188,6 @@ class FeatureSet(Registry):
For :class:`~lamindb.Feature`, types are expected to be in-homogeneous and defined on a per-feature level.
"""
modality = models.ForeignKey(Modality, PROTECT, null=True, default=None, related_name="feature_sets")
"""The measurement modality, e.g., "RNA", "Protein", "Gene Module", "pathway" (:class:`~lamindb.Modality`)."""
registry = CharField(max_length=128, db_index=True)
"""The registry that stores & validated the feature identifiers, e.g., `'core.Feature'` or `'bionty.Gene'`."""
hash = CharField(max_length=20, default=None, db_index=True, null=True)
Expand All @@ -1285,7 +1204,6 @@ def __init__(
self,
features: Iterable[Registry],
type: Optional[Union[Type, str]] = None,
modality: Optional[str] = None,
name: Optional[str] = None,
):
...
Expand All @@ -1311,7 +1229,6 @@ def from_values( # type: ignore
field: FieldAttr = Feature.name,
type: Optional[Union[Type, str]] = None,
name: Optional[str] = None,
modality: Optional[Modality] = None,
**kwargs,
) -> Optional["FeatureSet"]:
"""Create feature set for validated features.
Expand All @@ -1324,7 +1241,6 @@ def from_values( # type: ignore
`None` if reference registry is :class:`~lamindb.Feature`, defaults to
`"float"` otherwise.
name: A name.
modality: A name or id for :class:`~lamindb.Modality`.
**kwargs: Can contain ``organism`` or other context to interpret values.
Examples:
Expand All @@ -1343,7 +1259,6 @@ def from_df(
df: "pd.DataFrame",
field: FieldAttr = Feature.name,
name: Optional[str] = None,
modality: Optional[Modality] = None,
**kwargs,
) -> Optional["FeatureSet"]:
"""Create feature set for validated features."""
Expand Down Expand Up @@ -1571,7 +1486,6 @@ def from_df(
key: Optional[str] = None,
description: Optional[str] = None,
run: Optional[Run] = None,
modality: Optional[Modality] = None,
version: Optional[str] = None,
is_new_version_of: Optional["File"] = None,
**kwargs,
Expand All @@ -1584,7 +1498,6 @@ def from_df(
key: A relative path within default storage,
e.g., `"myfolder/myfile.fcs"`.
description: A description.
modality: The modality of the features.
version: A version string.
is_new_version_of: An old version of the file.
run: The run that creates the file.
Expand Down Expand Up @@ -1620,7 +1533,6 @@ def from_anndata(
key: Optional[str] = None,
description: Optional[str] = None,
run: Optional[Run] = None,
modality: Optional[Modality] = None,
version: Optional[str] = None,
is_new_version_of: Optional["File"] = None,
**kwargs,
Expand All @@ -1633,7 +1545,6 @@ def from_anndata(
key: A relative path within default storage,
e.g., `"myfolder/myfile.fcs"`.
description: A description.
modality: The modality of the features.
version: A version string.
is_new_version_of: An old version of the file.
run: The run that creates the file.
Expand Down Expand Up @@ -2057,7 +1968,6 @@ def from_df(
name: Optional[str] = None,
description: Optional[str] = None,
run: Optional[Run] = None,
modality: Optional[Modality] = None,
reference: Optional[str] = None,
reference_type: Optional[str] = None,
version: Optional[str] = None,
Expand All @@ -2073,7 +1983,6 @@ def from_df(
description: A description.
version: A version string.
is_new_version_of: An old version of the dataset.
modality: The modality of the features.
run: The run that creates the dataset.
See Also:
Expand Down Expand Up @@ -2106,7 +2015,6 @@ def from_anndata(
name: Optional[str] = None,
description: Optional[str] = None,
run: Optional[Run] = None,
modality: Optional[Modality] = None,
reference: Optional[str] = None,
reference_type: Optional[str] = None,
version: Optional[str] = None,
Expand All @@ -2122,7 +2030,6 @@ def from_anndata(
description: A description.
version: A version string.
is_new_version_of: An old version of the dataset.
modality: The modality of the features.
run: The run that creates the dataset.
See Also:
Expand Down

0 comments on commit 06ef5a3

Please sign in to comment.