diff --git a/.gitignore b/.gitignore index 9f15966..ccf848b 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ __pycache__/ *.pye Sandbox.ipynb +test.ipynb diff --git a/data/10ktp__10X__Visium__Mouse__brain__20200623__v1.1.0/10ktp_make_vitessce.py b/data/10ktp__10X__Visium__Mouse__brain__20200623__v1.1.0/10ktp_make_vitessce.py index 7f21b41..3dd3a13 100644 --- a/data/10ktp__10X__Visium__Mouse__brain__20200623__v1.1.0/10ktp_make_vitessce.py +++ b/data/10ktp__10X__Visium__Mouse__brain__20200623__v1.1.0/10ktp_make_vitessce.py @@ -1,18 +1,8 @@ -# ADJUST -uid = "10ktp" - -# Setup before running this script for the first time -# 1) Ensure you have a lamin.ai account -# 2) Run `lamin login` to authenticate -# 3) Activate lamin db connection with `lamin load scverse/spatialdata-db` -# 4) Execute script once and replace the stem_uid for this file +theislab_uid = "10ktp" import lamindb as ln -ln.settings.transform.stem_uid = "5PYtTxDE7LvE" -ln.settings.transform.version = "1" - -ln.track() +ln.context.track("5PYtTxDE7LvE") from vitessce import ( VitessceConfig, @@ -31,7 +21,7 @@ from lamindb.integrations import save_vitessce_config -artifact = ln.Artifact.filter(ulabels__name=uid).one() +artifact = ln.Artifact.filter(ulabels__name=theislab_uid).one() vc = VitessceConfig( schema_version="1.0.16", @@ -49,4 +39,4 @@ dataset = vc.add_dataset(name='Visium demo').add_object(wrapper) spatial = vc.add_view("spatialBeta", dataset=dataset) vc.layout(spatial) -view = save_vitessce_config(vc, description="Visium HD demo vitessce config") \ No newline at end of file +view = save_vitessce_config(vc, description="Visium HD demo vitessce config") diff --git a/data/10ktp__10X__Visium__Mouse__brain__20200623__v1.1.0/10ktp_to_lamin.py b/data/10ktp__10X__Visium__Mouse__brain__20200623__v1.1.0/10ktp_to_lamin.py index ec141ce..ccf2425 100644 --- a/data/10ktp__10X__Visium__Mouse__brain__20200623__v1.1.0/10ktp_to_lamin.py +++ b/data/10ktp__10X__Visium__Mouse__brain__20200623__v1.1.0/10ktp_to_lamin.py @@ -1,42 +1,31 @@ -# ADJUST -uid = "10ktp" - -# Setup before running this script for the first time -# 1) Ensure you have a lamin.ai account -# 2) Run `lamin login` to authenticate -# 3) Activate lamin db connection with `lamin load scverse/spatialdata-db` -# 4) Execute script once and replace the stem_uid for this file +theislab_uid = "10ktp" import lamindb as ln +from spatialdata_db import load_10x_metadata -ln.settings.transform.stem_uid = "KgGzOw8PUYKO" -ln.settings.transform.version = "3" ln.track("KgGzOw8PUYKO7CpM") + try: - artifact = ln.Artifact.filter(ulabels__name=uid).one() + artifact = ln.Artifact.filter(ulabels__name=theislab_uid).one() artifact.delete(permanent=True) except: pass -### From here on we assume Lamin is set up correctly DATASET_PATH = "/lustre/groups/ml01/projects/2024_spatialdata_db/data/10ktp__10X__Visium__Mouse__brain__20200623__v1.1.0/10ktp__10X__Visium__Mouse__brain__20200623__v1.1.0.zarr" artifact = ln.Artifact(DATASET_PATH, description="10X, Visium, Mouse, Brain") -artifact.save() # transfers to Lamin +artifact.save() # Associate ID with the artifact so we can retrieve afterwards tuid_parent = ln.ULabel.filter(name="theislab unique ID").one() -tuid = ln.ULabel(name=uid).save() +tuid = ln.ULabel(name=theislab_uid).save() tuid.parents.add(tuid_parent) artifact.labels.add(tuid) # load 10X metadata we have on disk -import pandas as pd -from spatialdata_db import load_10x_metadata - all_metadata_10x = load_10x_metadata() -assert len(all_metadata_10x.query(f"uid == '{uid}'")) == 1 -metadata = all_metadata_10x.query(f"uid == '{uid}'").iloc[0] +assert len(all_metadata_10x.query(f"uid == '{theislab_uid}'")) == 1 +metadata = all_metadata_10x.query(f"uid == '{theislab_uid}'").iloc[0] # Associate metadata as features import bionty as bt @@ -45,39 +34,18 @@ organism_lo = bt.Organism.public().lookup() tissue_lo = bt.Tissue.public().lookup() -# Species -- - -if metadata["Species"].lower() == "mouse": - feature_organism = bt.Organism.from_public(name=organism_lo.mouse.name) -elif metadata["Species"].lower() == "human": - feature_organism = bt.Organism.from_public(name=organism_lo.human.name) -else: - raise NotImplementedError("Unknown species!") - -feature_organism.save() - -# Tissue +# Species (Organism) +organisms = bt.Organism.from_values(metadata["Species"].lower(), field="name") +ln.save(organisms) +# Orgna (Tissue) if metadata["organ"].lower() == "olfactory_bulb": metadata["organ"] = "olfactorybulb" - -if metadata["organ"].lower() == "brain": - feature_tissue = bt.Tissue.from_public(name=tissue_lo.brain.name) -elif metadata["organ"].lower() == "kidney": - feature_tissue = bt.Tissue.from_public(name=tissue_lo.kidney.name) -elif metadata["organ"].lower() == "colon": - feature_tissue = bt.Tissue.from_public(name=tissue_lo.colon.name) -else: - raise NotImplementedError("Unknown tissue!") - -feature_tissue.save() +tissues = bt.Tissue.from_values(metadata["organ"].lower(), field="name") +ln.save(tissues) # Associate bionty terms to artifact +artifact.organism.set(organisms) +artifact.tissue.set(tissues) -artifact.labels.add(feature_organism, feature=feature_lo.organism) -artifact.labels.add(feature_tissue, feature=feature_lo.tissue) - - -# finish for tracing in Lamin - -ln.finish() \ No newline at end of file +ln.context.finish() diff --git a/pyproject.toml b/pyproject.toml index ff7bf63..902e7d6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,11 @@ dependencies = [ "anndata", # for debug logging (referenced from the issue template) "session-info", - "lamindb[aws,bionty,jupyter]" + "lamindb[aws,bionty,jupyter]", + "vitessce", + "spatialdata", + "spatialdata-io", + "spatialdata-plot" ] optional-dependencies.dev = [ "pre-commit",