Contents

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.

1 Installation and use

This package is available in Bioconductor version 3.15 and later. The following code installs cellxgenedp as well as other packages required for this vignette.

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

Use the following pkgs vector to install from GitHub (latest, unchecked, development version) instead

pkgs <- c(
    "mtmorgan/cellxgenedp", "zellkonverter", "SingleCellExperiment", "HDF5Array"
)

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.

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

2 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!

3 Collections, datasets and files

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

db <- db()

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(): 195
## number of datasets(): 1275
## number of files(): 2518

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

collections(db)
## # A tibble: 195 × 18
##    collection_id    collection_version_id collection_url consortia contact_email
##    <chr>            <chr>                 <chr>          <list>    <chr>        
##  1 59c9ecfe-c47d-4… 8db59637-4b42-4195-b… https://cellx… <lgl [1]> twc@stanford…
##  2 a18474f4-ff1e-4… e1078e5b-da88-49d8-b… https://cellx… <lgl [1]> kpn2114@colu…
##  3 f5af7a2f-ab4c-4… cb80d978-a1a2-4696-8… https://cellx… <lgl [1]> Yanling_Liao…
##  4 aee9c366-f2fb-4… 62fc92b9-92f9-4f6f-9… https://cellx… <lgl [1]> kjensen@tgen…
##  5 e5f58829-1a66-4… 519f5ac5-1f84-4b48-9… https://cellx… <chr [2]> angela.pisco…
##  6 b52eb423-5d0d-4… e75822ca-72d5-4d7f-a… https://cellx… <chr [2]> st9@sanger.a…
##  7 e3aa612b-0d7d-4… 8bfe4964-eab1-4ae8-b… https://cellx… <chr [1]> hongkuiz@all…
##  8 1b014f39-f202-4… 8b7765f4-c81a-46fe-a… https://cellx… <lgl [1]> kimberly.ald…
##  9 48d354f5-a5ca-4… be9483df-dbbd-421f-b… https://cellx… <chr [1]> Nathan.Salom…
## 10 37f1f46d-6dfa-4… 55fe1b45-a16f-4d6c-a… https://cellx… <lgl [1]> ecker@salk.e…
## # ℹ 185 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,275 × 32
##    dataset_id   dataset_version_id collection_id donor_id assay  batch_condition
##    <chr>        <chr>              <chr>         <list>   <list> <list>         
##  1 595c9010-99… b4645848-e3d8-492… 59c9ecfe-c47… <chr>    <list> <lgl [1]>      
##  2 2f05ab20-a0… 3b715360-b0ae-4e5… 59c9ecfe-c47… <chr>    <list> <lgl [1]>      
##  3 faed4f71-6b… 1cd4f84b-7fe4-463… a18474f4-ff1… <chr>    <list> <lgl [1]>      
##  4 e5233a94-9e… 80d1f22a-8f51-49d… a18474f4-ff1… <chr>    <list> <lgl [1]>      
##  5 9b188f26-c8… 1c158adf-90ea-47b… a18474f4-ff1… <chr>    <list> <lgl [1]>      
##  6 94423ec1-21… 7c4220a8-ce41-49f… a18474f4-ff1… <chr>    <list> <lgl [1]>      
##  7 7bb64315-9e… 9ec33c56-14a4-481… a18474f4-ff1… <chr>    <list> <lgl [1]>      
##  8 773b9b2e-70… f186deb1-4926-404… a18474f4-ff1… <chr>    <list> <lgl [1]>      
##  9 63bb6359-39… a5df7f5b-34d8-421… a18474f4-ff1… <chr>    <list> <lgl [1]>      
## 10 03d5794d-cd… 8db806f1-a518-4a2… a18474f4-ff1… <chr>    <list> <lgl [1]>      
## # ℹ 1,265 more rows
## # ℹ 26 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,518 × 4
##    dataset_id                             filesize filetype url                 
##    <chr>                                     <dbl> <chr>    <chr>               
##  1 595c9010-99ec-462d-b6a1-2b2fe5407871  333391557 H5AD     https://datasets.ce…
##  2 595c9010-99ec-462d-b6a1-2b2fe5407871  348066008 RDS      https://datasets.ce…
##  3 2f05ab20-a092-4bab-9276-3e0eb24e3fee  630668977 H5AD     https://datasets.ce…
##  4 2f05ab20-a092-4bab-9276-3e0eb24e3fee  683935787 RDS      https://datasets.ce…
##  5 faed4f71-6b50-4fc7-bd1c-8f385dccfdce   31737910 H5AD     https://datasets.ce…
##  6 faed4f71-6b50-4fc7-bd1c-8f385dccfdce   26350706 RDS      https://datasets.ce…
##  7 e5233a94-9e43-418c-8209-6f1400c31530 1321449650 H5AD     https://datasets.ce…
##  8 e5233a94-9e43-418c-8209-6f1400c31530 1311136088 RDS      https://datasets.ce…
##  9 9b188f26-c8e1-4a78-af15-622a35a371fc   36324999 H5AD     https://datasets.ce…
## 10 9b188f26-c8e1-4a78-af15-622a35a371fc   30585807 RDS      https://datasets.ce…
## # ℹ 2,508 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.

3.1 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> "c9c120ca-7605-43b0-9ef5-728392d708f5"
## $ collection_url        <chr> "https://cellxgene.cziscience.com/collections/28…
## $ consortia             <list> <"BRAIN Initiative", "CZI Single-Cell Biology">
## $ contact_email         <chr> "kimberly.siletti@ki.se"
## $ 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-03-19
## $ published_at          <date> 2022-12-09
## $ revised_at            <date> 2024-03-22

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 × 32
##    collection_id   dataset_id dataset_version_id donor_id assay  batch_condition
##    <chr>           <chr>      <chr>              <list>   <list> <list>         
##  1 283d65eb-dd53-… ff7d15fa-… 1846f7ed-d11e-44f… <chr>    <list> <chr [1]>      
##  2 283d65eb-dd53-… fe1a73ab-… 5e5db76a-4390-41a… <chr>    <list> <chr [1]>      
##  3 283d65eb-dd53-… fbf173f9-… a7334adc-f8e7-443… <chr>    <list> <chr [1]>      
##  4 283d65eb-dd53-… fa554686-… 9bc5af53-e980-484… <chr>    <list> <chr [1]>      
##  5 283d65eb-dd53-… f9034091-… 71809c6b-c83a-497… <chr>    <list> <chr [1]>      
##  6 283d65eb-dd53-… f8dda921-… 4fc4d6fb-f105-4f9… <chr>    <list> <chr [1]>      
##  7 283d65eb-dd53-… f7d003d4-… c8b0535b-bc4f-478… <chr>    <list> <chr [1]>      
##  8 283d65eb-dd53-… f6d9f2ad-… dc08c31c-6629-49d… <chr>    <list> <chr [1]>      
##  9 283d65eb-dd53-… f5a04dff-… 2e56729d-ee10-419… <chr>    <list> <chr [1]>      
## 10 283d65eb-dd53-… f502c312-… a3fa88de-cbbe-404… <chr>    <list> <chr [1]>      
## # ℹ 128 more rows
## # ℹ 26 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>, …

