Skip to content

Commit

Permalink
Simplify 10ktp
Browse files Browse the repository at this point in the history
Signed-off-by: zethson <lukas.heumos@posteo.net>
  • Loading branch information
Zethson committed Oct 8, 2024
1 parent b9b1d84 commit cc65ae1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 64 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ __pycache__/
*.pye

Sandbox.ipynb
test.ipynb
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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",
Expand All @@ -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")
view = save_vitessce_config(vc, description="Visium HD demo vitessce config")
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
ln.context.finish()
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit cc65ae1

Please sign in to comment.