The function formatTxSpots reads the transcript spot coordinates of
smFISH-based data and formats the data. The data is not added to an SFE
object. If the file specified in file_out already exists, then this file
will be read instead of the original file in the file argument, so the
processing is not run multiple times. The function addTxSpots adds the data
read and processed in formatTxSpots to the SFE object, and reads all
transcript spot data. To only read a subset of transcript spot data, first
use formatTxSpots to write the re-formatted data to disk. Then read the
specific subset and add them separately to the SFE object with the setter
functions.
Usage
formatTxSpots(
file,
dest = deprecated(),
spatialCoordsNames = c("global_x", "global_y", "global_z"),
gene_col = "gene",
cell_col = "cell_id",
z = deprecated(),
phred_col = "qv",
min_phred = 20,
split_col = deprecated(),
not_in_cell_id = c("-1", "UNASSIGNED"),
z_option = deprecated(),
flip = FALSE,
file_out = NULL,
BPPARAM = SerialParam(),
return = TRUE,
save_memory = FALSE,
partition = FALSE
)
addTxSpots(
sfe,
file,
sample_id = 1L,
spatialCoordsNames = c("global_x", "global_y", "global_z"),
gene_col = "gene",
z = deprecated(),
phred_col = "qv",
min_phred = 20,
split_col = deprecated(),
z_option = deprecated(),
flip = FALSE,
file_out = NULL,
BPPARAM = SerialParam()
)Arguments
- file
File with the transcript spot coordinates. Should be one row per spot when read into R and should have columns for coordinates on each axis, gene the transcript is assigned to, and optionally cell the transcript is assigned to. Must be csv, tsv, or parquet.
- dest
This argument and the "colGeometry" option is deprecated. Only "rowGeometry" will be allowed.
- spatialCoordsNames
Column names for the x, y, and optionally z coordinates of the spots. The defaults are for Vizgen.
- gene_col
Column name for genes.
- cell_col
Column name for cell IDs, ignored if
dest = "rowGeometry". Can have length > 1 when multiple columns are needed to uniquely identify cells, in which case the contents of the columns will be concatenated, such as in CosMX data where cell ID is only unique within the same FOV. Default "cell_id" is for Vizgen MERFISH. Should bec("cell_ID", "fov")for CosMX.- z
Selecting z-planes is deprecated. All z-planes are read by default.
- phred_col
Column name for Phred scores of the spots.
- min_phred
Minimum Phred score to keep spot. By default 20, the conventional threshold indicating "acceptable", meaning that there's 1% chance that the spot was decoded in error.
- split_col
Categorical column to split the geometries, such as cell compartment the spots are assigned to as in the "CellComp" column in CosMX output.
- not_in_cell_id
Value of cell ID indicating that the spot is not assigned to any cell, such as "-1" in Vizgen MERFISH and "0" in CosMX. When there're multiple columns for
cell_col, the first column is used to identify spots that are not in cells.- z_option
Deprecated. Will always be "3d" to construct 3D point geometries if multiple z-planes are present.
- flip
Logical, whether to flip the geometry to match image. Here the y coordinates are simply set to -y, so the original bounding box is not preserved. This is consistent with
readVizgenandreadXenium.- file_out
Name of file to save the geometry or raster to disk. Especially when the geometries are so large that it's unwieldy to load everything into memory. If this file (or directory for multiple files) already exists, then the existing file(s) will be read, skipping the processing. When writing the file, extensions supplied are ignored and extensions are determined based on
dest.- BPPARAM
BiocParallelParamobject to specify multithreading to convert raw char in some parquet files to R objects. Not used otherwise.- return
Logical, whether to return the geometries in memory. This does not depend on whether the geometries are written to file. Always
FALSEwhendest = "colGeometry".- save_memory
Don't load transcript spots of all genes at once. Not fully implemented here.
- partition
Whether to partition the output by gene.
- sfe
A
SpatialFeatureExperimentobject.- sample_id
Which sample in the SFE object the transcript spots should be added to.
Value
A sf data frame for vector geometries if file_out is not set.
SpatRaster for raster. If there are multiple files written, such as when
splitting by cell compartment or when dest = "colGeometry", then a
directory with the same name as file_out will be created (but without the
extension) and the files are written to that directory with informative
names. parquet files that can be read with st_read is written for
vector geometries. When return = FALSE, the file name or directory (when
there're multiple files) is returned.
The sf data frame, or path to file where geometries are written if
return = FALSE.
Examples
# Default arguments are for MERFISH
fp <- tempfile()
dir_use <- SFEData::VizgenOutput(file_path = fp)
#> see ?SFEData and browseVignettes('SFEData') for documentation
#> downloading 1 resources
#> retrieving 1 resource
#>
#> loading from cache
#> The downloaded files are in /private/var/folders/q2/p1t6rgxj5fj32g1dc7dmd49r0000gn/T/Rtmp4UEbWg/file1808304998d9/vizgen_cellbound
g <- formatTxSpots(file.path(dir_use, "detected_transcripts.csv"))
#> >>> Converting transcript spots to geometry
unlink(dir_use, recursive = TRUE)