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

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(): 200
## number of datasets(): 1319
## number of files(): 2606

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

collections(db)
## # A tibble: 200 × 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 f5af7a2f-ab4c-4… cb80d978-a1a2-4696-8… https://cellx… <lgl [1]> Yanling_Liao…
##  3 aee9c366-f2fb-4… 62fc92b9-92f9-4f6f-9… https://cellx… <lgl [1]> kjensen@tgen…
##  4 e5f58829-1a66-4… 519f5ac5-1f84-4b48-9… https://cellx… <chr [2]> angela.pisco…
##  5 b52eb423-5d0d-4… e75822ca-72d5-4d7f-a… https://cellx… <chr [2]> st9@sanger.a…
##  6 e3aa612b-0d7d-4… 8bfe4964-eab1-4ae8-b… https://cellx… <chr [1]> hongkuiz@all…
##  7 1b014f39-f202-4… 8b7765f4-c81a-46fe-a… https://cellx… <lgl [1]> kimberly.ald…
##  8 48d354f5-a5ca-4… be9483df-dbbd-421f-b… https://cellx… <chr [1]> Nathan.Salom…
##  9 37f1f46d-6dfa-4… 55fe1b45-a16f-4d6c-a… https://cellx… <lgl [1]> ecker@salk.e…
## 10 e2a4a67f-6a18-4… ba625d7c-6e3d-4737-9… https://cellx… <chr [1]> Douglas.Stra…
## # ℹ 190 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,319 × 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 7be2824e-d6… cdc5c7db-c0c1-4b3… f5af7a2f-ab4… <chr>    <list> <chr [1]>      
##  4 6beff4d6-98… d0a58fe9-66f2-4e6… f5af7a2f-ab4… <chr>    <list> <chr [1]>      
##  5 5bc26721-89… 0e06a616-7910-45d… f5af7a2f-ab4… <chr>    <list> <chr [1]>      
##  6 389b1fd4-2b… 40c52755-6725-4f7… f5af7a2f-ab4… <chr>    <list> <chr [1]>      
##  7 1398f3a9-b4… 5d1600bf-6e8a-435… f5af7a2f-ab4… <chr>    <list> <chr [1]>      
##  8 e6361237-ac… 73abacb7-7914-4cb… aee9c366-f2f… <chr>    <list> <lgl [1]>      
##  9 98f5d518-1e… 7192cf6c-ef41-4a3… aee9c366-f2f… <chr>    <list> <lgl [1]>      
## 10 3b8b5de4-3a… f249d65b-8400-468… aee9c366-f2f… <chr>    <list> <lgl [1]>      
## # ℹ 1,309 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,606 × 4
##    dataset_id                            filesize filetype url                  
##    <chr>                                    <dbl> <chr>    <chr>                
##  1 595c9010-99ec-462d-b6a1-2b2fe5407871 333391557 H5AD     https://datasets.cel…
##  2 595c9010-99ec-462d-b6a1-2b2fe5407871 348066008 RDS      https://datasets.cel…
##  3 2f05ab20-a092-4bab-9276-3e0eb24e3fee 630668977 H5AD     https://datasets.cel…
##  4 2f05ab20-a092-4bab-9276-3e0eb24e3fee 683935787 RDS      https://datasets.cel…
##  5 7be2824e-d62a-42ef-9169-084555c6df87 110941688 H5AD     https://datasets.cel…
##  6 7be2824e-d62a-42ef-9169-084555c6df87  72209932 RDS      https://datasets.cel…
##  7 6beff4d6-98a8-4f49-8ba7-84d152494a23  77144105 H5AD     https://datasets.cel…
##  8 6beff4d6-98a8-4f49-8ba7-84d152494a23  24129997 RDS      https://datasets.cel…
##  9 5bc26721-894b-4e9a-9423-6ecfd233ab20  60237039 H5AD     https://datasets.cel…
## 10 5bc26721-894b-4e9a-9423-6ecfd233ab20  26206324 RDS      https://datasets.cel…
## # ℹ 2,596 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,319 × 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 [4]>  <list [1]> <chr [1]>       <list [11]> <list [1]>        <list> 
##  4 <chr [4]>  <list [1]> <chr [1]>       <list [1]>  <list [1]>        <list> 
##  5 <chr [4]>  <list [1]> <chr [1]>       <list [1]>  <list [1]>        <list> 
##  6 <chr [4]>  <list [1]> <chr [1]>       <list [9]>  <list [1]>        <list> 
##  7 <chr [4]>  <list [1]> <chr [1]>       <list [4]>  <list [1]>        <list> 
##  8 <chr [14]> <list [1]> <lgl [1]>       <list [6]>  <list [14]>       <list> 
##  9 <chr [21]> <list [1]> <lgl [1]>       <list [6]>  <list [15]>       <list> 
## 10 <chr [16]> <list [1]> <lgl [1]>       <list [6]>  <list [16]>       <list> 
## # ℹ 1,309 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        611
##  2 assay 10x 3' v2                      EFO:0009899        275
##  3 assay Slide-seqV2                    EFO:0030062        223
##  4 assay Visium Spatial Gene Expression EFO:0010961        161
##  5 assay 10x 5' v1                      EFO:0011025         91
##  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     545
##  2 self_reported_ethnicity unknown                        unknown            468
##  3 self_reported_ethnicity na                             na                 376
##  4 self_reported_ethnicity Asian                          HANCESTRO:0008     144
##  5 self_reported_ethnicity Hispanic or Latin American     HANCESTRO:0014      64
##  6 self_reported_ethnicity African American               HANCESTRO:0568      63
##  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      1015
## 2 sex   female  PATO:0000383       773
## 3 sex   unknown unknown            194

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          4528024

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: 15 × 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 6b701826-37bb-4… d0722128-9bd2-4c62-8… https://cellx… <chr [1]> astreets@ber…
##  5 3c4f0970-7614-4… a6c2ae16-2e0b-4f62-a… https://cellx… <lgl [1]> alexmascensi…
##  6 f17b9205-f61f-4… 87279d9b-8ab2-4e10-9… https://cellx… <chr [1]> genevieve.ko…
##  7 cec4ef8e-1e70-4… 7b72315c-9210-459a-b… https://cellx… <lgl [1]> Ryan.Logan@u…
##  8 bcb61471-2a44-4… 447d101d-5306-4321-a… https://cellx… <chr [3]> info@kpmp.org
##  9 c9706a92-0e5f-4… 04464954-ab11-4a56-b… https://cellx… <chr [1]> hnakshat@iup…
## 10 72d37bc9-76cc-4… e95dbb27-c619-4f2d-9… https://cellx… <chr [1]> m.sepp@zmbh.…
## 11 625f6bf4-2f33-4… fb5e1588-a7ee-41d6-a… https://cellx… <chr [1]> a5wang@healt…
## 12 e1fa9900-3fc9-4… 93bc2a17-6fb0-4329-9… https://cellx… <lgl [1]> j.ma@yale.edu
## 13 a98b828a-622a-4… 93db548a-c8de-4581-a… https://cellx… <chr [1]> markusbi@med…
## 14 b953c942-f5d8-4… 4ac10bd3-3a86-4356-b… https://cellx… <lgl [1]> icobos@stanf…
## 15 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 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> "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: 781 × 4
##    collection_id                        link_name             link_type link_url
##    <chr>                                <chr>                 <chr>     <chr>   
##  1 59c9ecfe-c47d-4a6a-bab0-895cc0c1942b GSE159812             RAW_DATA  https:/…
##  2 59c9ecfe-c47d-4a6a-bab0-895cc0c1942b <NA>                  DATA_SOU… https:/…
##  3 59c9ecfe-c47d-4a6a-bab0-895cc0c1942b <NA>                  LAB_WEBS… https:/…
##  4 59c9ecfe-c47d-4a6a-bab0-895cc0c1942b <NA>                  LAB_WEBS… https:/…
##  5 59c9ecfe-c47d-4a6a-bab0-895cc0c1942b <NA>                  RAW_DATA  https:/…
##  6 f5af7a2f-ab4c-4728-829e-48efb9562105 GSE222250             RAW_DATA  https:/…
##  7 aee9c366-f2fb-470b-8937-577d5d87d3fc Synapse               RAW_DATA  https:/…
##  8 e5f58829-1a66-40b5-a624-9046778e74f5 <NA>                  RAW_DATA  https:/…
##  9 e5f58829-1a66-40b5-a624-9046778e74f5 Tabula Sapiens Portal OTHER     https:/…
## 10 e5f58829-1a66-40b5-a624-9046778e74f5 <NA>                  OTHER     https:/…
## # ℹ 771 more rows
external_links |>
    count(link_type)
