facs4/4 Jupyter Notebook lamindata

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', key='facs4.ipynb'), started new Run('VOYAjyWvoRSBPGTP') at 2025-10-30 19:02:36 UTC
 notebook imports: bionty==1.8.1 lamindb==1.15a1 scanpy==1.11.5
ln.Collection.to_dataframe()
Hide code cell output
uid key description hash reference reference_type version is_latest is_locked created_at branch_id space_id created_by_id run_id meta_artifact_id
id
2 xJCs0YYoYshwjGA60001 My versioned cytometry collection None eNSQbRNsjg278G1RwXmqCw None None 2 True False 2025-10-30 19:02:28.356000+00:00 1 1 1 2 None
1 xJCs0YYoYshwjGA60000 My versioned cytometry collection None jZ8YvUdZGRwPgfoBQbOg_Q None None 1 False False 2025-10-30 19:02:19.064000+00:00 1 1 1 1 None
collection = ln.Collection.get(key="My versioned cytometry collection", version="2")
adata = collection.load(join="inner")
Hide code cell output
/opt/hostedtoolcache/Python/3.12.11/x64/lib/python3.12/site-packages/anndata/_core/anndata.py:1791: 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
Hide code cell output
Index(['CNYtRlJCCNsU1Ln50000', 'ETOh6WcbRg6ggd8P0000'], dtype='object')

By default, the intersection of features is used:

adata.var.index
Hide 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")
Hide code cell output
WARNING: saving figure to file figures/pca_cd8.pdf
_images/9dc8169aa9cef990b359438ecf295fe6657713241a7e6409bb739cac8dec9691.png
artifact = ln.Artifact("./figures/pca_cd8.pdf", description="My result on CD8").save()
artifact.view_lineage()
_images/b5d29a70f7b4728b077f309ed54592b22a3f6b6875ffcb8ad14153293e5c3a91.svg

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
Hide code cell output
rm: cannot remove 'test-flow': No such file or directory
╭─ Error ──────────────────────────────────────────────────────────────────────╮
 '/home/runner/work/lamin-usecases/lamin-usecases/docs/test-facs/.lamindb'    
 contains 3 objects - delete them prior to deleting the storage location      
╰──────────────────────────────────────────────────────────────────────────────╯