Dispatches on the file extension (HTAN's File_Format is too coarse:
hdf5 covers .h5ad and 10x .h5, RData covers .rds):
Arguments
- x
A file path, a Space Ranger
outs/directory, or the result ofhtan_download()(in which case every row'spathis read).- coords
character(2)orNULL. For cell tables, the x and y centroid columns.NULLtries common names (X_centroid/Y_centroidfrom MCMICRO,x/y,centroid_x/centroid_y, and others).- ...
Passed to the underlying reader.
Value
A SingleCellExperiment, SpatialExperiment, other
SummarizedExperiment, tibble or path, depending on the file. For a
multi-row htan_download() result, a list named by
HTAN_Data_File_ID.
Details
.h5adanndataR::read_h5ad()to aSingleCellExperiment; aspatialembedding becomesspatialCoords()of aSpatialExperiment. Files in the pre-0.8 AnnData layout, which anndataR rejects and many HTAN centers wrote, are read with rhdf5 instead:X,layers,obs,varand numericobsmarrays, but notuns. Duplicatedobsorvarnames are made unique withmake.unique(), with a message..rds,.rda,.RDataRead, then:
SingleCellExperimentand otherSummarizedExperiments pass through; a Seurat object is converted with SeuratObject (counts, data, metadata, reductions, and tissue coordinates when present). Anything else is returned as is, with a message..h5(10x)TENxIO::TENxH5()to aSingleCellExperiment.- a Space Ranger
outs/directory VisiumIO::TENxVisium()to aSpatialExperiment..csv,.tsv,.txt(optionally.gz)Imaging Level 4 cell tables become a
SpatialExperiment(cells as columns, marker intensities as theintensitiesassay, centroids asspatialCoords(), other per-cell columns ascolData). A table without recognisable coordinates is returned as a tibble..tif,.tiff,.svsImages are not read; the path is returned with a message (see RBioFormats or cytomapper).
Level 4 objects are heterogeneous across HTAN centers. Readers are best-effort: check the result.
Examples
cells <- data.frame(CellID = 1:3, CD3 = c(1, 5, 2), CD8 = c(0, 3, 1),
X_centroid = c(10, 20, 30), Y_centroid = c(5, 15, 25), Area = 40:42)
path <- tempfile(fileext = ".csv")
write.csv(cells, path, row.names = FALSE)
read_htan(path)
#> class: SpatialExperiment
#> dim: 2 3
#> metadata(0):
#> assays(1): intensities
#> rownames(2): CD3 CD8
#> rowData names(0):
#> colnames(3): 1 2 3
#> colData names(3): CellID Area sample_id
#> reducedDimNames(0):
#> mainExpName: NULL
#> altExpNames(0):
#> spatialCoords names(2) : x y
#> imgData names(0):
## A tiny Visium file in the pre-0.8 AnnData layout
if (requireNamespace("rhdf5", quietly = TRUE)) {
read_htan(system.file("extdata", "h5ad", "legacy_visium.h5ad",
package = "HTAN"))
}
#> legacy_visium.h5ad is in the pre-0.8 AnnData layout; reading it with read_htan()'s fallback reader.
#> ℹ `uns` is not read; `...` is ignored.
#> class: SpatialExperiment
#> dim: 5 4
#> metadata(0):
#> assays(3): counts dense X
#> rownames(5): OR4F5 SAMD11 NOC2L KLHL17 PERM1
#> rowData names(5): gene_ids feature_types highly_variable n_cells
#> Feature.Counts.in.Spots.Under.Tissue
#> colnames(4): AAACAAGTATCTCCCA-1 AAACAATCTACTAGCA-1 AAACACCAATAACTGC-1
#> AAACAGAGCGACTCCT-1
#> colData names(6): in_tissue array_row ... cluster sample_id
#> reducedDimNames(1): X_pca
#> mainExpName: NULL
#> altExpNames(0):
#> spatialCoords names(2) : x y
#> imgData names(0):