## # A tibble: 5 × 2
##   link_type       n
##   <chr>       <int>
## 1 DATA_SOURCE    37
## 2 LAB_WEBSITE    42
## 3 OTHER         351
## 4 PROTOCOL       45
## 5 RAW_DATA      306
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.4.0 RC (2024-04-16 r86468)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 22.04.4 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.20-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.9.0           dplyr_1.1.4                
##  [3] SingleCellExperiment_1.27.0 SummarizedExperiment_1.35.0
##  [5] Biobase_2.65.0              GenomicRanges_1.57.0       
##  [7] GenomeInfoDb_1.41.0         IRanges_2.39.0             
##  [9] S4Vectors_0.43.0            BiocGenerics_0.51.0        
## [11] MatrixGenerics_1.17.0       matrixStats_1.3.0          
## [13] zellkonverter_1.15.0        BiocStyle_2.33.0           
## 
## loaded via a namespace (and not attached):
##  [1] dir.expiry_1.13.0       xfun_0.43               bslib_0.7.0            
##  [4] htmlwidgets_1.6.4       rhdf5_2.49.0            lattice_0.22-6         
##  [7] rhdf5filters_1.17.0     rjsoncons_1.3.0         vctrs_0.6.5            
## [10] tools_4.4.0             generics_0.1.3          curl_5.2.1             
## [13] parallel_4.4.0          tibble_3.2.1            fansi_1.0.6            
## [16] pkgconfig_2.0.3         Matrix_1.7-0            lifecycle_1.0.4        
## [19] GenomeInfoDbData_1.2.12 compiler_4.4.0          httpuv_1.6.15          
## [22] htmltools_0.5.8.1       sass_0.4.9              yaml_2.3.8             
## [25] later_1.3.2             pillar_1.9.0            crayon_1.5.2           
## [28] jquerylib_0.1.4         DT_0.33                 DelayedArray_0.31.0    
## [31] cachem_1.0.8            abind_1.4-5             mime_0.12              
## [34] basilisk_1.17.0         tidyselect_1.2.1        digest_0.6.35          
## [37] bookdown_0.39           fastmap_1.1.1           grid_4.4.0             
## [40] cli_3.6.2               SparseArray_1.5.0       magrittr_2.0.3         
## [43] S4Arrays_1.5.0          utf8_1.2.4              withr_3.0.0            
## [46] promises_1.3.0          filelock_1.0.3          UCSC.utils_1.1.0       
## [49] rmarkdown_2.26          XVector_0.45.0          httr_1.4.7             
## [52] reticulate_1.36.1       png_0.1-8               HDF5Array_1.33.0       
## [55] shiny_1.8.1.1           evaluate_0.23           knitr_1.46             
## [58] basilisk.utils_1.17.0   rlang_1.1.3             Rcpp_1.0.12            
## [61] xtable_1.8-4            glue_1.7.0              BiocManager_1.30.22    
## [64] jsonlite_1.8.8          Rhdf5lib_1.27.0         R6_2.5.1               
## [67] zlibbioc_1.51.0