Commit 1a25925f authored by Anne  BITON's avatar Anne BITON
Browse files

Upload script making a few facs plot

parent 3725e965
---
title: "Gating cells based on MFI"
author: "Laina Freyer, Anne Biton"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output:
prettydoc::html_pretty:
highlight: github
number_sections: yes
theme: cayman
toc: yes
---
```{r setup, eval=TRUE, echo=FALSE, warning = FALSE, message=FALSE, results=FALSE, prompt=FALSE}
knitr::opts_chunk$set(echo = FALSE, cache = FALSE, warning = FALSE, message=FALSE, results=FALSE, prompt=FALSE, dpi=150)
dirdata <- "../../data/"
library(data.table)
library(ggplot2)
library(foreach)
library(biomaRt)
library(matrixStats)
library(Seurat)
library(Matrix)
library(scater)
library(scran)
library(pheatmap)
library(dplyr)
library(scales)
library(tidyverse)
library(cowplot)
library(SingleCellExperiment)
library(scater)
library(scran)
library(batchelor)
```
# Load data
```{r}
#merged
sceall_seurat <- readRDS(paste0(dirdata,'derived/FL/FL_sceall_seurat_fastMNN_bycond.rds'))
```
```{r, warning=F, message=F}
# Set up biexponential scales
# https://ggplot2.narkive.com/FxdQGE78/biexponential-scale#post9ggplo
biexp_trans <- function(lim = 100, decade.size = lim){trans <- function(x){ifelse(x <= lim, x, lim + decade.size * (suppressWarnings(log(x, 10)) - log(lim, 10)))}
inv <- function(x) {ifelse(x <= lim, x, 10^(((x-lim)/decade.size) + log(lim,10)))}
breaks <- function(x) {if (all(x <= lim)) {pretty_breaks()(x)} else if (all(x > lim)) {log_breaks(10)(x)} else {unique(c(pretty_breaks()(c(x[1],lim)), log_breaks(10)(c(lim, x[2]))))}}
trans_new(paste0("biexp-",format(lim)), trans, inv, breaks)}
```
# Assign Index Sort Progenitor Identity
We assigned subpopulation identity (CMP, GMP, MEP, P1) using the `select.cells` function and MFI for CD16/32 versus CD34 from the index sort.
The assigned progenitors metadata were saved in `r paste0(dirdata,'derived/FL_E10.5_E12.5_library123/cell2progenitor_run123_FL.rds')`.
```{r, warning=F, message=F, fig.width=7, fig.height=6}
# Scatter plot for Cell Selection
plot <- ggplot(data = data.frame(x = sceall_seurat$CD34_MFI, y = sceall_seurat$CD16_32_MFI), aes(x,y)) + geom_point(size=1, colour = "grey", alpha = 0.5) + scale_y_continuous(name = "CD16/32", trans=biexp_trans(lim=400, decade.size=1600), limits = c(-500,80000)) + scale_x_continuous(name = "CD34", trans=biexp_trans(lim=400, decade.size=300), limits = c(-400,80000)) + theme_bw() + ggtitle("Progenitor Gating") + theme(plot.title=element_text(hjust=0.5, size=26))
plot
#Idents(sceall_seurat) <- "subpopulation"
```
`select.cells <- CellSelector(plot = plot)`
Use cursor to select cells in Plots window, press escape to return them as select.cell.
```{r, warning=F, message=F, fig.width=5, fig.height=4}
# subset E10.5 FL
sceall_seurat_E10.5FL <- subset(sceall_seurat, subset = `condition` == 'E10.5_Fetal_Liver')
# subset E12.5 FL
sceall_seurat_E12.5FL <- subset(sceall_seurat, subset = `condition` == 'E12.5_Fetal_Liver')
cols_progenitors <- c('CMP' = "#d570fa", 'GMP' = "#4e9dfc", 'MEP' = "#ed5a32", 'P1' = "#eda532", 'NA' = "#ffffff")
cols_progenitors2 <- c('CMP' = "#d570fa", 'GMP' = "#4e9dfc", 'MEP' = "#ed5a32", 'P1' = "grey", 'NA' = "grey")
cols_progenitors3 <- c('CMP' = "grey", 'GMP' = "grey", 'MEP' = "grey", 'P1' = "grey", 'NA' = "grey")
```
```{r progenitor overlay , warning=F, message=F, fig.width=8, fig.height=5, eval=TRUE}
ggplot(data = data.frame(cd34 = sceall_seurat_E10.5FL$CD34_MFI,
cd3612 = sceall_seurat_E10.5FL$CD16_32_MFI,
progenitor = sceall_seurat_E10.5FL$progenitors),
aes(x=cd34,y=cd3612, color=progenitor)) +
geom_point(size=1) +
scale_y_continuous(name = "CD16/32", trans=biexp_trans(lim=400, decade.size=1600), limits = c(-500,80000)) +
scale_x_continuous(name = "CD34", trans=biexp_trans(lim=400, decade.size=300), limits = c(-400,80000)) +
scale_color_manual(values = cols_progenitors) +
theme_bw() + ggtitle(paste0("E10.5 "))
ggplot(data = data.frame(cd34 = sceall_seurat_E12.5FL$CD34_MFI,
cd3612 = sceall_seurat_E12.5FL$CD16_32_MFI,
progenitor = sceall_seurat_E12.5FL$progenitors),
aes(x=cd34,y=cd3612, color=progenitor)) +
geom_point(size=1) +
scale_y_continuous(name = "CD16/32", trans=biexp_trans(lim=400, decade.size=1600), limits = c(-500,80000)) +
scale_x_continuous(name = "CD34", trans=biexp_trans(lim=400, decade.size=300), limits = c(-400,80000)) +
scale_color_manual(values = cols_progenitors) +
theme_bw() + ggtitle(paste0("E12.5 "))
```
# FACS plot overlays by cluster and progenitor gate
Proportion of progenitors in each cluster, E10.5 cells.
```{r proportions 10.5, echo=F, message=F, warning=F, results=T}
#proportion of progenitors in each cluster
signif(scale(table(sceall_seurat_E10.5FL$progenitors, sceall_seurat_E10.5FL$knn_clusters),
scale=colSums(table(sceall_seurat_E10.5FL$progenitors, sceall_seurat_E10.5FL$knn_clusters)),
center=FALSE)*100, digits = 2)
```
Proportion of progenitors in each cluster, E12.5 cells.
```{r proportions 12.5, echo=F, message=F, warning=F, results=T}
signif(scale(table(sceall_seurat_E12.5FL$progenitors, sceall_seurat_E12.5FL$knn_clusters),
scale=colSums(table(sceall_seurat_E12.5FL$progenitors, sceall_seurat_E12.5FL$knn_clusters)),
center=FALSE)*100, digits = 2)
```
```{r cluster overlay 10.5 and e12.5, echo=F, warning=F, message=F, fig.width=20, fig.height=8}
plotlist <- foreach(clustername=levels(sceall_seurat$knn_clusters)) %do% {
g10 <- ggplot(data = data.frame(x = sceall_seurat_E10.5FL$CD34_MFI,
y = sceall_seurat_E10.5FL$CD16_32_MFI), aes(x,y)) +
geom_point(size=1, colour = "grey", alpha = 0.5) +
scale_y_continuous(name = "CD16/32", trans=biexp_trans(lim=400, decade.size=1600), limits = c(-500,80000)) +
scale_x_continuous(name = "CD34", trans=biexp_trans(lim=400, decade.size=300), limits = c(-400,80000)) +
theme_bw() + ggtitle(paste0("E10.5 \n ", clustername)) + theme(plot.title=element_text(hjust=0.5, size=26)) +
geom_point(data = data.frame(x = subset(sceall_seurat_E10.5FL, subset = `knn_clusters` == clustername)$CD34_MFI,
y = subset(sceall_seurat_E10.5FL, subset = `knn_clusters` == clustername)$CD16_32_MFI), aes(x,y), size=1, colour = "blue") +
theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
theme(axis.text=element_blank()) + theme(axis.title.y=element_text(size=20)) +
theme(axis.title.x = element_text(margin = margin(t = 14, r = 0, b = 0, l = 0))) +
theme(axis.title.y = element_text(margin = margin(t = 0, r = 14, b = 0, l = 0)))
g12 <- ggplot(data = data.frame(x = sceall_seurat_E12.5FL$CD34_MFI,
y = sceall_seurat_E12.5FL$CD16_32_MFI), aes(x,y)) +
geom_point(size=1, colour = "grey", alpha = 0.5) +
scale_y_continuous(name = "CD16/32", trans=biexp_trans(lim=400, decade.size=1600), limits = c(-500,80000)) +
scale_x_continuous(name = "CD34", trans=biexp_trans(lim=400, decade.size=300), limits = c(-400,80000)) +
theme_bw() + ggtitle(paste0("E12.5 \n ", clustername)) + theme(plot.title=element_text(hjust=0.5, size=26)) +
geom_point(data = data.frame(x = subset(sceall_seurat_E12.5FL, subset = `knn_clusters` == clustername)$CD34_MFI,
y = subset(sceall_seurat_E12.5FL, subset = `knn_clusters` == clustername)$CD16_32_MFI), aes(x,y), size=1, colour = "blue") +
theme(panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
theme(axis.text=element_blank()) + theme(axis.title.y=element_text(size=20)) +
theme(axis.title.x = element_text(margin = margin(t = 14, r = 0, b = 0, l = 0))) +
theme(axis.title.y = element_text(margin = margin(t = 0, r = 14, b = 0, l = 0)))
return(list(g10,g12))
}
cowplot::plot_grid(plotlist = do.call(c, plotlist)[c(1,3,5,7,9,11,13,15,17,19,2,4,6,8,10,12,14,16,18,20)], nrow=2)
```
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment