Skip to contents

This vignette introduces the basic {laminr} workflow.

Setup

Install {laminr} from CRAN:

install.packages("laminr", dependencies = TRUE)

Set up the Python environment:

laminr::install_lamindb()

Set the default LaminDB instance:

laminr::lamin_connect("<owner>/<name>")

This instance acts as the default instance for everything that follows. Any data and tracking information will be added to it.

See vignette("setup", package = "laminr") for more details.

Start your analysis

Load {laminr} to get started.

Create your default database db object for this R session:

db <- connect()
#> ! schema module 'wetlab' is not installed → no access to its labels & registries (resolve via `pip install wetlab`)
#> ! schema module 'ourprojects' is not installed → no access to its labels & registries (resolve via `pip install ourprojects`)
#> ! schema module 'bionty' is not installed → no access to its labels & registries (resolve via `pip install bionty`)
#>  connected lamindb: laminlabs/lamindata

It is used to manage all datasets and metadata entities.

LaminDB tracks which code is used to create data. To track the current source code, run:

db$track("I8BlHXFXqZOG0000")

Connect to other instances

It is possible to connect to any LaminDB instance for reading data. Connect to the public CELLxGENE instance:

cellxgene <- connect("laminlabs/cellxgene")
cellxgene
#> cellxgene
#>   Core registries
#>     $Run
#>     $User
#>     $Param
#>     $ULabel
#>     $Feature
#>     $Storage
#>     $Artifact
#>     $Transform
#>     $Collection
#>     $FeatureSet
#>     $ParamValue
#>     $FeatureValue
#>   Additional modules
#>     bionty
#>     ourprojects

Download a dataset

Artifacts are objects that bundle data and associated metadata. An artifact can be any file or folder but is typically a dataset.

artifact <- cellxgene$Artifact$get("7dVluLROpalzEh8mNyxk")
artifact
#> Artifact(uid='7dVluLROpalzEh8mNyxk', description='Renal cell carcinoma, pre aPD1, kidney Puck_200727_12', key='cell-census/2023-12-15/h5ads/02faf712-92d4-4589-bec7-13105059cf86.h5ad', id=1742, run_id=22, hash='YNYuokfAoDFxdaRILjmU9w', size=13997860, suffix='.h5ad', storage_id=2, version='2023-12-15', _accessor='AnnData', is_latest=TRUE, transform_id=16, _hash_type='md5-n', created_at='2024-01-11T09:13:23.143694+00:00', created_by_id=1, updated_at='2024-01-24T07:17:47.009288+00:00', visibility=1, n_observations=17612, _key_is_virtual=FALSE)

To download the dataset and load it into memory, run:

adata <- artifact$load()
#> ... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad:  0.0%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad:  0.1%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad:  0.6%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad:  0.7%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad:  1.2%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad:  1.7%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad:  2.1%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad:  2.6%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad:  3.1%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad:  3.5%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad:  4.0%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad:  4.5%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad:  4.9%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad:  5.4%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad:  5.9%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad:  6.3%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad:  6.8%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad:  7.3%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad:  7.7%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad:  8.2%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad:  8.3%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad:  8.8%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad:  9.3%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad:  9.7%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 10.2%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 10.7%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 11.1%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 11.6%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 12.0%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 12.4%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 12.9%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 13.4%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 13.8%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 14.3%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 14.8%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 15.2%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 15.7%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 16.2%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 16.6%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 17.1%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 17.6%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 18.0%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 18.5%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 19.0%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 19.4%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 19.9%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 20.4%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 20.9%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 21.3%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 21.8%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 22.3%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 22.7%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 23.2%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 23.7%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 24.1%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 24.6%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 25.1%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 25.5%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 26.0%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 26.5%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 26.9%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 27.4%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 27.9%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 28.3%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 28.8%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 29.3%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 29.7%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 30.2%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 30.7%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 31.2%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 31.6%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 32.1%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 32.6%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 33.0%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 33.5%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 34.0%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 34.4%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 34.9%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 35.4%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 35.8%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 36.3%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 36.8%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 37.2%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 37.7%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 38.2%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 38.6%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 39.1%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 39.6%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 40.0%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 40.5%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 41.0%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 41.5%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 41.9%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 42.4%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 42.9%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 43.3%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 43.8%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 44.3%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 44.7%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 45.2%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 45.7%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 46.1%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 46.6%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 47.1%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 47.5%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 48.0%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 48.5%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 48.9%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 49.4%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 49.9%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 50.3%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 50.8%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 51.3%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 51.8%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 52.2%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 52.7%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 53.2%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 53.6%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 54.1%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 54.6%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 55.0%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 55.5%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 56.0%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 56.4%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 56.9%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 57.4%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 57.8%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 58.3%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 58.8%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 59.2%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 59.7%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 60.2%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 60.6%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 61.1%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 61.6%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 62.1%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 62.5%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 63.0%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 63.5%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 63.9%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 64.4%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 64.9%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 65.3%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 65.8%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 66.3%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 66.7%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 67.2%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 67.7%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 68.1%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 68.6%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 69.1%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 69.5%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 70.0%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 70.5%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 70.9%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 71.4%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 71.9%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 72.4%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 72.8%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 73.3%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 73.8%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 74.2%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 74.7%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 75.2%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 75.6%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 76.1%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 76.6%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 77.0%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 77.5%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 78.0%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 78.4%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 78.9%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 79.4%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 79.8%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 80.3%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 80.8%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 81.2%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 81.7%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 82.2%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 82.7%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 83.1%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 83.6%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 84.1%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 84.5%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 85.0%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 85.5%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 85.9%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 86.4%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 86.9%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 87.3%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 87.8%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 88.3%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 88.7%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 89.2%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 89.7%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 90.1%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 90.5%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 91.0%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 91.4%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 91.9%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 92.4%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 92.8%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 93.3%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 93.8%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 94.2%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 94.7%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 95.2%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 95.6%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 96.1%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 96.6%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 97.1%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 97.5%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 98.0%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 98.5%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 98.9%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 99.4%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 99.9%... synchronizing 02faf712-92d4-4589-bec7-13105059cf86.h5ad: 100.0%! run input wasn't tracked, call `ln.track()` and re-run
adata
#> AnnData object with n_obs × n_vars = 17612 × 23254
#>     obs: 'n_genes', 'n_UMIs', 'log10_n_UMIs', 'log10_n_genes', 'Cell_Type', 'cell_type_ontology_term_id', 'organism_ontology_term_id', 'tissue_ontology_term_id', 'assay_ontology_term_id', 'disease_ontology_term_id', 'self_reported_ethnicity_ontology_term_id', 'development_stage_ontology_term_id', 'sex_ontology_term_id', 'donor_id', 'is_primary_data', 'suspension_type', 'cell_type', 'assay', 'disease', 'organism', 'sex', 'tissue', 'self_reported_ethnicity', 'development_stage'
#>     var: 'gene', 'n_beads', 'n_UMIs', 'feature_is_filtered', 'feature_name', 'feature_reference', 'feature_biotype'
#>     uns: 'Cell_Type_colors', 'schema_version', 'title'
#>     obsm: 'X_spatial'

This artifact contains an AnnData object.

Work with the dataset

Once you have loaded a dataset you can perform any analysis with it as you would normally. Here, marker genes are calculated for each of the provided cell type labels using {Seurat}.

library(Seurat)
#> Loading required package: SeuratObject
#> Loading required package: sp
#> 'SeuratObject' was built under R 4.4.0 but the current version is
#> 4.4.2; it is recomended that you reinstall 'SeuratObject' as the ABI
#> for R may have changed
#> 
#> Attaching package: 'SeuratObject'
#> The following objects are masked from 'package:base':
#> 
#>     intersect, t

