Title: | Read in Xenium, CosMx, MERSCOPE or STARmapPLUS data as SpatialExperiment object |
---|---|
Description: | Read in imaging-based spatial transcriptomics technology data. Current available modules are for Xenium by 10X Genomics, CosMx by Nanostring, MERSCOPE by Vizgen, or STARmapPLUS from Broad Institute. You can choose to read the data in as a SpatialExperiment or a SingleCellExperiment object. |
Authors: | Yixing E. Dong [aut, cre] |
Maintainer: | Yixing E. Dong <[email protected]> |
License: | Artistic-2.0 |
Version: | 0.99.8 |
Built: | 2025-02-13 03:26:51 UTC |
Source: | https://github.com/bioc/SpatialExperimentIO |
Sanity check if one and only file with the specified name pattern exists in the data download directory, and return the file path to .csv Used for count matrix and metadata only, as they require unique.
.sanityCheck(tech, filetype, expectfilename, dirName, filepatternvar)
.sanityCheck(tech, filetype, expectfilename, dirName, filepatternvar)
tech |
Name of technology. Defined at the beginning of the function. e.g. "CosMx" |
filetype |
File type to do sanity check. e.g. "metadata" |
expectfilename |
Expected file pattern name for this file type. e.g. "metadata_file.csv" |
dirName |
Directory to the data download. |
filepatternvar |
The file pattern variable. e.g. "metaDataPattern" |
a path to a unique file of count matrix or colData.
Yixing Estella Dong
## Not run: dir <- system.file(file.path("extdata", "CosMx_small"), package = "SpatialExperimentIO") countmat_file <- SpatialExperimentIO:::.sanityCheck(tech = "CosMx", filetype = "count matrix", expectfilename = "`exprMat_file.csv`", dirName = dir, filepatternvar = "exprMat_file.csv") ## End(Not run)
## Not run: dir <- system.file(file.path("extdata", "CosMx_small"), package = "SpatialExperimentIO") countmat_file <- SpatialExperimentIO:::.sanityCheck(tech = "CosMx", filetype = "count matrix", expectfilename = "`exprMat_file.csv`", dirName = dir, filepatternvar = "exprMat_file.csv") ## End(Not run)
Add CosMx-related parquet paths to metadata for transcripts, polygon, or cell/nucleus boundaries.
addParquetPathsCosmx( sxe, dirName, addTx = TRUE, txMetaNames = "transcripts", txPattern = "tx_file.csv", addPolygon = TRUE, polygonMetaNames = "polygons", polygonPattern = "polygons.csv" )
addParquetPathsCosmx( sxe, dirName, addTx = TRUE, txMetaNames = "transcripts", txPattern = "tx_file.csv", addPolygon = TRUE, polygonMetaNames = "polygons", polygonPattern = "polygons.csv" )
sxe |
a SPE or SCE Xenium object to add parquet to |
dirName |
the directory that stores the transcripts/polygon .csv or .parquet files. |
addTx |
to add path to transcripts parquet to |
txMetaNames |
names to add to slots in |
txPattern |
.csv or .parquet (if you have previous converted) pattern
of transcript file in |
addPolygon |
to add path to polygons parquet to |
polygonMetaNames |
names to add to slots in |
polygonPattern |
.csv or .parquet (if you have previous converted) pattern
of polygons file in the |
a SPE or SCE Xenium object with parquet paths added to metadata
Yixing Estella Dong
cospath <- system.file(file.path("extdata", "CosMx_small"), package = "SpatialExperimentIO") sxe <- readCosmxSXE(dirName = cospath, addParquetPaths = FALSE) sxe <- addParquetPathsCosmx(sxe, dirName = cospath, addPolygon = FALSE)
cospath <- system.file(file.path("extdata", "CosMx_small"), package = "SpatialExperimentIO") sxe <- readCosmxSXE(dirName = cospath, addParquetPaths = FALSE) sxe <- addParquetPathsCosmx(sxe, dirName = cospath, addPolygon = FALSE)
Add Xenium-related parquet paths to metadata for transcripts or cell/nucleus boundaries.
addParquetPathsXenium( sxe, dirName, addTx = TRUE, txMetaNames = "transcripts", txPattern = "transcripts.parquet", addCellBound = TRUE, cellBoundMetaNames = "cell_boundaries", cellBoundPattern = "cell_boundaries.parquet", addNucBound = TRUE, NucBoundMetaNames = "nucleus_boundaries", NucBoundPattern = "nucleus_boundaries.parquet" )
addParquetPathsXenium( sxe, dirName, addTx = TRUE, txMetaNames = "transcripts", txPattern = "transcripts.parquet", addCellBound = TRUE, cellBoundMetaNames = "cell_boundaries", cellBoundPattern = "cell_boundaries.parquet", addNucBound = TRUE, NucBoundMetaNames = "nucleus_boundaries", NucBoundPattern = "nucleus_boundaries.parquet" )
sxe |
a SPE or SCE Xenium object to add parquet to |
dirName |
the directory that stores the transcripts/cell_boundaries/nucleus_boundaries .parquet files. |
addTx |
to add path to transcripts parquet to |
txMetaNames |
names to add to slots in |
txPattern |
.parquet pattern of transcript file in |
addCellBound |
to add path to cell boundaries parquet to |
cellBoundMetaNames |
names to add to slots in |
cellBoundPattern |
.parquet pattern of cell boundaries file in |
addNucBound |
to add path to nucleus boundaries parquet to |
NucBoundMetaNames |
names to add to slots in |
NucBoundPattern |
.parquet pattern of nucleus boundaries file in |
a SPE or SCE Xenium object with parquet paths added to metadata
Yixing Estella Dong
xepath <- system.file(file.path("extdata", "Xenium_small"), package = "SpatialExperimentIO") sxe <- readXeniumSXE(dirName = xepath, addParquetPaths = FALSE) sxe <- addParquetPathsXenium(sxe, dirName = xepath)
xepath <- system.file(file.path("extdata", "Xenium_small"), package = "SpatialExperimentIO") sxe <- readXeniumSXE(dirName = xepath, addParquetPaths = FALSE) sxe <- addParquetPathsXenium(sxe, dirName = xepath)
Add parquet paths to metadata for transcripts, polygon, or cell/nucleus boundaries.
addParquetPathToMeta( sxe, dirName = dirName, metaNames = "transcripts", filePattern = "tx_file.csv" )
addParquetPathToMeta( sxe, dirName = dirName, metaNames = "transcripts", filePattern = "tx_file.csv" )
sxe |
a SPE or SCE object to add parquet to |
dirName |
the directory that stores the transcripts/polygon/cell_boundaries .csv or .parquet files. |
metaNames |
a vector of names to |
filePattern |
a vector of file patterns to search in the current directory.
e.g. |
a SPE or SCE object with parquet paths added to metadata
dir <- system.file(file.path("extdata", "CosMx_small"), package = "SpatialExperimentIO") sxe <- readCosmxSXE(dir, addParquetPaths = FALSE) sxe <- addParquetPathToMeta(sxe, dirName = dir, metaNames = "transcripts", filePattern = "tx_file.parquet")
dir <- system.file(file.path("extdata", "CosMx_small"), package = "SpatialExperimentIO") sxe <- readCosmxSXE(dir, addParquetPaths = FALSE) sxe <- addParquetPathToMeta(sxe, dirName = dir, metaNames = "transcripts", filePattern = "tx_file.parquet")
If transcripts or polygon is expected to be loaded, write a parquet file to the current data download (if not already), and return the file path to .parquet
csvToParquetPaths(dirName, filepath = "tx_csv_path")
csvToParquetPaths(dirName, filepath = "tx_csv_path")
dirName |
current directory of data download |
filepath |
path to transcripts or polygons csv |
a path to .parquet
Yixing Estella Dong
dir <- system.file(file.path("extdata", "CosMx_small"), package = "SpatialExperimentIO") tx_csv_path <- file.path(dir, "lung_p9s1_tx_file.csv") tx_parquet_path <- csvToParquetPaths(dirName, filepath = tx_csv_path)
dir <- system.file(file.path("extdata", "CosMx_small"), package = "SpatialExperimentIO") tx_csv_path <- file.path(dir, "lung_p9s1_tx_file.csv") tx_parquet_path <- csvToParquetPaths(dirName, filepath = tx_csv_path)
Creates a SpatialExperiment
from the downloaded unzipped CosMx
directory for Nanostring CosMx spatial gene expression data.
readCosmxSXE( dirName = dirName, returnType = "SPE", countMatPattern = "exprMat_file.csv", metaDataPattern = "metadata_file.csv", coordNames = c("CenterX_global_px", "CenterY_global_px"), addFovPos = TRUE, fovPosPattern = "fov_positions_file.csv", altExps = c("NegPrb", "Negative", "SystemControl", "FalseCode"), addParquetPaths = TRUE, ... )
readCosmxSXE( dirName = dirName, returnType = "SPE", countMatPattern = "exprMat_file.csv", metaDataPattern = "metadata_file.csv", coordNames = c("CenterX_global_px", "CenterY_global_px"), addFovPos = TRUE, fovPosPattern = "fov_positions_file.csv", altExps = c("NegPrb", "Negative", "SystemControl", "FalseCode"), addParquetPaths = TRUE, ... )
dirName |
a directory path to CosMx download that contains files of interest. |
returnType |
option of |
countMatPattern |
a filename pattern for the count matrix. Default value is
|
metaDataPattern |
a filename pattern for the metadata .csv file that
contains spatial coords. Default value is |
coordNames |
a vector of two strings specify the spatial coord names.
Default value is |
addFovPos |
to read in fov_position_list.csv and add the data frame to
|
fovPosPattern |
.csv pattern of fov_position_list.csv files in the raw download.
Default value is |
altExps |
gene names contains these strings will be moved to |
addParquetPaths |
to add parquet paths to |
... |
extra parameters to pass to |
The constructor assumes the downloaded unzipped CosMx folder has the following
structure, with two mandatory files:
CosMx_unzipped/optional_default_folder/
· | — *_exprMat_file.csv
· | — *_metadata_file.csv
Optional files to add to the metadata() as a list of paths (will be converted to parquet):
· | — *_fov_positions_file.csv
· | — *_tx_file.csv
· | — *_polygons.csv
If no optional files, need to set addFovPos = FALSE
and addParquetPaths = FALSE
.
If only one of *_tx_file.csv
or *_polygons.csv
exists, set addParquetPaths = TRUE
but
set the not available addTx
or addPolygon
to FALSE
.
See addParquetPathsCosmx()
a SpatialExperiment
or a SingleCellExperiment
object
Yixing Estella Dong
# A relatively small data download can be from: # https://nanostring.com/resources/smi-ffpe-dataset-lung9-rep1-data/ # A mock counts and mock metadata with spatial location generated for a 8 genes by # 9 cells object is in /extdata: cospath <- system.file( file.path("extdata", "CosMx_small"), package = "SpatialExperimentIO") list.files(cospath) # One of the following depending on your output (`SPE` or `SCE`) requirement. cos_spe <- readCosmxSXE(dirName = cospath, addPolygon = FALSE) cos_sce <- readCosmxSXE(dirName = cospath, returnType = "SCE", addPolygon = FALSE) cos_spe <- readCosmxSXE(dirName = cospath, addParquetPaths = FALSE)
# A relatively small data download can be from: # https://nanostring.com/resources/smi-ffpe-dataset-lung9-rep1-data/ # A mock counts and mock metadata with spatial location generated for a 8 genes by # 9 cells object is in /extdata: cospath <- system.file( file.path("extdata", "CosMx_small"), package = "SpatialExperimentIO") list.files(cospath) # One of the following depending on your output (`SPE` or `SCE`) requirement. cos_spe <- readCosmxSXE(dirName = cospath, addPolygon = FALSE) cos_sce <- readCosmxSXE(dirName = cospath, returnType = "SCE", addPolygon = FALSE) cos_spe <- readCosmxSXE(dirName = cospath, addParquetPaths = FALSE)
Creates a SpatialExperiment
from the downloaded MERSCOPE
directory for Vizgen MERSCOPE spatial gene expression data.
readMerscopeSXE( dirName = dirName, returnType = "SPE", countMatPattern = "cell_by_gene.csv", metaDataPattern = "cell_metadata.csv", coordNames = c("center_x", "center_y") )
readMerscopeSXE( dirName = dirName, returnType = "SPE", countMatPattern = "cell_by_gene.csv", metaDataPattern = "cell_metadata.csv", coordNames = c("center_x", "center_y") )
dirName |
a directory path to MERSCOPE download that contains files of interest. |
returnType |
option of |
countMatPattern |
a filename pattern for the count matrix. Default value is
|
metaDataPattern |
a filename pattern for the metadata .csv file that
contains spatial coords. Default value is |
coordNames |
a vector of two strings specify the spatial coord names.
Default value is |
The constructor assumes the downloaded MERSCOPE count matrix and metadata in
the same folder with the following structure:
MERSCOPE_folder/
· | — cell_by_gene.csv
· | — cell_metadata.csv
a SpatialExperiment
or a SingleCellExperiment
object
Yixing Estella Dong
# A relatively small data download can be from: # https://console.cloud.google.com/storage/browser/vz-ffpe-showcase/ # HumanOvarianCancerPatient2Slice2?pageState=(%22StorageObjectListTable%22: # (%22f%22:%22%255B%255D%22))&prefix=&forceOnObjectsSortingFiltering=false # A mock counts and mock metadata with spatial location generated for a 9 genes by # 8 cells object is in /extdata: merpath <- system.file( file.path("extdata", "MERSCOPE_small"), package = "SpatialExperimentIO") list.files(merpath) # One of the following depending on your output (`SPE` or `SCE`) requirement. mer_spe <- readMerscopeSXE(dirName = merpath) mer_sce <- readMerscopeSXE(dirName = merpath, returnType = "SCE")
# A relatively small data download can be from: # https://console.cloud.google.com/storage/browser/vz-ffpe-showcase/ # HumanOvarianCancerPatient2Slice2?pageState=(%22StorageObjectListTable%22: # (%22f%22:%22%255B%255D%22))&prefix=&forceOnObjectsSortingFiltering=false # A mock counts and mock metadata with spatial location generated for a 9 genes by # 8 cells object is in /extdata: merpath <- system.file( file.path("extdata", "MERSCOPE_small"), package = "SpatialExperimentIO") list.files(merpath) # One of the following depending on your output (`SPE` or `SCE`) requirement. mer_spe <- readMerscopeSXE(dirName = merpath) mer_sce <- readMerscopeSXE(dirName = merpath, returnType = "SCE")
Creates a SpatialExperiment
from the downloaded seqFISH
directory for Spatial Genomics seqFISH spatial gene expression data.
readSeqfishSXE( dirName = dirName, returnType = "SPE", countMatPattern = "CellxGene.csv", metaDataPattern = "CellCoordinates.csv", coordNames = c("center_x", "center_y") )
readSeqfishSXE( dirName = dirName, returnType = "SPE", countMatPattern = "CellxGene.csv", metaDataPattern = "CellCoordinates.csv", coordNames = c("center_x", "center_y") )
dirName |
a directory path to seqFISH download that contains files of interest. |
returnType |
option of |
countMatPattern |
a filename pattern for the count matrix. Default value is
|
metaDataPattern |
a filename pattern for the metadata .csv file that
contains spatial coords. Default value is |
coordNames |
a vector of two strings specify the spatial coord names.
Default value is |
The constructor assumes the downloaded seqFISH count matrix and metadata in
the same folder with the following structure:
seqFISH_folder/
· | — *_CellxGene.csv
· | — *_CellCoordinates.csv
a SpatialExperiment
or a SingleCellExperiment
object
Yixing Estella Dong
# A relatively small data download can be from: # https://spatialgenomics.com/data/#kidney-data # A mock counts and mock metadata with spatial location generated for a 9 genes by # 13 cells object is in /extdata: seqfpath <- system.file( file.path("extdata", "seqFISH_small"), package = "SpatialExperimentIO") list.files(seqfpath) # One of the following depending on your output (`SPE` or `SCE`) requirement. seqf_spe <- readSeqfishSXE(dirName = seqfpath) seqf_sce <- readSeqfishSXE(dirName = seqfpath, returnType = "SCE")
# A relatively small data download can be from: # https://spatialgenomics.com/data/#kidney-data # A mock counts and mock metadata with spatial location generated for a 9 genes by # 13 cells object is in /extdata: seqfpath <- system.file( file.path("extdata", "seqFISH_small"), package = "SpatialExperimentIO") list.files(seqfpath) # One of the following depending on your output (`SPE` or `SCE`) requirement. seqf_spe <- readSeqfishSXE(dirName = seqfpath) seqf_sce <- readSeqfishSXE(dirName = seqfpath, returnType = "SCE")
Creates a SpatialExperiment
from the downloaded STARmap PLUS count
matrix.csv and metadata.csv
readStarmapplusSXE( dirName = dirName, returnType = "SPE", countMatPattern = "raw_expression_pd.csv", metaDataPattern = "spatial.csv", coordNames = c("X", "Y", "Z") )
readStarmapplusSXE( dirName = dirName, returnType = "SPE", countMatPattern = "raw_expression_pd.csv", metaDataPattern = "spatial.csv", coordNames = c("X", "Y", "Z") )
dirName |
a directory path to STARmap PLUS download that contains files of interest. |
returnType |
option of |
countMatPattern |
a filename pattern for the count matrix. Default value is
|
metaDataPattern |
a filename pattern for the metadata .csv file that
contains spatial coords. Default value is |
coordNames |
a vector of three strings specify the spatial coord names.
Default value is |
The constructor assumes the downloaded unzipped STARmap PLUS folder has the following
structure, with two mandatory files:
STARmap_PLUS_download/
· | — *raw_expression_pd.csv
· | — *spatial.csv
a SpatialExperiment
or a SingleCellExperiment
object
Yixing Estella Dong
# A relatively small data download can be from: # https://zenodo.org/records/8327576 # A mock counts and mock metadata with spatial location generated for a 8 genes by # 9 cells object is in /extdata: starpath <- system.file( file.path("extdata", "STARmapPLUS_small"), package = "SpatialExperimentIO") list.files(starpath) # One of the following depending on your output (`SPE` or `SCE`) requirement. star_spe <- readStarmapplusSXE(dirName = starpath) star_sce <- readStarmapplusSXE(dirName = starpath, returnType = "SCE")
# A relatively small data download can be from: # https://zenodo.org/records/8327576 # A mock counts and mock metadata with spatial location generated for a 8 genes by # 9 cells object is in /extdata: starpath <- system.file( file.path("extdata", "STARmapPLUS_small"), package = "SpatialExperimentIO") list.files(starpath) # One of the following depending on your output (`SPE` or `SCE`) requirement. star_spe <- readStarmapplusSXE(dirName = starpath) star_sce <- readStarmapplusSXE(dirName = starpath, returnType = "SCE")
Creates a SpatialExperiment
from the downloaded unzipped Xenium
Output Bundle directory for 10x Genomics Xenium spatial gene expression data.
readXeniumSXE( dirName, returnType = "SPE", countMatPattern = "cell_feature_matrix.h5", metaDataPattern = "cells.parquet", coordNames = c("x_centroid", "y_centroid"), addExperimentXenium = TRUE, altExps = c("NegControlProbe", "UnassignedCodeword", "NegControlCodeword", "antisense", "BLANK"), addParquetPaths = TRUE, ... )
readXeniumSXE( dirName, returnType = "SPE", countMatPattern = "cell_feature_matrix.h5", metaDataPattern = "cells.parquet", coordNames = c("x_centroid", "y_centroid"), addExperimentXenium = TRUE, altExps = c("NegControlProbe", "UnassignedCodeword", "NegControlCodeword", "antisense", "BLANK"), addParquetPaths = TRUE, ... )
dirName |
a directory path to Xenium Output Bundle download that contains files of interest. |
returnType |
option of |
countMatPattern |
a folder directory or the h5 file pattern for the count matrix.
Default value is |
metaDataPattern |
a filename pattern of the zipped .csv file that
contains spatial coords. Default value is |
coordNames |
a vector of two strings specify the spatial coord names.
Default value is |
addExperimentXenium |
to add experiment.xenium parameters to |
altExps |
gene names contains these strings will be moved to |
addParquetPaths |
to add parquet paths to |
... |
extra parameters to pass to |
The constructor assumes the downloaded unzipped Xenium Output Bundle has the
following structure, with mandatory file of cells.csv.gz and either folder
/cell_feature_matrix or .h5 file cell_feature_matrix.h5:
Xenium_unzipped
· | — cell_feature_matrix.h5
· | — cell_feature_matrix
· · | - barcodes.tsv.gz
· · | - features.tsv.gz
· · | - matrix.mtx.gz
· | — cells.parquet
Optional files to add to the metadata() as a list of paths (will be converted to parquet):
· | — transcripts.parquet
· | — cell_boundaries.parquet
· | — nucleus_boundaries.parquet
· | — experiment.xenium
See addParquetPathsXenium()
a SpatialExperiment
or a SingleCellExperiment
object
Yixing Estella Dong
# A relatively small data set is the Xenium mouse brain data that can be # downloaded from 10X website. # A mock .h5 and mock metadata with spatial location generated for a 4 genes by # 6 cells object is in /extdata: xepath <- system.file( file.path("extdata", "Xenium_small"), package = "SpatialExperimentIO") list.files(xepath) # One of the following depending on your input (.h5 or folder) and output # (`SPE` or `SCE`) requirement. xe_spe <- readXeniumSXE(dirName = xepath) ## Not run: xe_spe <- readXeniumSXE(dirName = xepath, countMatPattern = "cell_feature_matrix") ## End(Not run) xe_sce <- readXeniumSXE(dirName = xepath, returnType = "SCE") xe_spe <- readXeniumSXE(dirName = xepath, addParquetPaths = TRUE) xe_spe <- readXeniumSXE(dirName = xepath, addParquetPaths = TRUE, addNucBound = FALSE)
# A relatively small data set is the Xenium mouse brain data that can be # downloaded from 10X website. # A mock .h5 and mock metadata with spatial location generated for a 4 genes by # 6 cells object is in /extdata: xepath <- system.file( file.path("extdata", "Xenium_small"), package = "SpatialExperimentIO") list.files(xepath) # One of the following depending on your input (.h5 or folder) and output # (`SPE` or `SCE`) requirement. xe_spe <- readXeniumSXE(dirName = xepath) ## Not run: xe_spe <- readXeniumSXE(dirName = xepath, countMatPattern = "cell_feature_matrix") ## End(Not run) xe_sce <- readXeniumSXE(dirName = xepath, returnType = "SCE") xe_spe <- readXeniumSXE(dirName = xepath, addParquetPaths = TRUE) xe_spe <- readXeniumSXE(dirName = xepath, addParquetPaths = TRUE, addNucBound = FALSE)