Discovery and retrieval

NOTE: The interface to CELLxGENE has changed; versions of cellxgenedp prior to 1.4.1 / 1.5.2 will cease to work when CELLxGENE removes the previous interface. See the vignette section ‘API changes’ for additional details.

Installation and use

This package is available in Bioconductor version 3.15 and later. The following code installs cellxgenedp from Bioconductor

if (!"BiocManager" %in% rownames(installed.packages()))
    install.packages("BiocManager", repos = "https://CRAN.R-project.org")
BiocManager::install("cellxgenedp")

Alternatively, install the ‘development’ version from GitHub (see GitHub.io for current documentation)

if (!"remotes" %in% rownames(installed.packages()))
    install.packages("remotes", repos = "https://CRAN.R-project.org")
remotes::install_github("mtmorgan/cellxgenedp")

To also install additional packages required for this vignette, use

pkgs <- c("tidyr", "zellkonverter", "SingleCellExperiment", "HDF5Array")
required_pkgs <- pkgs[!pkgs %in% rownames(installed.packages())]
BiocManager::install(required_pkgs)

Load the package into your current R session. We make extensive use of the dplyr packages, and at the end of the vignette use SingleCellExperiment and zellkonverter, so load those as well.

library(zellkonverter)
library(SingleCellExperiment) # load early to avoid masking dplyr::count()
library(dplyr)
library(cellxgenedp)

cxg() Provides a ‘shiny’ interface

The following sections outline how to use the cellxgenedp package in an R script; most functionality is also available in the cxg() shiny application, providing an easy way to identify, download, and visualize one or several datasets. Start the app

cxg()

choose a project on the first tab, and a dataset for visualization, or one or more datasets for download!

Collections, datasets and files

Retrieve metadata about resources available at the cellxgene data portal using db():

db <- db()
## Collections ■                                  1% | ETA:  2m
## Collections ■■                                 3% | ETA:  2m
## Collections ■■■                                5% | ETA:  2m
## Collections ■■■■                              11% | ETA:  1m
## Collections ■■■■■■                            16% | ETA:  1m
## Collections ■■■■■■                            18% | ETA:  1m
## Collections ■■■■■■■■                          24% | ETA:  1m
## Collections ■■■■■■■■■■                        31% | ETA: 50s
## Collections ■■■■■■■■■■■■                      36% | ETA: 44s
## Collections ■■■■■■■■■■■■■                     40% | ETA: 43s
## Collections ■■■■■■■■■■■■■■                    44% | ETA: 39s
## Collections ■■■■■■■■■■■■■■■■                  48% | ETA: 38s
## Collections ■■■■■■■■■■■■■■■■                  52% | ETA: 39s
## Collections ■■■■■■■■■■■■■■■■■                 52% | ETA: 43s
## Collections ■■■■■■■■■■■■■■■■■                 55% | ETA: 41s
## Collections ■■■■■■■■■■■■■■■■■■■               59% | ETA: 36s
## Collections ■■■■■■■■■■■■■■■■■■■■              64% | ETA: 31s
## Collections ■■■■■■■■■■■■■■■■■■■■■             67% | ETA: 28s
## Collections ■■■■■■■■■■■■■■■■■■■■■■            69% | ETA: 28s
## Collections ■■■■■■■■■■■■■■■■■■■■■■■           72% | ETA: 25s
## Collections ■■■■■■■■■■■■■■■■■■■■■■■■          76% | ETA: 22s
## Collections ■■■■■■■■■■■■■■■■■■■■■■■■■         80% | ETA: 17s
## Collections ■■■■■■■■■■■■■■■■■■■■■■■■■■        84% | ETA: 14s
## Collections ■■■■■■■■■■■■■■■■■■■■■■■■■■■■      89% | ETA: 10s
## Collections ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■     94% | ETA:  5s
## Collections ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■    98% | ETA:  2s
## Collections ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■  100% | ETA:  0s

Printing the db object provides a brief overview of the available data, as well as hints, in the form of functions like collections(), for further exploration.

db
## cellxgene_db
## number of collections(): 252
## number of datasets(): 1622
## number of files(): 2942

The portal organizes data hierarchically, with ‘collections’ (research studies, approximately), ‘datasets’, and ‘files’. Discover data using the corresponding functions.

collections(db)
## # A tibble: 252 × 18
##    collection_id    collection_version_id collection_url consortia contact_email
##    <chr>            <chr>                 <chr>          <list>    <chr>        
##  1 db70986c-7d91-4… 261b9ea2-7c86-4fb8-a… https://cellx… <lgl [1]> korbinian.tr…
##  2 2902f08c-f83c-4… f6bb8e5a-d4b5-45b2-b… https://cellx… <lgl [1]> [email protected]
##  3 180bff9c-c8a5-4… 08fe7e17-7a75-454e-b… https://cellx… <lgl [1]> Martin.Kampm…
##  4 02b01703-bf1b-4… e82e40f6-3696-4b3b-9… https://cellx… <lgl [1]> sophliu95@gm…
##  5 4d8fed08-2d6d-4… 2280eac2-a84b-4b9a-9… https://cellx… <lgl [1]> sten.linnars…
##  6 45f0f67d-4b69-4… 37910e4c-5c24-46ac-8… https://cellx… <chr [2]> bosiljkat@al…
##  7 24d42e5e-ce6d-4… e18d44b9-7fbe-4c7b-9… https://cellx… <chr [1]> pas2182@colu…
##  8 2d2e2acd-dade-4… aafcdfdc-93d4-4310-9… https://cellx… <chr [1]> e.rawlins@gu…
##  9 a96133de-e951-4… d5424314-8912-47fa-9… https://cellx… <chr [1]> jklugham@bro…
## 10 6b701826-37bb-4… 551fc857-23de-4008-8… https://cellx… <chr [1]> astreets@ber…
## # ℹ 242 more rows
## # ℹ 13 more variables: contact_name <chr>, curator_name <chr>,
## #   description <chr>, doi <chr>, links <list>, name <chr>,
## #   publisher_metadata <list>, revising_in <lgl>, revision_of <lgl>,
## #   visibility <chr>, created_at <date>, published_at <date>, revised_at <date>
datasets(db)
## # A tibble: 1,622 × 33
##    dataset_id   dataset_version_id collection_id donor_id assay  batch_condition
##    <chr>        <chr>              <chr>         <list>   <list> <list>         
##  1 72955cdb-bd… 999a6b92-46ca-498… db70986c-7d9… <chr>    <list> <lgl [1]>      
##  2 1f1c5c14-59… 2afef4bd-99af-41f… 2902f08c-f83… <chr>    <list> <lgl [1]>      
##  3 f9ad5649-f3… d9db936c-41c6-439… 180bff9c-c8a… <chr>    <list> <lgl [1]>      
##  4 cd77258f-b0… 000198ac-27c7-4b9… 180bff9c-c8a… <chr>    <list> <lgl [1]>      
##  5 bdacc907-7c… 017837df-b8be-4a4… 180bff9c-c8a… <chr>    <list> <lgl [1]>      
##  6 b94e3bdf-a3… 3512034b-9a5c-4db… 180bff9c-c8a… <chr>    <list> <lgl [1]>      
##  7 9f1049ac-f8… bb8f672d-593d-482… 180bff9c-c8a… <chr>    <list> <lgl [1]>      
##  8 873ff933-4f… a7d3ba30-903d-44f… 180bff9c-c8a… <chr>    <list> <lgl [1]>      
##  9 75a881cf-5d… 50d7154f-e5b9-48a… 180bff9c-c8a… <chr>    <list> <lgl [1]>      
## 10 6c600df6-dd… 1f97f38b-2a9e-48a… 180bff9c-c8a… <chr>    <list> <lgl [1]>      
## # ℹ 1,612 more rows
## # ℹ 27 more variables: cell_count <int>, cell_type <list>, citation <chr>,
## #   default_embedding <chr>, development_stage <list>, disease <list>,
## #   embeddings <list>, explorer_url <chr>, feature_biotype <list>,
## #   feature_count <int>, feature_reference <list>, is_primary_data <list>,
## #   mean_genes_per_cell <dbl>, organism <list>, primary_cell_count <int>,
## #   raw_data_location <chr>, schema_version <chr>, …
files(db)
## # A tibble: 2,942 × 4
##    dataset_id                             filesize filetype url                 
##    <chr>                                     <dbl> <chr>    <chr>               
##  1 72955cdb-bd92-4135-aa52-21f33f9640db 4221495897 H5AD     https://datasets.ce…
##  2 72955cdb-bd92-4135-aa52-21f33f9640db 1216838411 RDS      https://datasets.ce…
##  3 1f1c5c14-5949-4c81-b28e-b272e271b672  105862325 H5AD     https://datasets.ce…
##  4 1f1c5c14-5949-4c81-b28e-b272e271b672   96479066 RDS      https://datasets.ce…
##  5 f9ad5649-f372-43e1-a3a8-423383e5a8a2   17724244 H5AD     https://datasets.ce…
##  6 f9ad5649-f372-43e1-a3a8-423383e5a8a2   14805677 RDS      https://datasets.ce…
##  7 cd77258f-b08b-4c89-b93f-6e6f146b1a4d   47491494 H5AD     https://datasets.ce…
##  8 cd77258f-b08b-4c89-b93f-6e6f146b1a4d   46270555 RDS      https://datasets.ce…
##  9 bdacc907-7c26-419f-8808-969eab3ca2e8    9460591 H5AD     https://datasets.ce…
## 10 bdacc907-7c26-419f-8808-969eab3ca2e8    7134383 RDS      https://datasets.ce…
## # ℹ 2,932 more rows

Each of these resources has a unique primary identifier (e.g., file_id) as well as an identifier describing the relationship of the resource to other components of the database (e.g., dataset_id). These identifiers can be used to ‘join’ information across tables.

Using dplyr to navigate data

A collection may have several datasets, and datasets may have several files. For instance, here is the collection with the most datasets

collection_with_most_datasets <-
    datasets(db) |>
    count(collection_id, sort = TRUE) |>
    slice(1)

We can find out about this collection by joining with the collections() table.

left_join(
    collection_with_most_datasets |> select(collection_id),
    collections(db),
    by = "collection_id"
) |> glimpse()
## Rows: 1
## Columns: 18
## $ collection_id         <chr> "283d65eb-dd53-496d-adb7-7570c7caa443"
## $ collection_version_id <chr> "3a7554b3-364d-435c-b193-2c410b4d685b"
## $ collection_url        <chr> "https://cellxgene.cziscience.com/collections/28…
## $ consortia             <list> <"BRAIN Initiative", "CZI Cell Science">
## $ contact_email         <chr> "[email protected]"
## $ contact_name          <chr> "Kimberly Siletti"
## $ curator_name          <chr> "James Chaffer"
## $ description           <chr> "First draft atlas of human brain transcriptomic…
## $ doi                   <chr> "10.1126/science.add7046"
## $ links                 <list> [["", "RAW_DATA", "http://data.nemoarchive.org/b…
## $ name                  <chr> "Human Brain Cell Atlas v1.0"
## $ publisher_metadata    <list> [[["Siletti", "Kimberly"], ["Hodge", "Rebecca"]…
## $ revising_in           <lgl> NA
## $ revision_of           <lgl> NA
## $ visibility            <chr> "PUBLIC"
## $ created_at            <date> 2024-10-04
## $ published_at          <date> 2022-12-09
## $ revised_at            <date> 2024-10-10

We can take a similar strategy to identify all datasets belonging to this collection

left_join(
    collection_with_most_datasets |> select(collection_id),
    datasets(db),
    by = "collection_id"
)
## # A tibble: 138 × 33
##    collection_id   dataset_id dataset_version_id donor_id assay  batch_condition
##    <chr>           <chr>      <chr>              <list>   <list> <list>         
##  1 283d65eb-dd53-… ff7d15fa-… 67c901a1-61b9-44b… <chr>    <list> <chr [1]>      
##  2 283d65eb-dd53-… fe1a73ab-… a1d76660-6c76-452… <chr>    <list> <chr [1]>      
##  3 283d65eb-dd53-… fbf173f9-… 0e9ac792-173c-4a7… <chr>    <list> <chr [1]>      
##  4 283d65eb-dd53-… fa554686-… 10fa9df1-dd8e-4d7… <chr>    <list> <chr [1]>      
##  5 283d65eb-dd53-… f9034091-… 8043f1b1-93f5-449… <chr>    <list> <chr [1]>      
##  6 283d65eb-dd53-… f8dda921-… 2094b8a9-0a4f-4fa… <chr>    <list> <chr [1]>      
##  7 283d65eb-dd53-… f7d003d4-… 8d0adf31-efcd-44a… <chr>    <list> <chr [1]>      
##  8 283d65eb-dd53-… f6d9f2ad-… 160cef00-39e7-49a… <chr>    <list> <chr [1]>      
##  9 283d65eb-dd53-… f5a04dff-… 6c74e563-2d25-4eb… <chr>    <list> <chr [1]>      
## 10 283d65eb-dd53-… f502c312-… b95a40b6-537b-469… <chr>    <list> <chr [1]>      
## # ℹ 128 more rows
## # ℹ 27 more variables: cell_count <int>, cell_type <list>, citation <chr>,
## #   default_embedding <chr>, development_stage <list>, disease <list>,
## #   embeddings <list>, explorer_url <chr>, feature_biotype <list>,
## #   feature_count <int>, feature_reference <list>, is_primary_data <list>,
## #   mean_genes_per_cell <dbl>, organism <list>, primary_cell_count <int>,
## #   raw_data_location <chr>, schema_version <chr>, …

facets() provides information on ‘levels’ present in specific columns

Notice that some columns are ‘lists’ rather than atomic vectors like ‘character’ or ‘integer’.

datasets(db) |>
    select(where(is.list))
## # A tibble: 1,622 × 16
##    donor_id   assay      batch_condition cell_type   development_stage disease
##    <list>     <list>     <list>          <list>      <list>            <list> 
##  1 <chr [57]> <list [2]> <lgl [1]>       <list [11]> <list [11]>       <list> 
##  2 <chr [5]>  <list [1]> <lgl [1]>       <list [9]>  <list [1]>        <list> 
##  3 <chr [10]> <list [1]> <lgl [1]>       <list [1]>  <list [8]>        <list> 
##  4 <chr [10]> <list [1]> <lgl [1]>       <list [1]>  <list [8]>        <list> 
##  5 <chr [10]> <list [1]> <lgl [1]>       <list [1]>  <list [8]>        <list> 
##  6 <chr [10]> <list [1]> <lgl [1]>       <list [1]>  <list [8]>        <list> 
##  7 <chr [10]> <list [1]> <lgl [1]>       <list [1]>  <list [8]>        <list> 
##  8 <chr [10]> <list [1]> <lgl [1]>       <list [1]>  <list [8]>        <list> 
##  9 <chr [10]> <list [1]> <lgl [1]>       <list [1]>  <list [8]>        <list> 
## 10 <chr [10]> <list [1]> <lgl [1]>       <list [7]>  <list [8]>        <list> 
## # ℹ 1,612 more rows
## # ℹ 10 more variables: embeddings <list>, feature_biotype <list>,
## #   feature_reference <list>, is_primary_data <list>, organism <list>,
## #   self_reported_ethnicity <list>, sex <list>, spatial <list>,
## #   suspension_type <list>, tissue <list>

This indicates that at least some of the datasets had more than one type of assay, cell_type, etc. The facets() function provides a convenient way of discovering possible levels of each column, e.g., assay, organism, self_reported_ethnicity, or sex, and the number of datasets with each label.

facets(db, "assay")
## # A tibble: 39 × 4
##    facet label                          ontology_term_id     n
##    <chr> <chr>                          <chr>            <int>
##  1 assay 10x 3' v3                      EFO:0009922        746
##  2 assay 10x 3' v2                      EFO:0009899        340
##  3 assay Visium Spatial Gene Expression EFO:0010961        268
##  4 assay Slide-seqV2                    EFO:0030062        240
##  5 assay 10x 5' v1                      EFO:0011025        107
##  6 assay Smart-seq2                     EFO:0008931         72
##  7 assay 10x multiome                   EFO:0030059         69
##  8 assay sci-RNA-seq3                   EFO:0030028         48
##  9 assay 10x 5' v2                      EFO:0009900         38
## 10 assay 10x 5' transcription profiling EFO:0030004         27
## # ℹ 29 more rows
facets(db, "self_reported_ethnicity")
## # A tibble: 37 × 4
##    facet                   label                          ontology_term_id     n
##    <chr>                   <chr>                          <chr>            <int>
##  1 self_reported_ethnicity European                       HANCESTRO:0005     644
##  2 self_reported_ethnicity unknown                        unknown            643
##  3 self_reported_ethnicity na                             na                 416
##  4 self_reported_ethnicity Asian                          HANCESTRO:0008     165
##  5 self_reported_ethnicity African American               HANCESTRO:0568      86
##  6 self_reported_ethnicity Hispanic or Latin American     HANCESTRO:0014      78
##  7 self_reported_ethnicity Native American,Hispanic or L… HANCESTRO:0013,…    50
##  8 self_reported_ethnicity African American or Afro-Cari… HANCESTRO:0016      40
##  9 self_reported_ethnicity Greater Middle Eastern  (Midd… HANCESTRO:0015      24
## 10 self_reported_ethnicity South Asian                    HANCESTRO:0006      23
## # ℹ 27 more rows
facets(db, "sex")
## # A tibble: 3 × 4
##   facet label   ontology_term_id     n
##   <chr> <chr>   <chr>            <int>
## 1 sex   male    PATO:0000384      1175
## 2 sex   female  PATO:0000383       959
## 3 sex   unknown unknown            262

Filtering faceted columns

Suppose we were interested in finding datasets from the 10x 3’ v3 assay (ontology_term_id of EFO:0009922) containing individuals of African American ethnicity, and female sex. Use the facets_filter() utility function to filter data sets as needed