3.2 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,275 × 15
##    donor_id   assay      batch_condition cell_type   development_stage disease
##    <list>     <list>     <list>          <list>      <list>            <list> 
##  1 <chr [14]> <list [1]> <lgl [1]>       <list [7]>  <list [13]>       <list> 
##  2 <chr [16]> <list [1]> <lgl [1]>       <list [13]> <list [14]>       <list> 
##  3 <chr [39]> <list [2]> <lgl [1]>       <list [3]>  <list [25]>       <list> 
##  4 <chr [43]> <list [2]> <lgl [1]>       <list [31]> <list [28]>       <list> 
##  5 <chr [37]> <list [2]> <lgl [1]>       <list [1]>  <list [23]>       <list> 
##  6 <chr [42]> <list [2]> <lgl [1]>       <list [5]>  <list [27]>       <list> 
##  7 <chr [70]> <list [3]> <lgl [1]>       <list [31]> <list [39]>       <list> 
##  8 <chr [42]> <list [2]> <lgl [1]>       <list [10]> <list [27]>       <list> 
##  9 <chr [41]> <list [2]> <lgl [1]>       <list [7]>  <list [26]>       <list> 
## 10 <chr [40]> <list [2]> <lgl [1]>       <list [4]>  <list [26]>       <list> 
## # ℹ 1,265 more rows
## # ℹ 9 more variables: embeddings <list>, feature_biotype <list>,
## #   feature_reference <list>, is_primary_data <list>, organism <list>,
## #   self_reported_ethnicity <list>, sex <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: 38 × 4
##    facet label                          ontology_term_id     n
##    <chr> <chr>                          <chr>            <int>
##  1 assay 10x 3' v3                      EFO:0009922        597
##  2 assay 10x 3' v2                      EFO:0009899        271
##  3 assay Slide-seqV2                    EFO:0030062        223
##  4 assay Visium Spatial Gene Expression EFO:0010961        131
##  5 assay 10x 5' v1                      EFO:0011025         90
##  6 assay Smart-seq2                     EFO:0008931         63
##  7 assay 10x multiome                   EFO:0030059         62
##  8 assay sci-RNA-seq                    EFO:0010550         33
##  9 assay 10x 5' v2                      EFO:0009900         24
## 10 assay 10x 5' transcription profiling EFO:0030004         21
## # ℹ 28 more rows
facets(db, "self_reported_ethnicity")
## # A tibble: 33 × 4
##    facet                   label                          ontology_term_id     n
##    <chr>                   <chr>                          <chr>            <int>
##  1 self_reported_ethnicity European                       HANCESTRO:0005     544
##  2 self_reported_ethnicity unknown                        unknown            434
##  3 self_reported_ethnicity na                             na                 366
##  4 self_reported_ethnicity Asian                          HANCESTRO:0008     143
##  5 self_reported_ethnicity Hispanic or Latin American     HANCESTRO:0014      63
##  6 self_reported_ethnicity African American               HANCESTRO:0568      62
##  7 self_reported_ethnicity Native American,Hispanic or L… HANCESTRO:0013,…    50
##  8 self_reported_ethnicity African American or Afro-Cari… HANCESTRO:0016      32
##  9 self_reported_ethnicity Greater Middle Eastern  (Midd… HANCESTRO:0015      22
## 10 self_reported_ethnicity African                        HANCESTRO:0010      19
## # ℹ 23 more rows
facets(db, "sex")
## # A tibble: 3 × 4
##   facet label   ontology_term_id     n
##   <chr> <chr>   <chr>            <int>
## 1 sex   male    PATO:0000384       986
## 2 sex   female  PATO:0000383       762
## 3 sex   unknown unknown            180

