VisualVisium_demo/VisualVisium_demo.md

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 ACGCCTGACACGCGCT-100063.8428261.750451112 TACCGATCCAACACTT-101169.9668365.271751565 ATTAAAGCGGACGAGC-100263.8428268.793061521 GATAAGGGACGATTAG-101369.9668372.314362218 GTGCAAATCACCAATA-100463.8428275.835672302 TGTTGGCTGGCGGAAG-101569.9668379.305942945
# 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 CACATAAGGCGACCGT-1112969.96683163.613232871bm1 ATACGCCGATCTACCG-1113169.96683170.604734445bm1 ACTTATCTGATCTATA-1103263.84282174.126024496bm1 GTGTGAGCCGAGGTGC-1113369.96683177.647434103bm1 TCTGTGACTGACCGTT-1132382.21485142.536420585bm1 CTAGCAACTAATTTAC-1122876.09084160.091926016bm1
# 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

png

# 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

png




cajanegra1/VisualVisium documentation built on Sept. 15, 2020, 11:33 a.m.