library(data.table)
library(cowplot)
library(ggpubr)
library(Matrix)
library(BuenColors)
Loading required package: ggplot2 Attaching package: ‘cowplot’ The following object is masked from ‘package:ggplot2’: ggsave Loading required package: magrittr Attaching package: ‘ggpubr’ The following object is masked from ‘package:cowplot’: get_legend Loading required package: MASS
plot_umap <- function(df_umap,labels,title='UMAP',colormap=colormap){
set.seed(2019)
df_umap = data.frame(cbind(df_umap,labels),stringsAsFactors = FALSE)
colnames(df_umap) = c('umap1','umap2','celltype')
df_umap$umap1 = as.numeric(df_umap$umap1)
df_umap$umap2 = as.numeric(df_umap$umap2)
options(repr.plot.width=4, repr.plot.height=4)
p <- ggplot(shuf(df_umap), aes(x = umap1, y = umap2, color = celltype)) +
geom_point(size = 1) + scale_color_manual(values = colormap) +
ggtitle(title)
return(p)
}
workdir = './output/'
path_fig = paste0(workdir,'figures/')
system(paste0('mkdir -p ',path_fig))
path_umap = paste0(workdir,'umap_rds/')
se = readRDS(paste0(workdir,'se.rds'))
se
class: RangedSummarizedExperiment dim: 80000 1200 metadata(0): assays(1): counts rownames(80000): chr1_30528_31028 chr1_97671_98171 ... chrX_154841997_154842497 chrX_154862080_154862580 rowData names(0): colnames(1200): CD4_1 CD4_2 ... NK_1199 NK_1200 colData names(1): label
for (df in sapply(strsplit(list.files(path_umap), "\\."),'[',1)){
assign(df,readRDS(paste0(path_umap,df,'.rds')))
}
ls()
labels = se@colData$label
colormap = jdb_color_maps
p_control <- plot_umap(df_umap_control,labels = labels,colormap = colormap,title='Control-Naive')
p_control
p_chromVAR_motif <- plot_umap(df_umap_chromVAR_motif,labels = labels,colormap = colormap,title='chromVAR motif')
p_chromVAR_kmer <- plot_umap(df_umap_chromVAR_kmer,labels = labels,colormap = colormap,title='chromVAR kmer')
options(repr.plot.width=8, repr.plot.height=3)
cowplot::plot_grid(p_chromVAR_motif,p_chromVAR_kmer)
p_chromVAR_motif2 <- plot_umap(df_umap_chromVAR_motif2,labels = labels,colormap = colormap,title='chromVAR motif after PCA')
p_chromVAR_kmer2 <- plot_umap(df_umap_chromVAR_kmer2,labels = labels,colormap = colormap,title='chromVAR kmer after PCA')
options(repr.plot.width=8, repr.plot.height=3)
cowplot::plot_grid(p_chromVAR_motif2,p_chromVAR_kmer2)
p_Cusanovich2018 <- plot_umap(df_umap_Cusanovich2018,labels = labels,colormap = colormap,title='Cusanovich2018')
p_Cusanovich2018
p_cisTopic <- plot_umap(df_umap_cisTopic,labels = labels,colormap = colormap,title='cisTopic')
p_cisTopic
p_GeneScoring <- plot_umap(df_umap_GeneScoring,labels = labels,colormap = colormap,title='Gene Scoring')
p_GeneScoring
p_GeneScoring2 <- plot_umap(df_umap_GeneScoring2,labels = labels,colormap = colormap,title='Gene Scoring after PCA')
p_GeneScoring2
p_Cicero <- plot_umap(df_umap_Cicero,labels = labels,colormap = colormap,title='Cicero')
p_Cicero
p_Cicero2 <- plot_umap(df_umap_Cicero2,labels = labels,colormap = colormap,title='Cicero after PCA')
p_Cicero2
p_SnapATAC <- plot_umap(df_umap_SnapATAC,labels = labels,colormap = colormap,title='SnapATAC')
p_SnapATAC
p_scABC <- plot_umap(df_umap_scABC,labels = labels,colormap = colormap,title='scABC')
p_scABC
p_SCRAT <- plot_umap(df_umap_SCRAT,labels = labels,colormap = colormap,title='SCRAT')
p_SCRAT
p_SCRAT2 <- plot_umap(df_umap_SCRAT2,labels = labels,colormap = colormap,title='SCRAT after PCA')
p_SCRAT2
p_Scasat <- plot_umap(df_umap_Scasat,labels = labels,colormap = colormap,title='Scasat')
p_Scasat
p_BROCKMAN <- plot_umap(df_umap_BROCKMAN,labels = labels,colormap = colormap,title='BROCKMAN')
p_BROCKMAN
figname = "bonemarrow_cov2500.pdf"
fig_width = 4*6
fig_height = 4*3
options(repr.plot.width=4, repr.plot.height=4)
leg <- cowplot::get_legend(p_control + theme(legend.direction = "horizontal", legend.position = c(0.2,0.5)) +
labs(color='cell type')+
guides(color=guide_legend(nrow=3,byrow=TRUE,override.aes = list(size=5))))
p_legend = as_ggplot(leg)
p_legend
options(repr.plot.width=fig_width, repr.plot.height=fig_height)
p_figure = cowplot::plot_grid(p_legend,
p_control+theme(legend.position = "none"),
p_cisTopic+theme(legend.position = "none"),
p_Cusanovich2018+theme(legend.position = "none"),
p_Scasat+theme(legend.position = "none"),
p_SnapATAC+theme(legend.position = "none"),
p_BROCKMAN+theme(legend.position = "none"),
p_chromVAR_kmer+theme(legend.position = "none"),
p_chromVAR_motif+theme(legend.position = "none"),
p_Cicero+theme(legend.position = "none"),
p_GeneScoring+theme(legend.position = "none"),
p_SCRAT+theme(legend.position = "none"),
p_scABC+theme(legend.position = "none"),
p_chromVAR_kmer2+theme(legend.position = "none"),
p_chromVAR_motif2+theme(legend.position = "none"),
p_Cicero2+theme(legend.position = "none"),
p_GeneScoring2+theme(legend.position = "none"),
p_SCRAT2+theme(legend.position = "none"),
labels = "",ncol = 6)
p_figure
cowplot::ggsave(p_figure,filename = paste0(path_fig,figname), width = fig_width, height = fig_height)