african_american_female <-
    datasets(db) |>
    filter(
        facets_filter(assay, "ontology_term_id", "EFO:0009922"),
        facets_filter(self_reported_ethnicity, "label", "African American"),
        facets_filter(sex, "label", "female")
    )

Use nrow(african_american_female) to find the number of datasets satisfying our criteria. It looks like there are up to

african_american_female |>
    summarise(total_cell_count = sum(cell_count))
## # A tibble: 1 × 1
##   total_cell_count
##              <int>
## 1         12600682

cells sequenced (each dataset may contain cells from several ethnicities, as well as males or individuals of unknown gender, so we do not know the actual number of cells available without downloading files). Use left_join to identify the corresponding collections:

## collections
left_join(
    african_american_female |> select(collection_id) |> distinct(),
    collections(db),
    by = "collection_id"
)
## # A tibble: 22 × 18
##    collection_id    collection_version_id collection_url consortia contact_email
##    <chr>            <chr>                 <chr>          <list>    <chr>        
##  1 a96133de-e951-4… d5424314-8912-47fa-9… https://cellx… <chr [1]> jklugham@bro…
##  2 6b701826-37bb-4… 551fc857-23de-4008-8… https://cellx… <chr [1]> astreets@ber…
##  3 bcb61471-2a44-4… 31eabd1a-1c09-4fd1-b… https://cellx… <chr [3]> [email protected]
##  4 0f528c8a-a25c-4… 50f9973a-b39d-404e-a… https://cellx… <chr [3]> [email protected]
##  5 625f6bf4-2f33-4… 69711362-2102-4908-9… https://cellx… <chr [1]> a5wang@healt…
##  6 380ade76-e561-4… 64ec7b81-1f41-4e55-9… https://cellx… <chr [1]> mengjiechen@…
##  7 3c4f0970-7614-4… eddf9dec-a5e0-4505-8… https://cellx… <lgl [1]> alexmascensi…
##  8 e1fa9900-3fc9-4… 36a1bb28-08d4-4b3f-a… https://cellx… <lgl [1]> [email protected]
##  9 a98b828a-622a-4… 4ceec425-3a7a-4207-a… https://cellx… <chr [1]> markusbi@med…
## 10 4c6eaf5c-6d57-4… d0de2705-a59f-4ce7-9… https://cellx… <chr [2]> ruichen@bcm.…
## # ℹ 12 more rows
## # ℹ 13 more variables: contact_name <chr>, curator_name <chr>,
## #   description <chr>, doi <chr>, links <list>, name <chr>,
## #   publisher_metadata <list>, revising_in <lgl>, revision_of <lgl>,
## #   visibility <chr>, created_at <date>, published_at <date>, revised_at <date>

Publication and other external data

Many collections include publication information and other external data. This information is available in the return value of collections(), but the helper function publisher_metadata(), authors(), and links() may facilitate access.

Suppose one is interested in the publication “A single-cell atlas of the healthy breast tissues reveals clinically relevant clusters of breast epithelial cells”. Discover it in the collections

title_of_interest <- paste(
    "A single-cell atlas of the healthy breast tissues reveals clinically",
    "relevant clusters of breast epithelial cells"
)
collection_of_interest <-
    collections(db) |>
    dplyr::filter(startsWith(name, title_of_interest))
collection_of_interest |>
    glimpse()
## Rows: 1
## Columns: 18
## $ collection_id         <chr> "c9706a92-0e5f-46c1-96d8-20e42467f287"
## $ collection_version_id <chr> "76a5356b-8091-453b-9e55-e9b25e330b5a"
## $ collection_url        <chr> "https://cellxgene.cziscience.com/collections/c9…
## $ consortia             <list> "CZI Cell Science"
## $ contact_email         <chr> "[email protected]"
## $ contact_name          <chr> "Harikrishna Nakshatri"
## $ curator_name          <chr> "Jennifer Yu-Sheng Chien"
## $ description           <chr> "Single-cell RNA sequencing (scRNA-seq) is an ev…
## $ doi                   <chr> "10.1016/j.xcrm.2021.100219"
## $ links                 <list> [["", "RAW_DATA", "https://explore.data.humancel…
## $ name                  <chr> "A single-cell atlas of the healthy breast tiss…
## $ publisher_metadata    <list> [[["Bhat-Nakshatri", "Poornima"], ["Gao", "Hongy…
## $ revising_in           <lgl> NA
## $ revision_of           <lgl> NA
## $ visibility            <chr> "PUBLIC"
## $ created_at            <date> 2024-10-06
## $ published_at          <date> 2021-03-25
## $ revised_at            <date> 2024-10-10

Use the collection_id to extract publisher metadata (including a DOI if available) and author information

collection_id_of_interest <- pull(collection_of_interest, "collection_id")
publisher_metadata(db) |>
    filter(collection_id == collection_id_of_interest) |>
    glimpse()
## Rows: 1
## Columns: 9
## $ collection_id   <chr> "c9706a92-0e5f-46c1-96d8-20e42467f287"
## $ name            <chr> "A single-cell atlas of the healthy breast tissues rev…
## $ is_preprint     <lgl> FALSE
## $ journal         <chr> "Cell Reports Medicine"
## $ published_at    <date> 2021-03-01
## $ published_year  <int> 2021
## $ published_month <int> 3
## $ published_day   <int> 1
## $ doi             <chr> NA
authors(db) |>
    filter(collection_id == collection_id_of_interest)
## # A tibble: 12 × 4
##    collection_id                        family         given       consortium
##    <chr>                                <chr>          <chr>       <chr>     
##  1 c9706a92-0e5f-46c1-96d8-20e42467f287 Bhat-Nakshatri Poornima    <NA>      
##  2 c9706a92-0e5f-46c1-96d8-20e42467f287 Gao            Hongyu      <NA>      
##  3 c9706a92-0e5f-46c1-96d8-20e42467f287 Sheng          Liu         <NA>      
##  4 c9706a92-0e5f-46c1-96d8-20e42467f287 McGuire        Patrick C.  <NA>      
##  5 c9706a92-0e5f-46c1-96d8-20e42467f287 Xuei           Xiaoling    <NA>      
##  6 c9706a92-0e5f-46c1-96d8-20e42467f287 Wan            Jun         <NA>      
##  7 c9706a92-0e5f-46c1-96d8-20e42467f287 Liu            Yunlong     <NA>      
##  8 c9706a92-0e5f-46c1-96d8-20e42467f287 Althouse       Sandra K.   <NA>      
##  9 c9706a92-0e5f-46c1-96d8-20e42467f287 Colter         Austyn      <NA>      
## 10 c9706a92-0e5f-46c1-96d8-20e42467f287 Sandusky       George      <NA>      
## 11 c9706a92-0e5f-46c1-96d8-20e42467f287 Storniolo      Anna Maria  <NA>      
## 12 c9706a92-0e5f-46c1-96d8-20e42467f287 Nakshatri      Harikrishna <NA>

Collections may have links to additional external data, in this case a DOI and two links to RAW_DATA.

external_links <- links(db)
external_links
## # A tibble: 888 × 4
##    collection_id                        link_name link_type link_url            
##    <chr>                                <chr>     <chr>     <chr>               
##  1 2902f08c-f83c-470e-a541-e463e25e5058 <NA>      OTHER     http://cells.ucsc.e…
##  2 2902f08c-f83c-470e-a541-e463e25e5058 <NA>      RAW_DATA  https://explore.dat…
##  3 2902f08c-f83c-470e-a541-e463e25e5058 Github    OTHER     https://github.com/…
##  4 2902f08c-f83c-470e-a541-e463e25e5058 GSE118127 RAW_DATA  https://www.ncbi.nl…
##  5 180bff9c-c8a5-4539-b13b-ddbc00d643e6 GSE147528 RAW_DATA  https://www.ncbi.nl…
##  6 180bff9c-c8a5-4539-b13b-ddbc00d643e6 <NA>      OTHER     https://kampmannlab…
##  7 180bff9c-c8a5-4539-b13b-ddbc00d643e6 Synapse   OTHER     https://www.synapse…
##  8 180bff9c-c8a5-4539-b13b-ddbc00d643e6 <NA>      RAW_DATA  https://explore.dat…
##  9 02b01703-bf1b-48de-b99a-23bef8cccc81 <NA>      OTHER     https://singlecell.…
## 10 02b01703-bf1b-48de-b99a-23bef8cccc81 <NA>      OTHER     https://github.com/…
## # ℹ 878 more rows
external_links |>
    count(link_type)
## # A tibble: 5 × 2
##   link_type       n
##   <chr>       <int>
## 1 DATA_SOURCE    58
## 2 LAB_WEBSITE    46
## 3 OTHER         382
## 4 PROTOCOL       52
## 5 RAW_DATA      350
external_links |>
    filter(collection_id == collection_id_of_interest)
## # A tibble: 2 × 4
##   collection_id                        link_name link_type link_url             
##   <chr>                                <chr>     <chr>     <chr>                
## 1 c9706a92-0e5f-46c1-96d8-20e42467f287 <NA>      RAW_DATA  https://explore.data…
## 2 c9706a92-0e5f-46c1-96d8-20e42467f287 <NA>      RAW_DATA  https://www.ncbi.nlm…

Conversely, knowledge of a DOI, etc., can be used to discover details of the corresponding collection.

doi_of_interest <- "https://doi.org/10.1016/j.stem.2018.12.011"
links(db) |>
    filter(link_url == doi_of_interest) |>
    left_join(collections(db), by = "collection_id") |>
    glimpse()
## Rows: 1
## Columns: 21
## $ collection_id         <chr> "b1a879f6-5638-48d3-8f64-f6592c1b1561"
## $ link_name             <chr> "PSC-ATO protocol"
## $ link_type             <chr> "PROTOCOL"
## $ link_url              <chr> "https://doi.org/10.1016/j.stem.2018.12.011"
## $ collection_version_id <chr> "f83b41a4-72a6-468b-8009-77a1b114687d"
## $ collection_url        <chr> "https://cellxgene.cziscience.com/collections/b1…
## $ consortia             <list> <"CZI Cell Science", "Wellcome HCA Strategic Sci…
## $ contact_email         <chr> "[email protected]"
## $ contact_name          <chr> "Sarah Teichmann"
## $ curator_name          <chr> "Batuhan Cakir"
## $ description           <chr> "Single-cell genomics studies have decoded the i…
## $ doi                   <chr> "10.1126/science.abo0510"
## $ links                 <list> [["scVI Models", "DATA_SOURCE", "https://develop…
## $ name                  <chr> "Mapping the developing human immune system acro…
## $ publisher_metadata    <list> [[["Suo", "Chenqu"], ["Dann", "Emma"], ["Goh", "…
## $ revising_in           <lgl> NA
## $ revision_of           <lgl> NA
## $ visibility            <chr> "PUBLIC"
## $ created_at            <date> 2024-10-23
## $ published_at          <date> 2022-10-04
## $ revised_at            <date> 2024-10-28

Visualizing data in cellxgene

Visualization is straight-forward once dataset_id is available. For example, to visualize the first dataset in african_american_female, use

african_american_female |>
    ## use criteria to identify a single dataset (here just the
    ## 'first' dataset), then visualize
    slice(1) |>
    datasets_visualize()

Visualization is an interactive process, so datasets_visualize() will only open up to 5 browser tabs per call.

File download and use

Datasets usually contain H5AD (files produced by the python AnnData module), and Rds (serialized files produced by the R Seurat package). The Rds files may be unreadable if the version of Seurat used to create the file is different from the version used to read the file. We therefore focus on the H5AD files.

For illustration, we find all files associated with studies with African American females

download one of our selected files.

selected_files <-
    left_join(
        african_american_female |> select(dataset_id),
        files(db),
        by = "dataset_id"
    )

And then choose a single dataset and its H5AD file for download

local_file <-
    selected_files |>
    filter(
        dataset_id == "de985818-285f-4f59-9dbd-d74968fddba3",
        filetype == "H5AD"
    ) |>
    files_download(dry.run = FALSE)
basename(local_file)
## [1] "80aa80bd-e935-4f4d-a9c9-ec072dbe30ed.h5ad"

These are downloaded to a local cache (use the internal function cellxgenedp:::.cellxgenedb_cache_path() for the location of the cache), so the process is only time-consuming the first time.

H5AD files can be converted to R / Bioconductor objects using the zellkonverter package.

h5ad <- readH5AD(local_file, use_hdf5 = TRUE, reader = "R")
h5ad
## class: SingleCellExperiment 
## dim: 33159 31696 
## metadata(5): citation default_embedding schema_reference schema_version
##   title
## assays(1): X
## rownames(33159): ENSG00000243485 ENSG00000237613 ... ENSG00000277475
##   ENSG00000268674
## rowData names(6): feature_is_filtered feature_name ... feature_length
##   feature_type
## colnames(31696): CMGpool_AAACCCAAGGACAACC CMGpool_AAACCCACAATCTCTT ...
##   K109064_TTTGTTGGTTGCATCA K109064_TTTGTTGGTTGGACCC
## colData names(45): mapped_reference_annotation donor_id ...
##   development_stage observation_joinid
## reducedDimNames(3): X_pca X_tsne X_umap
## mainExpName: NULL
## altExpNames(0):

The SingleCellExperiment object is a matrix-like object with rows corresponding to genes and columns to cells. Thus we can easily explore the cells present in the data.