# Create a Seurat object
seurat_obj <- CreateSeuratObject(
  counts = as(Matrix::t(adata$X), "CsparseMatrix"),
  meta.data = adata$obs
)
# Add gene metadata
seurat_obj[["RNA"]] <- AddMetaData(
  GetAssay(seurat_obj), adata$var
)
# Set cell identities to the provided cell type annotation
Idents(seurat_obj) <- "cell_type"
# Normalise the data
seurat_obj <- NormalizeData(seurat_obj)
#> Normalizing layer: counts
# Test for marker genes (the output is a data.frame)
markers <- FindAllMarkers(
  seurat_obj,
  features = Features(seurat_obj)[1:100] # Only test a few features for speed
)
#> Calculating cluster fibroblast
#> For a (much!) faster implementation of the Wilcoxon Rank Sum Test,
#> (default method for FindMarkers) please install the presto package
#> --------------------------------------------
#> install.packages('devtools')
#> devtools::install_github('immunogenomics/presto')
#> --------------------------------------------
#> After installation of presto, Seurat will automatically use the more 
#> efficient implementation (no further action necessary).
#> This message will be shown once per session
#> Calculating cluster epithelial cell
#> Calculating cluster myeloid cell
#> Calculating cluster malignant cell
#> Warning: The following tests were not performed:
#> Warning: When testing epithelial cell versus all:
#>  Cell group 1 has fewer than 3 cells
# Display the marker genes
knitr::kable(markers)
p_val avg_log2FC pct.1 pct.2 p_val_adj cluster gene
ENSG00000147113 0.0000001 1.8228103 0.019 0.005 0.0011654 fibroblast ENSG00000147113
ENSG00000170004 0.0000002 2.5663044 0.021 0.006 0.0036485 fibroblast ENSG00000170004
ENSG00000196139 0.0000003 -0.8318130 0.053 0.110 0.0058749 fibroblast ENSG00000196139
ENSG00000132170 0.0006719 1.7151510 0.020 0.009 1.0000000 fibroblast ENSG00000132170
ENSG00000205542 0.0007360 0.6442683 0.230 0.195 1.0000000 fibroblast ENSG00000205542
ENSG00000163536 0.0025157 1.8914687 0.012 0.004 1.0000000 fibroblast ENSG00000163536
ENSG00000067064 0.0063090 1.2509162 0.014 0.006 1.0000000 fibroblast ENSG00000067064
ENSG00000105855 0.0068491 -0.5412708 0.022 0.041 1.0000000 fibroblast ENSG00000105855
ENSG00000205542.1 0.0000002 1.3623005 0.310 0.195 0.0046479 myeloid cell ENSG00000205542
ENSG00000196139.1 0.0015658 -0.5898982 0.040 0.108 1.0000000 myeloid cell ENSG00000196139
ENSG00000196139.2 0.0000000 0.7939631 0.111 0.050 0.0000224 malignant cell ENSG00000196139
ENSG00000205542.2 0.0000001 -0.8585382 0.193 0.247 0.0013456 malignant cell ENSG00000205542
ENSG00000147113.1 0.0000018 -1.4976270 0.005 0.016 0.0415774 malignant cell ENSG00000147113
ENSG00000170004.1 0.0000073 -2.2898276 0.006 0.018 0.1686987 malignant cell ENSG00000170004
ENSG00000105855.1 0.0003828 0.7197716 0.041 0.019 1.0000000 malignant cell ENSG00000105855
ENSG00000053371 0.0038080 0.8347505 0.029 0.014 1.0000000 malignant cell ENSG00000053371
ENSG00000141385 0.0058269 1.0575502 0.019 0.007 1.0000000 malignant cell ENSG00000141385
ENSG00000132170.1 0.0072852 -1.3878878 0.009 0.017 1.0000000 malignant cell ENSG00000132170
ENSG00000163536.1 0.0076905 -1.8629158 0.004 0.010 1.0000000 malignant cell ENSG00000163536
# Plot the marker genes
DotPlot(seurat_obj, features = unique(markers$gene)) +
  ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90, vjust = 0.5))
#> Warning: Scaling data with a low number of groups may produce misleading
#> results

Slice a TileDB-SOMA array store

When artifacts contain TileDB-SOMA array stores they can be opened and sliced using the {tiledbsoma} package.