3.3 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          4419584

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: 14 × 18
##    collection_id    collection_version_id collection_url consortia contact_email
##    <chr>            <chr>                 <chr>          <list>    <chr>        
##  1 62e8f058-9c37-4… 645d7ef5-f8ab-4b40-8… https://cellx… <chr [1]> chanj3@mskcc…
##  2 4195ab4c-20bd-4… 4bb38c2f-9c6a-4895-b… https://cellx… <chr [1]> nnavin@mdand…
##  3 b9fc3d70-5a72-4… a73587fc-5019-46e2-a… https://cellx… <chr [1]> bruce.aronow…
##  4 f17b9205-f61f-4… 87279d9b-8ab2-4e10-9… https://cellx… <chr [1]> genevieve.ko…
##  5 cec4ef8e-1e70-4… 7b72315c-9210-459a-b… https://cellx… <lgl [1]> Ryan.Logan@u…
##  6 bcb61471-2a44-4… 447d101d-5306-4321-a… https://cellx… <chr [3]> info@kpmp.org
##  7 c9706a92-0e5f-4… 04464954-ab11-4a56-b… https://cellx… <chr [1]> hnakshat@iup…
##  8 72d37bc9-76cc-4… e95dbb27-c619-4f2d-9… https://cellx… <chr [1]> m.sepp@zmbh.…
##  9 625f6bf4-2f33-4… fb5e1588-a7ee-41d6-a… https://cellx… <chr [1]> a5wang@healt…
## 10 e1fa9900-3fc9-4… 93bc2a17-6fb0-4329-9… https://cellx… <lgl [1]> j.ma@yale.edu
## 11 a98b828a-622a-4… 93db548a-c8de-4581-a… https://cellx… <chr [1]> markusbi@med…
## 12 6b701826-37bb-4… d63af6c4-1427-4237-a… https://cellx… <chr [1]> astreets@ber…
## 13 b953c942-f5d8-4… 4ac10bd3-3a86-4356-b… https://cellx… <lgl [1]> icobos@stanf…
## 14 71f4bccf-53d4-4… 7a0d0734-79cc-48fd-9… https://cellx… <chr [1]> kevinmbyrd@g…
## # ℹ 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>

3.4 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 facilite 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> "04464954-ab11-4a56-b136-e924b750f1bd"
## $ collection_url        <chr> "https://cellxgene.cziscience.com/collections/c9…
## $ consortia             <list> "CZI Single-Cell Biology"
## $ contact_email         <chr> "hnakshat@iupui.edu"
## $ 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://data.humancellatlas.o…
## $ 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-03-19
## $ published_at          <date> 2021-03-25
## $ revised_at            <date> 2024-03-22

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: 770 × 4
##    collection_id                        link_name       link_type   link_url    
##    <chr>                                <chr>           <chr>       <chr>       
##  1 59c9ecfe-c47d-4a6a-bab0-895cc0c1942b GSE159812       RAW_DATA    https://www…
##  2 59c9ecfe-c47d-4a6a-bab0-895cc0c1942b <NA>            DATA_SOURCE https://twc…
##  3 59c9ecfe-c47d-4a6a-bab0-895cc0c1942b <NA>            LAB_WEBSITE https://www…
##  4 59c9ecfe-c47d-4a6a-bab0-895cc0c1942b <NA>            LAB_WEBSITE https://web…
##  5 59c9ecfe-c47d-4a6a-bab0-895cc0c1942b <NA>            RAW_DATA    https://dat…
##  6 a18474f4-ff1e-4864-af69-270b956cee5b EGAD00001010074 RAW_DATA    https://ega…
##  7 a18474f4-ff1e-4864-af69-270b956cee5b <NA>            OTHER       https://git…
##  8 f5af7a2f-ab4c-4728-829e-48efb9562105 GSE222250       RAW_DATA    https://www…
##  9 aee9c366-f2fb-470b-8937-577d5d87d3fc Synapse         RAW_DATA    https://www…
## 10 e5f58829-1a66-40b5-a624-9046778e74f5 <NA>            RAW_DATA    https://reg…
## # ℹ 760 more rows
external_links |>
    count(link_type)
## # A tibble: 5 × 2
##   link_type       n
##   <chr>       <int>
## 1 DATA_SOURCE    35
## 2 LAB_WEBSITE    41
## 3 OTHER         349
## 4 PROTOCOL       45
## 5 RAW_DATA      300
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://data.humance…
## 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> "1265f8ec-9918-499a-8b7d-ede70c8d77c0"
## $ collection_url        <chr> "https://cellxgene.cziscience.com/collections/b1…
## $ consortia             <list> <"CZI Single-Cell Biology", "Wellcome HCA Strate…
## $ contact_email         <chr> "st9@sanger.ac.uk"
## $ 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-03-19
## $ published_at          <date> 2022-10-04
## $ revised_at            <date> 2024-03-22

