facs4/4 Jupyter Notebook lamindata

Analyze the collection and save a result

import lamindb as ln
import bionty as bt

ln.context.uid = "zzJzdgJ763Dy0000"
ln.context.track()
→ connected lamindb: testuser1/test-facs
→ notebook imports: bionty==0.50.2 lamindb==0.76.8 scanpy==1.10.3
→ created Transform(uid='zzJzdgJ763Dy0000') & created Run(started_at='2024-09-25 08:44:42 UTC')
ln.Collection.df()
Hide code cell output
uid version is_latest name description hash reference reference_type visibility transform_id meta_artifact_id run_id created_by_id updated_at
id
2 PWrsYlPY3IDcMCBq0001 2 True My versioned cytometry collection None aIyjTZDm9LEyi4udLlQ-FA None None 1 2 None 2 1 2024-09-25 08:44:33.378447+00:00
1 PWrsYlPY3IDcMCBq0000 1 False My versioned cytometry collection None _SSVHoSL17yyiRlHc8Hrgw None None 1 1 None 1 1 2024-09-25 08:44:33.377763+00:00
collection = ln.Collection.get(name="My versioned cytometry collection", version="2")
adata = collection.load(join="inner")
Hide code cell output
/opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/anndata/_core/anndata.py:1754: 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(['VIqckZ1pweYw9p4T0000', 'xunrP57rMJgHgNI00000'], 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/cdaf076839a6b4d308660beb5839365c75818e2a60a02f109adca088ffb50bbd.png
artifact = ln.Artifact("./figures/pca_cd8.pdf", description="My result on CD8").save()
artifact.view_lineage()
_images/1cd6d9fcf3079159bb2a3b011ff877f14d39cb43294fd3f0a1173a6c7261c6a5.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.context.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
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.11.10/x64/bin/lamin", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/rich_click/rich_command.py", line 367, in __call__
    return super().__call__(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/rich_click/rich_command.py", line 152, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/lamin_cli/__main__.py", line 201, in delete
    return delete(instance, force=force)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/lamindb_setup/_delete.py", line 102, in delete
    n_objects = check_storage_is_empty(
                ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/lamindb_setup/core/upath.py", line 776, in check_storage_is_empty
    raise InstanceNotEmpty(message)
lamindb_setup.core.upath.InstanceNotEmpty: Storage /home/runner/work/lamin-usecases/lamin-usecases/docs/test-facs/.lamindb contains 3 objects ('_is_initialized' ignored) - delete them prior to deleting the instance