Skip to content

Instantly share code, notes, and snippets.

@FloWuenne
Created July 26, 2017 18:55
Show Gist options
  • Save FloWuenne/e2b11727e9c72604e4d14d49797c2d0e to your computer and use it in GitHub Desktop.
Save FloWuenne/e2b11727e9c72604e4d14d49797c2d0e to your computer and use it in GitHub Desktop.
Cell cycle assignment for single cell data using scran and cyclone with gene symbols instead of ensembl IDs
library(scran)
library(org.Hs.eg.db)
## Load pretrained model from scran
hg.pairs <- readRDS(system.file("exdata", "human_cycle_markers.rds", package="scran"))
## Translate all ensembl IDs to gene symbols for pretrained model
g1_symbols <- data.frame()
s_symbols <- data.frame()
g2m_symbols <- data.frame()
## G1 first
g1_first_ids <- hg.pairs$G1$first
g1_first_symbols <- bitr(g1_first_ids, fromType="ENSEMBL", toType="SYMBOL", OrgDb="org.Hs.eg.db")
colnames(g1_first_symbols) <- c("first","first_symbol")
g1_symbols <- full_join(hg.pairs$G1,g1_first_symbols,by="first")
## G1 second
g1_second_ids <- hg.pairs$G1$second
g1_second_symbols <- bitr(g1_second_ids, fromType="ENSEMBL", toType="SYMBOL", OrgDb="org.Hs.eg.db")
colnames(g1_second_symbols) <- c("second","second_symbol")
g1_symbols <- full_join(g1_symbols,g1_second_symbols,by="second")
g1_symbols <- g1_symbols %>%
dplyr::select(first_symbol,second_symbol)
colnames(g1_symbols) <- c("first","second")
## S first
s_first_ids <- hg.pairs$S$first
s_first_symbols <- bitr(s_first_ids, fromType="ENSEMBL", toType="SYMBOL", OrgDb="org.Hs.eg.db")
colnames(s_first_symbols) <- c("first","first_symbol")
s_symbols <- full_join(hg.pairs$S,s_first_symbols,by="first")
## S second
s_second_ids <- hg.pairs$S$second
s_second_symbols <- bitr(s_second_ids, fromType="ENSEMBL", toType="SYMBOL", OrgDb="org.Hs.eg.db")
colnames(s_second_symbols) <- c("second","second_symbol")
s_symbols <- full_join(s_symbols,s_second_symbols,by="second")
s_symbols <- s_symbols %>%
dplyr::select(first_symbol,second_symbol)
colnames(s_symbols) <- c("first","second")
## G2M first
g2m_first_ids <- hg.pairs$G2M$first
g2m_first_symbols <- bitr(g2m_first_ids, fromType="ENSEMBL", toType="SYMBOL", OrgDb="org.Hs.eg.db")
colnames(g2m_first_symbols) <- c("first","first_symbol")
g2m_symbols <- full_join(hg.pairs$G2M,g2m_first_symbols,by="first")
## G2M second
g2m_second_ids <- hg.pairs$G2M$second
g2m_second_symbols <- bitr(g2m_second_ids, fromType="ENSEMBL", toType="SYMBOL", OrgDb="org.Hs.eg.db")
colnames(g2m_second_symbols) <- c("second","second_symbol")
g2m_symbols <- full_join(g2m_symbols,g2m_second_symbols,by="second")
g2m_symbols <- g2m_symbols %>%
dplyr::select(first_symbol,second_symbol)
colnames(g2m_symbols) <- c("first","second")
## Make a new list of pairs with symbols instead of ensembl IDs
hg.pairs_symbols <- list(g1_symbols,s_symbols,g2m_symbols)
names(hg.pairs_symbols) <- c("G1","S","G2M")
## Assign cell cycle phase using scrans cyclone function
assigned <- scran::cyclone(seurat_scater_sce, pairs=hg.pairs_symbols,
assay="exprs")
## Add cell cycle phases to Seurat object
## Add Litter ID and replicate number as metadata
cells <- rownames([email protected])
meta_data <- data.frame("Cell_cycle"=assigned$phases)
rownames(meta_data) <- cells
expression_seurat <- AddMetaData(expression_seurat,
metadata=meta_data)
@rtian30
Copy link

rtian30 commented Aug 21, 2018

Hi,
When I run:
hg.pairs <- readRDS(system.file("exdata","human_cycle_markers.rds", package="scran"))

It resulted a error message:
Error in gzfile(file, "rb") : cannot open the connection
In addition: Warning message:
In gzfile(file, "rb") :
cannot open compressed file '', probable reason 'Invalid argument'

Do you know what happens?

Here are my session info:
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252

attached base packages:
[1] stats4 parallel stats graphics grDevices utils datasets methods base

other attached packages:
[1] readr_1.1.1 org.Hs.eg.db_3.6.0 AnnotationDbi_1.42.1 scater_1.8.4
[5] SingleCellExperiment_1.2.0 SummarizedExperiment_1.10.1 DelayedArray_0.6.5 BiocParallel_1.14.2
[9] matrixStats_0.54.0 GenomicRanges_1.32.6 GenomeInfoDb_1.16.0 IRanges_2.14.10
[13] S4Vectors_0.18.3 ggplot2_3.0.0 Biobase_2.40.0 BiocGenerics_0.26.0
[17] BiocInstaller_1.30.0

Thanks,

Ruoyu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment