Read in tables produced by pileup_cells()
which are an
extension of the matrixMarket sparse matrix format to store values for more
than 1 matrix.
The .mtx.gz files are formatted with columns:
row index (0 based)
column index (0 based)
values for sparseMatrix #1 (nRef)
values for sparseMatrix #2 (nAlt)
Usage
read_sparray(mtx_fn, sites_fn, bc_fn, site_format = c("coordinate", "index"))
Examples
library(Rsamtools)
library(GenomicRanges)
bam_fn <- raer_example("5k_neuron_mouse_possort.bam")
gr <- GRanges(c("2:579:-", "2:625:-", "2:645:-", "2:589:-", "2:601:-"))
gr$REF <- c(rep("A", 4), "T")
gr$ALT <- c(rep("G", 4), "C")
cbs <- unique(scanBam(bam_fn, param = ScanBamParam(tag = "CB"))[[1]]$tag$CB)
cbs <- na.omit(cbs)
outdir <- tempdir()
bai <- indexBam(bam_fn)
fp <- FilterParam(library_type = "fr-second-strand")
mtx_fns <- pileup_cells(bam_fn, gr, cbs, outdir, return_sce = FALSE)
sce <- read_sparray(mtx_fns[1], mtx_fns[2], mtx_fns[3])
sce
#> class: SingleCellExperiment
#> dim: 4 556
#> metadata(0):
#> assays(2): nRef nAlt
#> rownames(4): site_2_579_2_AG site_2_625_2_AG site_2_589_2_AG
#> site_2_601_2_TC
#> rowData names(2): REF ALT
#> colnames(556): TGGAACTCAAGCTGTT-1 TACTTCAGTAACCCTA-1 ...
#> TGTACAGTCTTCGTGC-1 TGTTGAGGTGACTGAG-1
#> colData names(0):
#> reducedDimNames(0):
#> mainExpName: NULL
#> altExpNames(0):
unlink(bai)