suppressMessages(library('data.table'))
suppressMessages(library('tidyverse'))
suppressMessages(library('cowplot'))
suppressMessages(library('VisualVisium'))
# Load the count matrix and the tissue positions list into R objects.
# A compressed version of V1_Adult_Mouse_Brain_outs is stored at inst/extdata.
cntmtr_tpl <- rawmatr_and_tpl("/Volumes/Backup\ Plus/10x_datasets/V1_Adult_Mouse_Brain_outs")
# The tissue positions list table; each row corresponds to a spot in the array.
# See detailed description at https://support.10xgenomics.com/spatial-gene-expression/software/pipelines/latest/output/images
tpl <- cntmtr_tpl[['tpl']]
head(tpl)
A data.table: 6 × 7
barcodetissuerowcolimagerowimagecolumis
# The raw count matrix, with genes in the rows, spots in the columns (includes all the spots in the array).
# See detailed description at https://support.10xgenomics.com/spatial-gene-expression/software/pipelines/latest/output/matrices
count_matrix <- cntmtr_tpl[['raw_matrix']]
str(count_matrix)
num [1:32285, 1:4992] 0 0 0 0 0 0 0 0 0 0 ...
- attr(*, "dimnames")=List of 2
..$ : chr [1:32285] "ENSMUSG00000051951" "ENSMUSG00000089699" "ENSMUSG00000102331" "ENSMUSG00000102343" ...
..$ : chr [1:4992] "AAACAACGAATAGTTC-1" "AAACAAGTATCTCCCA-1" "AAACAATCTACTAGCA-1" "AAACACCAATAACTGC-1" ...
# Function that groups spots into bands around the perimeter of the tissue.
tpl_wbands <- visium_bands(tpl)
head(tpl_wbands)
A data.table: 6 × 8
barcodetissuerowcolimagerowimagecolumisband
# Plot the inside-tissue and outside-tissue bands on the Visium array.
coord_range <- range(as.matrix(tpl_wbands[, list(imagecol, imagerow)]))
pbands_in <- ggplot(tpl_wbands[tissue == 1],
aes(x=imagecol, y=imagerow, color=band)) +
geom_point(shape = 20, size = 1, stroke = 0.5) +
coord_fixed(xlim = coord_range, ylim = coord_range) +
xlab('X') +
ylab('Y') +
ggtitle('bands inside of tissue') +
theme_bw() +
scale_colour_brewer(palette = 'Spectral')
pbands_out <- ggplot(tpl_wbands[tissue == 0],
aes(x=imagecol, y=imagerow, color=band)) +
geom_point(shape = 20, size = 1, stroke = 0.5) +
coord_fixed(xlim = coord_range, ylim = coord_range) +
xlab('X') +
ylab('Y') +
ggtitle('bands outside of tissue') +
theme_bw() +
scale_colour_brewer(palette = 'Spectral')
p <- plot_grid(pbands_in, pbands_out, nrow = 1)
options(repr.plot.width=10, repr.plot.height=5)
p
# Show distributions of UMIs for inside (bm) and outside (bp) tissue bands.
p <- ggplot(tpl_wbands, aes(x=band, y=log10(umis+1))) +
geom_violin(trim=T) +
geom_boxplot(width=0.1) +
theme_bw() +
ylab('log10(UMIs+1)')
options(repr.plot.width=10, repr.plot.height=5)
p
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.