{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "scrolled": true }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Loading required package: ggplot2\n", "\n", "Attaching package: ‘cowplot’\n", "\n", "The following object is masked from ‘package:ggplot2’:\n", "\n", " ggsave\n", "\n", "Loading required package: magrittr\n", "\n", "Attaching package: ‘ggpubr’\n", "\n", "The following object is masked from ‘package:cowplot’:\n", "\n", " get_legend\n", "\n", "Loading required package: MASS\n" ] } ], "source": [ "library(data.table)\n", "library(cowplot)\n", "library(ggpubr)\n", "library(Matrix)\n", "library(BuenColors)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### define functions" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "plot_umap <- function(df_umap,labels,title='UMAP',colormap=colormap){\n", " set.seed(2019) \n", " df_umap = data.frame(cbind(df_umap,labels),stringsAsFactors = FALSE)\n", " colnames(df_umap) = c('umap1','umap2','celltype')\n", " df_umap$umap1 = as.numeric(df_umap$umap1)\n", " df_umap$umap2 = as.numeric(df_umap$umap2)\n", " options(repr.plot.width=4, repr.plot.height=4)\n", " p <- ggplot(shuf(df_umap), aes(x = umap1, y = umap2, color = celltype)) +\n", " geom_point(size = 1) + scale_color_manual(values = colormap) +\n", " ggtitle(title)\n", " return(p)\n", "}" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Input" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "workdir = './output/'\n", "path_fig = paste0(workdir,'figures/')\n", "system(paste0('mkdir -p ',path_fig))" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "path_umap = paste0(workdir,'umap_rds/')" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "se = readRDS(paste0(workdir,'se.rds'))" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "class: RangedSummarizedExperiment \n", "dim: 80000 1200 \n", "metadata(0):\n", "assays(1): counts\n", "rownames(80000): chr1_9942_10442 chr1_12478_12978 ...\n", " chrX_154841997_154842497 chrX_154862080_154862580\n", "rowData names(0):\n", "colnames(1200): CD4_1 CD4_2 ... NK_1199 NK_1200\n", "colData names(1): label" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "se" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "for (df in sapply(strsplit(list.files(path_umap), \"\\\\.\"),'[',1)){\n", " assign(df,readRDS(paste0(path_umap,df,'.rds')))\n", "}" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "