Analyze the collection and save a result¶
import lamindb as ln
import bionty as bt
ln.track("zzJzdgJ763Dy0000")
→ connected lamindb: testuser1/test-facs
→ created Transform('zzJzdgJ763Dy0000'), started new Run('CYD9PEzd...') at 2025-01-20 07:39:20 UTC
→ notebook imports: bionty==1.0.0 lamindb==1.0.2 scanpy==1.10.4
ln.Collection.df()
Show code cell output
uid | key | description | hash | reference | reference_type | space_id | meta_artifact_id | version | is_latest | run_id | created_at | created_by_id | _aux | _branch_code | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | |||||||||||||||
2 | 10GVN0SBTT6Cqg0n0001 | My versioned cytometry collection | None | aIyjTZDm9LEyi4udLlQ-FA | None | None | 1 | None | 2 | True | 2 | 2025-01-20 07:39:10.891000+00:00 | 1 | None | 1 |
1 | 10GVN0SBTT6Cqg0n0000 | My versioned cytometry collection | None | _SSVHoSL17yyiRlHc8Hrgw | None | None | 1 | None | 1 | False | 1 | 2025-01-20 07:39:01.194000+00:00 | 1 | None | 1 |
collection = ln.Collection.get(name="My versioned cytometry collection", version="2")
adata = collection.load(join="inner")
Show code cell output
/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/site-packages/anndata/_core/anndata.py:1756: UserWarning: Observation names are not unique. To make them unique, call `.obs_names_make_unique`.
utils.warn_names_duplicates("obs")
The AnnData
has the reference to the individual files in the .obs
annotations:
adata.obs.artifact_uid.cat.categories
Show code cell output
Index(['5s56cWrWhpiAwh5h0000', '4q0QrlBS4kevoDq60000'], dtype='object')
By default, the intersection of features is used:
adata.var.index
Show code cell output
Index(['CD8', 'CD27', 'Ccr7', 'Cd4', 'CD45RA', 'CD3'], dtype='object')
Let us create a plot:
markers = bt.CellMarker.lookup()
import scanpy as sc
sc.pp.pca(adata)
sc.pl.pca(adata, color=markers.cd8.name, save="_cd8")
Show code cell output
WARNING: saving figure to file figures/pca_cd8.pdf
artifact = ln.Artifact("./figures/pca_cd8.pdf", description="My result on CD8").save()
artifact.view_lineage()
Given the image is part of the notebook, there isn’t an actual need to save it and you can also rely on the report that you’ll create when saving the notebook:
ln.finish()
# clean up test instance
!rm -r test-flow
!lamin delete --force test-facs
Show code cell output
rm: cannot remove 'test-flow': No such file or directory
╭─ Error ──────────────────────────────────────────────────────────────────────╮
│ Storage │
│ '/home/runner/work/lamin-usecases/lamin-usecases/docs/test-facs/.lamindb' │
│ contains 3 objects - delete them prior to deleting the instance │
╰──────────────────────────────────────────────────────────────────────────────╯