Load packages
library( "Seurat" )
library( "scater" )
library( "scran" )
library( "tidyverse" )
Load data
Seurat -> SingleCellExperiment
sce <- readRDS( "/home/idies/workspace/practical_genomics/day1/retina.rds" )
sce <- as.SingleCellExperiment( sce )
Check data
1. assay()
Introduce
- How to access the expression data?
help( assay )
m_assay <- assay( , "logcounts" )
- What class of object is this?
class( )
dim( )
- How to subset first 10 rows, first 3 columns?
m_assay[ , ]
Subset RHO
x_rho <- m_assay[ , ]
( x_rho )
( x_rho )
hist( )
summary( )
Subset RHO, VIM
goi <- c( "RHO", "VIM" )
x_rhovim <- m_assay[ , ]
( x_rhovim )
( x_rhovim )
( x_rhovim )
ggplot RHO, VIM
t()
, data.frame()
, rownames_to_column()
, pivot_longer()
df_rhovim <- ( x_rhovim )
df_rhovim <- ( df_rhovim )
df_rhovim <- ( df_rhovim )
df_rhovim <- ( df_rhovim, cols=c( "RHO", "VIM" ) )
df_rhovim
ggplot( ) +
geom_histogram( aes( ) ) +
facet_wrap( vars() )
2. colData()
Introduce
- How to access the cell metadata?
( colData )
meta <- colData( )
- What class of object is this?
( meta )
meta
data.frame( )
( meta )
colnames( )
Subset rows
colData()
, data.frame()
, rownames_to_column()
df_meta <- ( sce ) %>%
() %>%
()
df_meta
( df_meta )
df_meta[ , ]
Subset libraryID
table( df_meta$ )
df_fovea2 <- df_meta %>%
filter( libraryID=="" )
df_fovea2
( df_fovea2 )
table( df_fovea2$ )
ggplot gene by cell_type
df_rhovim_fovea2 <- df_rhovim %>%
( df_meta, by="rowname" ) %>%
( libraryID=="fovea_donor_2" )
df_rhovim_fovea2
geom_violin()
, facet_wrap()
, theme()
ggplot( df_rhovim_fovea2 ) +
( aes( cell_type, value ) ) +
( vars(name) ) +
( axis.text.x=element_text( angle=90 ) )
3. reducedDim()
Introduce
- How to access the cluster visualization?
( reducedDim )
data.frame()
, rownames_to_column()
df_umap <- reducedDim( sce, "" ) %>%
() %>%
()
df_umap
ggplot cell_type
df_umap_meta <- full_join( , , by="rowname" )
df_umap_meta
ggplot( ) +
geom_point( aes( , , color= ) )
ggplot RHO
df_umap_rho <- full_join( , , by="rowname" ) %>%
filter( name=="" )
df_umap_rho
ggplot( ) +
geom_point( aes( , , color= ) )
4. findMarkers()
Introduce
- How to access differentially expressed genes?
( findMarkers )
- Preview of findMarkers() syntax
colLabels( sce ) <- colData( sce )$
markers <- findMarkers( )
- What class of object is this?
( markers )
( markers )
- Build up to
data.frame( markers[[1]] )
markers
hist summary.logFC
markers[1]
df_markers_amacrine <- markers[[1]] %>%
()
df_markers_amacrine
hist( df_markers_amacrine$ )
plotUMAP markers
df_markers_amacrine %>%
filter( summary.logFC > )
help( )
plotUMAP( sce, colour_by="MEG3", ="cell_type" )
Exercise 2
- Recreate plotUMAP() using ggplot2
- Plot another gene, cell metadata
- Recreate plotExpression() using ggplot2
- Plot another gene by cell metadata
- Adjust ggplot2 appearance
- Add titles, customize x/y labels, theme
- Explore findMarkers() results
- Use plotUMAP(), plotExpression()
Document software
sessionInfo()
LS0tCnRpdGxlIDogIkRheSAxIC8vIEhhbmRzLW9uIDIgLy8gRXhwbG9yZSBTaW5nbGVDZWxsRXhwZXJpbWVudCIKYXV0aG9yOiAiIgpkYXRlICA6ICIwNCBPY3RvYmVyIDIwMjEiCm91dHB1dDogCiAgaHRtbF9ub3RlYm9vazoKICAgIHRvYzogdHJ1ZQogICAgdG9jX2Zsb2F0OiB0cnVlCi0tLQoKIyBMb2FkIHBhY2thZ2VzCgpgYGB7ciBtZXNzYWdlPUZBTFNFfQpsaWJyYXJ5KCAiU2V1cmF0IiApCmxpYnJhcnkoICJzY2F0ZXIiICkKbGlicmFyeSggInNjcmFuIiApCgpsaWJyYXJ5KCAidGlkeXZlcnNlIiApCmBgYAoKIyBMb2FkIGRhdGEKCiMjIFNldXJhdCAtPiBTaW5nbGVDZWxsRXhwZXJpbWVudAoKYGBge3J9CnNjZSA8LSByZWFkUkRTKCAiL2hvbWUvaWRpZXMvd29ya3NwYWNlL3ByYWN0aWNhbF9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