# Set some environment variables to avoid an issue with {tiledbsoma}
# https://github.com/chanzuckerberg/cellxgene-census/issues/1261
Sys.setenv(TILEDB_VFS_S3_REGION = "us-west-2")
Sys.setenv(AWS_DEFAULT_REGION = "us-west-2")
Sys.setenv(TILEDB_VFS_S3_NO_SIGN_REQUEST = "true")

# Define a filter to select specific cells
value_filter <- paste(
  "tissue == 'brain' &&",
  "cell_type %in% c('microglial cell', 'neuron') &&",
  "suspension_type == 'cell' &&",
  "assay == '10x 3\\' v3'"
)

# Get the artifact containing the CELLxGENE Census TileDB-SOMA store
census_artifact <- cellxgene$Artifact$get("FYMewVq5twKMDXVy0001")
# Open the SOMACollection
soma_collection <- census_artifact$open()
# Slice the store to get a SOMADataFrame containing metadata for the cells of interest
cell_metadata <- soma_collection$get("census_data")$get("homo_sapiens")$obs$read(value_filter = value_filter)
# Concatenate the results to an arrow::Table
cell_metadata <- cell_metadata$concat()
# Convert to a data.frame
cell_metadata <- cell_metadata$to_data_frame()

cell_metadata
#> # A tibble: 66,418 × 28
#>    soma_joinid dataset_id                 assay assay_ontology_term_id cell_type
#>          <int> <fct>                      <fct> <fct>                  <fct>    
#>  1    48182177 c888b684-6c51-431f-972a-6… 10x … EFO:0009922            microgli…
#>  2    48182178 c888b684-6c51-431f-972a-6… 10x … EFO:0009922            microgli…
#>  3    48182185 c888b684-6c51-431f-972a-6… 10x … EFO:0009922            microgli…
#>  4    48182187 c888b684-6c51-431f-972a-6… 10x … EFO:0009922            microgli…
#>  5    48182188 c888b684-6c51-431f-972a-6… 10x … EFO:0009922            microgli…
#>  6    48182189 c888b684-6c51-431f-972a-6… 10x … EFO:0009922            microgli…
#>  7    48182190 c888b684-6c51-431f-972a-6… 10x … EFO:0009922            microgli…
#>  8    48182191 c888b684-6c51-431f-972a-6… 10x … EFO:0009922            microgli…
#>  9    48182192 c888b684-6c51-431f-972a-6… 10x … EFO:0009922            microgli…
#> 10    48182194 c888b684-6c51-431f-972a-6… 10x … EFO:0009922            microgli…
#> # ℹ 66,408 more rows
#> # ℹ 23 more variables: cell_type_ontology_term_id <fct>,
#> #   development_stage <fct>, development_stage_ontology_term_id <fct>,
#> #   disease <fct>, disease_ontology_term_id <fct>, donor_id <fct>,
#> #   is_primary_data <lgl>, observation_joinid <chr>,
#> #   self_reported_ethnicity <fct>,
#> #   self_reported_ethnicity_ontology_term_id <fct>, sex <fct>, …

Save the results

Save results as new artifacts to the default LaminDB instance.

seurat_path <- tempfile(fileext = ".rds")
saveRDS(seurat_obj, seurat_path)

db$Artifact$from_df(
  markers,
  description = "Marker genes for renal cell carcinoma dataset"
)$save()

db$Artifact$from_path(
  seurat_path,
  description = "Seurat object for renal cell carcinoma dataset"
)$save()

Mark the analysis as finished

Mark the analysis run as finished to create a time stamp and upload source code to the hub.

db$finish()

Save a notebook report (not needed for .R scripts)

Save a run report of your notebook (.Rmd or .qmd file) to your instance:

  1. Render the notebook to HTML
  • In RStudio, click the “Knit” button

  • OR From the command line, run:

    Rscript -e 'rmarkdown::render("laminr.Rmd")'
  • OR Use the rmarkdown package in R:

    rmarkdown::render("laminr.Rmd")
  1. Save it to your LaminDB instance using the lamin CLI:
lamin save laminr.Rmd

Further reading

For more details about how {laminr} works see vignette("concepts_features", package = "laminr").