4 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.

5 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] "dba8eab1-fb75-4a40-be68-2bcd8094ac52.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: 33145 31696 
## metadata(5): citation default_embedding schema_reference schema_version
##   title
## assays(1): X
## rownames(33145): ENSG00000243485 ENSG00000237613 ... ENSG00000277475
##   ENSG00000268674
## rowData names(5): feature_is_filtered feature_name feature_reference
##   feature_biotype feature_length
## colnames(31696): CMGpool_AAACCCAAGGACAACC CMGpool_AAACCCACAATCTCTT ...
##   K109064_TTTGTTGGTTGCATCA K109064_TTTGTTGGTTGGACCC
## colData names(36): donor_id self_reported_ethnicity_ontology_term_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

6 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.

7 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()

datasets()

files()

Session info

## R version 4.3.3 (2024-02-29)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 22.04.4 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.18-bioc/R/lib/libRblas.so 
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_GB              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: America/New_York
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats4    stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] cellxgenedp_1.6.2           dplyr_1.1.4                
##  [3] SingleCellExperiment_1.24.0 SummarizedExperiment_1.32.0
##  [5] Biobase_2.62.0              GenomicRanges_1.54.1       
##  [7] GenomeInfoDb_1.38.8         IRanges_2.36.0             
##  [9] S4Vectors_0.40.2            BiocGenerics_0.48.1        
## [11] MatrixGenerics_1.14.0       matrixStats_1.2.0          
## [13] zellkonverter_1.12.1        BiocStyle_2.30.0           
## 
## loaded via a namespace (and not attached):
##  [1] dir.expiry_1.10.0       xfun_0.43               bslib_0.7.0            
##  [4] htmlwidgets_1.6.4       rhdf5_2.46.1            lattice_0.22-6         
##  [7] rhdf5filters_1.14.1     rjsoncons_1.2.0         vctrs_0.6.5            
## [10] tools_4.3.3             bitops_1.0-7            generics_0.1.3         
## [13] curl_5.2.1              parallel_4.3.3          tibble_3.2.1           
## [16] fansi_1.0.6             pkgconfig_2.0.3         Matrix_1.6-5           
## [19] lifecycle_1.0.4         GenomeInfoDbData_1.2.11 compiler_4.3.3         
## [22] httpuv_1.6.15           htmltools_0.5.8         sass_0.4.9             
## [25] RCurl_1.98-1.14         yaml_2.3.8              later_1.3.2            
## [28] pillar_1.9.0            crayon_1.5.2            jquerylib_0.1.4        
## [31] DT_0.32                 DelayedArray_0.28.0     cachem_1.0.8           
## [34] abind_1.4-5             mime_0.12               basilisk_1.14.3        
## [37] tidyselect_1.2.1        digest_0.6.35           bookdown_0.38          
## [40] fastmap_1.1.1           grid_4.3.3              cli_3.6.2              
## [43] SparseArray_1.2.4       magrittr_2.0.3          S4Arrays_1.2.1         
## [46] utf8_1.2.4              withr_3.0.0             promises_1.2.1         
## [49] filelock_1.0.3          httr_1.4.7              rmarkdown_2.26         
## [52] XVector_0.42.0          reticulate_1.35.0       png_0.1-8              
## [55] HDF5Array_1.30.1        shiny_1.8.1             evaluate_0.23          
## [58] knitr_1.45              basilisk.utils_1.14.1   rlang_1.1.3            
## [61] Rcpp_1.0.12             xtable_1.8-4            glue_1.7.0             
## [64] BiocManager_1.30.22     jsonlite_1.8.8          Rhdf5lib_1.24.2        
## [67] R6_2.5.1                zlibbioc_1.48.2