| Title: | Release-Aware Access to Allen Brain Cell Atlas Data |
|---|---|
| Description: | Provides an R-native, release-aware interface to the Allen Brain Cell (ABC) Atlas <https://brain-map.org/bkp/explore/abc-atlas>. Discovers supported dataset routes, assembles validated cell and gene metadata, reports the expression files and disk space a request needs, and reads the expression of selected cells and genes from H5AD files directly in R. Expression can be returned as a sparse matrix bundle, a SingleCellExperiment, or a SpatialExperiment object. The package preserves source representation and provenance and distinguishes raw counts from upstream transformed or imputed expression. Atlas files are downloaded on first use and cached locally, so an internet connection is needed the first time each file is accessed. |
| Authors: | Uday Rangaswamy [aut] (ORCID: <https://orcid.org/0009-0007-2758-9213>), Mahdi Komeili [aut, cre] (ORCID: <https://orcid.org/0009-0000-3760-5327>), Federico Caretti [aut] (ORCID: <https://orcid.org/0000-0002-6963-5245>), Idris Kouadri Boudjelthia [aut] (ORCID: <https://orcid.org/0000-0002-3139-4861>), Maria Musarra Pizzo [aut], Amir Fardin [aut] (ORCID: <https://orcid.org/0000-0002-9472-408X>), Andres Hernandez-Clavijo [aut], Remo Sanges [aut] (ORCID: <https://orcid.org/0000-0002-5047-9713>) |
| Maintainer: | Mahdi Komeili <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.99.0 |
| Built: | 2026-11-25 20:11:31 UTC |
| Source: | https://github.com/BiocStaging/ABCatlasR |
Opens the files of one ABC Atlas release in a local folder and returns an
object that finds, downloads and reads them. load_data() and
fetch_data() use it internally; call it yourself only to work with
individual ABC Atlas files.
abc_cache_connect( download_base = NULL, offline = FALSE, release = .abc_default_release )abc_cache_connect( download_base = NULL, offline = FALSE, release = .abc_default_release )
download_base |
Folder for ABC Atlas files. If |
offline |
If |
release |
ABC Atlas release in |
A file is downloaded the first time it is needed and checked against the
checksum the ABC Atlas publishes for it. With offline = TRUE, only
files already in the folder are used: nothing is downloaded or written.
By default the release this package was validated against is used. With
release = NULL, the release is chosen as the Python
abc_atlas_access package chooses it: the one last used with this
folder, with a warning if a newer one exists, or else the newest. Files
are stored with the same layout as in the Python package, so the two can
share a folder.
An abc_cache object: a list of class "abc_cache"
with these elements:
download_baseThe folder.
manifest_name, version
The release file list in use and its release date.
offlineWhether downloads are switched off.
get_file_path(directory, file_name)Function that returns the local path of a file, downloading it if needed.
get_metadata_dataframe(directory, file_name, col_classes,
...)Function that reads a metadata CSV file into a data frame;
... is passed to data.table::fread().
example_dir <- system.file( "extdata", "ex", package = "ABCatlasR" ) cache <- abc_cache_connect( example_dir, offline = TRUE, release = "20250101" ) cacheexample_dir <- system.file( "extdata", "ex", package = "ABCatlasR" ) cache <- abc_cache_connect( example_dir, offline = TRUE, release = "20250101" ) cache
Returns the folder where ABC Atlas files are downloaded and kept for reuse. It is the first of these that is set:
the explicit path argument;
getOption("ABCatlasR.download_base");
the ABC_ATLAS_CACHE environment variable;
a per-user cache directory,
tools::R_user_dir("ABCatlasR", "cache").
The folder is created if it does not exist yet.
abc_download_dir(path = NULL)abc_download_dir(path = NULL)
path |
Folder to use. If |
The full path of the folder.
# Use a temporary cache directory. cache_dir <- file.path(tempdir(), "ABCatlasR-example") abc_download_dir(cache_dir)# Use a temporary cache directory. cache_dir <- file.path(tempdir(), "ABCatlasR-example") abc_download_dir(cache_dir)
Downloads the expression files that hold the selected cells, unless they
were downloaded before, and reads the expression of those cells and genes
into R. plan_fetch() can show the files and their sizes first, but is
not needed.
fetch_data( data, cell_ids, genes = NULL, data_type = NULL, return_type = c("matrix", "sce", "spatial"), offline = FALSE )fetch_data( data, cell_ids, genes = NULL, data_type = NULL, return_type = c("matrix", "sce", "spatial"), offline = FALSE )
data |
The object returned by |
cell_ids |
Labels of the cells to fetch, from the
|
genes |
Genes to fetch, given as gene identifiers or gene symbols.
Each name is looked up in |
data_type |
Type of expression values: |
return_type |
Form of the result: |
offline |
If |
Before downloading, the free space on the disk holding the folder is
checked, and a download that does not fit is refused. On the disk the
operating system runs from, at least 2 GB must also remain free
afterwards, so the system keeps room for virtual memory. Nothing is
checked when every file was downloaded before. The same check runs
before every other download, including the metadata read by
load_data().
The expression, in the form chosen by return_type.
For return_type = "matrix", an abc_matrix object: a list
of class c("abc_matrix", "list") with these elements:
expressionSparse dgCMatrix (genes x cells).
Rows are named by gene_identifier, columns by
cell_label, in the order requested.
cell_metadataData frame with one row per selected cell, in the order of the matrix columns.
gene_dataData frame with one row per selected gene, in the order of the matrix rows.
data_typeThe type of expression values, as in the
data_type argument.
provenanceList recording where the data come from:
dataset, release, data_type,
modality, spatial, expression_directories,
n_cells and n_genes.
For "sce", a SingleCellExperiment, and for "spatial", a
SpatialExperiment. The expression is in the counts assay for raw
data and otherwise in an assay named after the data type (for example
log2 or ln), the cell and gene
metadata are in colData and rowData, and the provenance
list is in metadata(x)$ABCatlasR. A SpatialExperiment also holds
the spatial coordinates in spatialCoords, and its provenance
records their columns in coordinate_columns.
This package does not create Seurat or Monocle 3 objects. Fetch raw
counts with return_type = "matrix" and convert them with the
package you use; both expect counts, so use data_type = "raw".
x <- fetch_data(abc, cell_ids = cells, genes = genes, data_type = "raw")
# Seurat (package SeuratObject). Seurat replaces "_" in feature names.
counts <- x$expression
rownames(counts) <- gsub("_", "-", rownames(counts))
seu <- SeuratObject::CreateSeuratObject(
counts = counts,
meta.data = x$cell_metadata
)
# Monocle 3 (package monocle3, installed from GitHub).
gene_metadata <- x$gene_data
gene_metadata$gene_short_name <- gene_metadata$gene_symbol
cds <- monocle3::new_cell_data_set(
x$expression,
cell_metadata = x$cell_metadata,
gene_metadata = gene_metadata
)
# A small synthetic dataset shipped with the package. example_dir <- system.file("extdata", "ex", package = "ABCatlasR") abc <- readRDS(file.path(example_dir, "example-data.rds")) abc$download_base <- example_dir cells <- c("c4", "c1") x <- fetch_data( abc, cell_ids = cells, genes = c("G1", "G4"), offline = TRUE ) x$expression# A small synthetic dataset shipped with the package. example_dir <- system.file("extdata", "ex", package = "ABCatlasR") abc <- readRDS(file.path(example_dir, "example-data.rds")) abc$download_base <- example_dir cells <- c("c4", "c1") x <- fetch_data( abc, cell_ids = cells, genes = c("G1", "G4"), offline = TRUE ) x$expression
Returns one row per dataset the package supports, with the name to pass
to load_data(). The list is part of the package, so this needs no
internet connection and downloads nothing.
list_datasets()list_datasets()
A data frame of class
c("abc_dataset_catalog", "data.frame") with one row per
dataset and these columns:
datasetDataset name, used as dataset in
load_data().
modalityKind of data, for example
"spatial_transcriptomics".
spatialWhether the cells have spatial coordinates,
so that return_type = "spatial" can be used.
imputedWhether the expression values are imputed rather than measured.
default_data_type, available_data_types
The
type of expression values used by default and all the types the
dataset offers (see the data_type argument of
fetch_data()).
cell_directory, gene_directory,
taxonomy, expression_directories
The ABC Atlas folders the dataset is read from.
datasets <- list_datasets() datasets[datasets$spatial, ]datasets <- list_datasets() datasets[datasets$spatial, ]
Reads the metadata of every cell and gene in one dataset, together with
its annotation tables such as cell types, donors and spatial positions.
The files are downloaded the first time and reused afterwards. Gene
expression is not downloaded here; see fetch_data().
load_data( dataset, download_base = NULL, offline = FALSE, release = .abc_default_release )load_data( dataset, download_base = NULL, offline = FALSE, release = .abc_default_release )
dataset |
Dataset name, for example |
download_base |
Folder for ABC Atlas files. If |
offline |
If |
release |
ABC Atlas release in |
Choose cells and genes from the returned tables, then pass their labels
and names to fetch_data(). The returned object also records the release
and the folder, so plan_fetch() and fetch_data() use the same ones.
An abc_data object: a list of class
c("abc_data", "list") with these elements:
cell_metadataData frame with one row per cell; the
row names are the cell_label values. It combines the
published cell metadata with the annotation tables that exist for
the dataset: cell type names and colours, donor, library and
spatial information. Attributes on the data frame
(abc_dataset, abc_modality, abc_spatial,
abc_default_data_type, abc_available_data_types and
abc_expression_directories) tell plan_fetch() and
fetch_data() where the expression is stored, so pass the object on
as returned.
gene_dataData frame with one row per gene. The
gene_identifier column identifies each gene uniquely;
gene_symbol is included where the ABC Atlas publishes it.
unique_valuesNamed list with the different values found in the main metadata columns, to help choose cells.
datasetDataset name, as listed by list_datasets().
download_baseFolder used for the files.
releaseABC Atlas release the metadata come from.
# Cache the downloaded metadata in a temporary folder. abc <- load_data( "HMBA_PatchSeq", download_base = file.path(tempdir(), "ABCatlasR") ) abc dim(abc$cell_metadata)# Cache the downloaded metadata in a temporary folder. abc <- load_data( "HMBA_PatchSeq", download_base = file.path(tempdir(), "ABCatlasR") ) abc dim(abc$cell_metadata)
Shows which expression files fetch_data() would need for the selected
cells: their sizes, which were downloaded before and how much is still to
download, and whether that fits on the disk. Nothing is downloaded.
Using plan_fetch() is optional; fetch_data() does not need it.
plan_fetch(data, cell_ids = NULL, data_type = NULL, offline = FALSE)plan_fetch(data, cell_ids = NULL, data_type = NULL, offline = FALSE)
data |
The object returned by |
cell_ids |
Labels of the cells, from the |
data_type |
Type of expression values, as in |
offline |
If |
Expression files are downloaded whole, so the sizes do not depend on the
genes. They depend on the cells, because some datasets spread their
cells over several files, and on data_type.
An abc_fetch_plan object, which prints as a report: a
list of class "abc_fetch_plan" with these elements:
dataset, release, data_type
The dataset, ABC Atlas release and type of expression values.
n_cellsNumber of selected cells.
filesData frame with one row per expression file:
dataset_label, feature_matrix_label,
data_type, n_cells (selected cells in the file),
size (bytes), relative_path, local_path,
cached (downloaded before), partial_bytes (bytes of
an interrupted download that will be resumed) and
additional_download (bytes still to download).
total_size, total_partial,
total_download
Sums of size, partial_bytes
and additional_download, in bytes.
storageThe disk space check fetch_data() makes
before downloading: available (free bytes, or NA if
unknown), download, system_disk, headroom
(space that must stay free), required and
sufficient.
# A small synthetic dataset shipped with the package. example_dir <- system.file("extdata", "ex", package = "ABCatlasR") abc <- readRDS(file.path(example_dir, "example-data.rds")) abc$download_base <- example_dir plan_fetch(abc, offline = TRUE) # Exact cells: only the files holding them are listed. plan_fetch(abc, cell_ids = c("c1", "c2"), offline = TRUE)# A small synthetic dataset shipped with the package. example_dir <- system.file("extdata", "ex", package = "ABCatlasR") abc <- readRDS(file.path(example_dir, "example-data.rds")) abc$download_base <- example_dir plan_fetch(abc, offline = TRUE) # Exact cells: only the files holding them are listed. plan_fetch(abc, cell_ids = c("c1", "c2"), offline = TRUE)