Convert SingleCellExperiment/SpatialExperiment/SpatialFeatureExperiment objects to list object for jazzPanda.
Source:R/convert_data.R
convert_data.Rd
This function takes an object of class SingleCellExperiment,
SpatialExperiment or SpatialFeatureExperimentreturns and returns a list
object that is expected for the get_vector
functions.
Value
outputs a list object with the following components
- trans_lst
A list of named dataframes. Each dataframe refers to one sample and shows the transcript detection coordinates for each gene. The name matches the input sample_names
- cm_lst
A list of named dataframes containing the count matrix for each sample. The name matches the input sample_names
Examples
library(SingleCellExperiment)
#> Loading required package: SummarizedExperiment
#> Loading required package: MatrixGenerics
#> Loading required package: matrixStats
#>
#> Attaching package: ‘MatrixGenerics’
#> The following objects are masked from ‘package:matrixStats’:
#>
#> colAlls, colAnyNAs, colAnys, colAvgsPerRowSet, colCollapse,
#> colCounts, colCummaxs, colCummins, colCumprods, colCumsums,
#> colDiffs, colIQRDiffs, colIQRs, colLogSumExps, colMadDiffs,
#> colMads, colMaxs, colMeans2, colMedians, colMins, colOrderStats,
#> colProds, colQuantiles, colRanges, colRanks, colSdDiffs, colSds,
#> colSums2, colTabulates, colVarDiffs, colVars, colWeightedMads,
#> colWeightedMeans, colWeightedMedians, colWeightedSds,
#> colWeightedVars, rowAlls, rowAnyNAs, rowAnys, rowAvgsPerColSet,
#> rowCollapse, rowCounts, rowCummaxs, rowCummins, rowCumprods,
#> rowCumsums, rowDiffs, rowIQRDiffs, rowIQRs, rowLogSumExps,
#> rowMadDiffs, rowMads, rowMaxs, rowMeans2, rowMedians, rowMins,
#> rowOrderStats, rowProds, rowQuantiles, rowRanges, rowRanks,
#> rowSdDiffs, rowSds, rowSums2, rowTabulates, rowVarDiffs, rowVars,
#> rowWeightedMads, rowWeightedMeans, rowWeightedMedians,
#> rowWeightedSds, rowWeightedVars
#> Loading required package: GenomicRanges
#> Loading required package: stats4
#> Loading required package: BiocGenerics
#>
#> Attaching package: ‘BiocGenerics’
#> The following objects are masked from ‘package:stats’:
#>
#> IQR, mad, sd, var, xtabs
#> The following objects are masked from ‘package:base’:
#>
#> Filter, Find, Map, Position, Reduce, anyDuplicated, aperm, append,
#> as.data.frame, basename, cbind, colnames, dirname, do.call,
#> duplicated, eval, evalq, get, grep, grepl, intersect, is.unsorted,
#> lapply, mapply, match, mget, order, paste, pmax, pmax.int, pmin,
#> pmin.int, rank, rbind, rownames, sapply, saveRDS, setdiff, table,
#> tapply, union, unique, unsplit, which.max, which.min
#> Loading required package: S4Vectors
#>
#> Attaching package: ‘S4Vectors’
#> The following object is masked from ‘package:utils’:
#>
#> findMatches
#> The following objects are masked from ‘package:base’:
#>
#> I, expand.grid, unname
#> Loading required package: IRanges
#> Loading required package: GenomeInfoDb
#> Loading required package: Biobase
#> Welcome to Bioconductor
#>
#> Vignettes contain introductory material; view with
#> 'browseVignettes()'. To cite Bioconductor, see
#> 'citation("Biobase")', and for packages 'citation("pkgname")'.
#>
#> Attaching package: ‘Biobase’
#> The following object is masked from ‘package:MatrixGenerics’:
#>
#> rowMedians
#> The following objects are masked from ‘package:matrixStats’:
#>
#> anyMissing, rowMedians
library(SpatialExperiment)
# A SingleCellExperiment object
set.seed(200)
counts_sp1 <- matrix(rpois(100, lambda = 10), ncol=10, nrow=10)
counts_sp2 <- matrix(rpois(100, lambda = 5), ncol=10, nrow=10)
sce <- SingleCellExperiment(list(sp1=counts_sp1, sp2=counts_sp2))
sce_example_lst <- convert_data(sce, sample_names = c("sp1","sp2"))
# A SpatialExperiment object
n <- 10
y <- matrix(rpois(200, lambda = 2),nrow = n, ncol = 2*n)
cd <- DataFrame(x = seq(2*n), y = seq(2*n))
spe1 <- SpatialExperiment(
assays = list(counts = y),
colData = cd,
sample_id="sample1",
spatialCoordsNames = c("x", "y"))
se_example_lst <- convert_data(spe1, sample_names = c("sample1"))
## Multiple sample scenario
spe2 <- SpatialExperiment(
assays = list(counts = matrix(rpois(200, lambda = 2),
nrow = n, ncol = 2*n)),
colData = cd,
sample_id="sample2",
spatialCoordsNames = c("x", "y"))
se_example_lst <- convert_data(cbind(spe1, spe2),
sample_names = c("sample1", "sample2"))