Skip to content

Instantly share code, notes, and snippets.

@FloWuenne
Last active July 26, 2017 14:38
Show Gist options
  • Save FloWuenne/11409997ad826ef429fec511f779cf40 to your computer and use it in GitHub Desktop.
Save FloWuenne/11409997ad826ef429fec511f779cf40 to your computer and use it in GitHub Desktop.
Plot mean expression of a gene vs other parameters and highlight specific genes using ggrepel
## Use scater to investigate and annotate gene and cluster properties
```{r}
library(scater)
## Create new SCE object from the seurat expression object
fData <- new("AnnotatedDataFrame", data = [email protected])
seurat_scater_sce <- newSCESet(exprsData = as.matrix(expression_seurat@data), phenoData = fData,
lowerDetectionLimit=0.01,
logExprsOffset=1)
seurat_scater_sce <- calculateQCMetrics(seurat_scater_sce)
```
```{r}
library(ggrepel)
## Put the feature Data into variable called gene_info
gene_info <- fData(seurat_scater_sce)
## Define a group of genes of interest
genes_of_interest <- c("")
## Write a table that contains some useful stats for these genes
genes_of_interest_data <- subset(gene_info,rownames(gene_info) %in% genes_of_interest)
write.table(params_goi,file="Feature_params.genes_of_interest.txt",
row.names=T,
col.names=T,
quote=F,
sep="\t")
## Plot the position of genes of interest in relation to all other genes in the distribution of mean gene expression vs pct dropout
mean_exprs_vs_drpt <- ggplot(gene_info,aes(log10(mean_exprs),pct_dropout)) +
geom_point(fill="white",col="grey",size=1.5) +
geom_point(data= genes_of_interest_data,
color="red",
size=1.5) +
geom_text_repel(
data = genes_of_interest_data,
aes(label = rownames(genes_of_interest_data)),
size = 5,
box.padding = unit(0.35, "lines"),
point.padding = unit(0.3, "lines")
) +
xlab("log10 of mean expression") +
ylab("% Total expression")
ggsave(mean_exprs_vs_drpt,file="mean_exprs_vs_drpt.svg")
## Plot the position of genes of interest in relation to all other genes in the distribution of mean gene expression vs pct_total_expression
mean_exprs_vs_pcttotal <- ggplot(gene_info,aes(log10(mean_exprs),pct_total_exprs)) +
geom_point(fill="white",
col="grey",
pch=21,
alpha=0.8,
size=1.5) +
geom_point(data= genes_of_interest_data,
fill="red",
col="black",
pch=21,
size=1.5) +
geom_text_repel(
data = genes_of_interest_data,
aes(label = rownames(genes_of_interest_data)),
size = 5,
box.padding = unit(0.35, "lines"),
point.padding = unit(0.3, "lines")
) +
xlab("log10 of mean expression") +
ylab("% Total expression")
ggsave(mean_exprs_vs_pcttotal,file="mean_exprs_vs_pcttotal.svg")
detach("package:scater", unload=TRUE)
detach("package:ggrepel", unload=TRUE)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment