Markdown

Analyze the collection and save a result

import lamindb as ln
import bionty as bt

ln.track("zzJzdgJ763Dy0000")
Hide code cell output
 connected lamindb: testuser1/test-facs
 created Transform('zzJzdgJ763Dy0000', key='facs4.ipynb'), started new Run('tNYQcn0nmURiHQYq') at 2026-01-29 23:14:21 UTC
 notebook imports: bionty==2.1.0 lamindb==2.0.1 scanpy==1.12
ln.Collection.to_dataframe()
Hide code cell output
uid key description hash reference reference_type version_tag is_latest is_locked created_at branch_id space_id created_by_id run_id meta_artifact_id
id
2 0PXsYmFARTOStjFP0001 My versioned cytometry collection None eNSQbRNsjg278G1RwXmqCw None None 2 True False 2026-01-29 23:14:13.081000+00:00 1 1 3 2 None
1 0PXsYmFARTOStjFP0000 My versioned cytometry collection None jZ8YvUdZGRwPgfoBQbOg_Q None None 1 False False 2026-01-29 23:14:02.233000+00:00 1 1 3 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.12/x64/lib/python3.12/site-packages/anndata/_core/anndata.py:1806: 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(['OmHrS3jjrlg6Zxxd0000', 'jUPHbuQ3gUKmFQJQ0000'], 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
/tmp/ipykernel_3774/1861229803.py:4: FutureWarning: Argument `save` is deprecated and will be removed in a future version. Use `sc.pl.plot(show=False).figure.savefig()` instead.
  sc.pl.pca(adata, color=markers.cd8.name, save="_cd8")
_images/22f8bb4fe8991b58503cbe11c329eb88fa57fea06a384754d29ca77ae59e9123.png
artifact = ln.Artifact("./figures/pca_cd8.pdf", description="My result on CD8").save()
artifact.view_lineage()
Hide code cell output
_images/f68d5bdee7ab67795124e60b84a21897ff81efda11b8c5ee965356a67f3ef9af.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:                                                          
 /home/runner/work/lamin-usecases/lamin-usecases/docs/test-facs/.lamindb/8ogf 
 eee1DsyU7WkG0000.pdf                                                         
 /home/runner/work/lamin-usecases/lamin-usecases/docs/test-facs/.lamindb/OmHr 
 S3jjrlg6Zxxd0000.h5ad                                                        
 /home/runner/work/lamin-usecases/lamin-usecases/docs/test-facs/.lamindb/jUPH 
 buQ3gUKmFQJQ0000.h5ad                                                        
 delete them prior to deleting the storage location                           
╰──────────────────────────────────────────────────────────────────────────────╯