h5ad |>
    colData(h5ad) |>
    as_tibble() |>
    count(sex, donor_id)
## # A tibble: 7 × 3
##   sex    donor_id                     n
##   <fct>  <fct>                    <int>
## 1 female D1                        2303
## 2 female D2                         864
## 3 female D3                        2517
## 4 female D4                        1771
## 5 female D5                        2244
## 6 female D11                       7454
## 7 female pooled [D9,D7,D8,D10,D6] 14543

Next steps

The Orchestrating Single-Cell Analysis with Bioconductor online resource provides an excellent introduction to analysis and visualization of single-cell data in R / Bioconductor. Extensive opportunities for working with AnnData objects in R but using the native python interface are briefly described in, e.g., ?AnnData2SCE help page of zellkonverter.

The hca package provides programmatic access to the Human Cell Atlas data portal, allowing retrieval of primary as well as derived single-cell data files.

API changes

Data access provided by CELLxGENE has changed to a new ‘Discover’ API. The main functionality of the cellxgenedp package has not changed, but specific columns have been removed, replaced or added, as follows:

collections()

  • Removed: access_type, data_submission_policy_version
  • Replaced: updated_at replaced with revised_at
  • Added: collection_version_id, collection_url, doi, revising_in, revision_of

datasets()

  • Removed: is_valid, processing_status, published, revision, created_at
  • Replaced: dataset_deployments replaced with explorer_url, name replaced with title, updated_at replaced with revised_at
  • Added: dataset_version_id, batch_condition, x_approximate_distribution

files()

  • Removed: file_id, filename, s3_uri, user_submitted, created_at, updated_at
  • Added: filesize, url

Session info

## R version 4.4.1 (2024-06-14)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.1 LTS
## 
## Matrix products: default
## BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so;  LAPACK version 3.12.0
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=C              
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## time zone: Etc/UTC
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats4    stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] cellxgenedp_1.11.0          dplyr_1.1.4                
##  [3] SingleCellExperiment_1.27.2 SummarizedExperiment_1.35.5
##  [5] Biobase_2.65.1              GenomicRanges_1.57.2       
##  [7] GenomeInfoDb_1.41.2         IRanges_2.39.2             
##  [9] S4Vectors_0.43.2            BiocGenerics_0.51.3        
## [11] MatrixGenerics_1.17.1       matrixStats_1.4.1          
## [13] zellkonverter_1.15.4        BiocStyle_2.33.1           
## 
## loaded via a namespace (and not attached):
##  [1] dir.expiry_1.13.1       xfun_0.48               bslib_0.8.0            
##  [4] htmlwidgets_1.6.4       rhdf5_2.49.0            lattice_0.22-6         
##  [7] rhdf5filters_1.17.0     rjsoncons_1.3.1         vctrs_0.6.5            
## [10] tools_4.4.1             generics_0.1.3          curl_5.2.3             
## [13] parallel_4.4.1          tibble_3.2.1            fansi_1.0.6            
## [16] pkgconfig_2.0.3         Matrix_1.7-1            lifecycle_1.0.4        
## [19] GenomeInfoDbData_1.2.13 compiler_4.4.1          httpuv_1.6.15          
## [22] htmltools_0.5.8.1       sys_3.4.3               buildtools_1.0.0       
## [25] sass_0.4.9              yaml_2.3.10             later_1.3.2            
## [28] pillar_1.9.0            crayon_1.5.3            jquerylib_0.1.4        
## [31] DT_0.33                 DelayedArray_0.31.14    cachem_1.1.0           
## [34] abind_1.4-8             mime_0.12               basilisk_1.17.2        
## [37] tidyselect_1.2.1        digest_0.6.37           maketools_1.3.1        
## [40] fastmap_1.2.0           grid_4.4.1              cli_3.6.3              
## [43] SparseArray_1.5.45      magrittr_2.0.3          S4Arrays_1.5.11        
## [46] utf8_1.2.4              withr_3.0.2             promises_1.3.0         
## [49] filelock_1.0.3          UCSC.utils_1.1.0        rmarkdown_2.28         
## [52] XVector_0.45.0          httr_1.4.7              reticulate_1.39.0      
## [55] png_0.1-8               HDF5Array_1.33.8        shiny_1.9.1            
## [58] evaluate_1.0.1          knitr_1.48              basilisk.utils_1.19.0  
## [61] rlang_1.1.4             Rcpp_1.0.13             xtable_1.8-4           
## [64] glue_1.8.0              BiocManager_1.30.25     jsonlite_1.8.9         
## [67] Rhdf5lib_1.27.0         R6_2.5.1                zlibbioc_1.51.2