Commit 3f331ef0 authored by Gervaise H. Henry's avatar Gervaise H. Henry 🤠

Add initial code for ds.aggr (CellRanger tSNE and K-clust=10)

parent 25690b09
gc()
library(methods)
library(optparse)
library(Seurat)
library(readr)
library(fBasics)
library(pastecs)
library(qusage)
library(RColorBrewer)
library(monocle)
library(dplyr)
library(viridis)
library(reshape2)
library(NMI)
source("../r.scripts/sc-TissueMapper.R")
setwd("../")
if (!dir.exists("./analysis")){
dir.create("./analysis")
}
downsamples <- c("All","350","300","250","200","150","100","075","050","037","025","012")
samples <- c("D17","D27","D35")
all.cells <- NULL
for (i in downsamples){
assign(paste0("cluster.",i),read_csv(paste0("./analysis/DATA/10x/",i,"/kmeans_10_clusters/clusters.csv")))
all.cells <- c(all.cells,get(paste0("cluster.",i))$Barcode)
}
all.cells <- unique(all.cells)
all.cells <- data.frame(Barcode=all.cells)
shared.cells <- Reduce(intersect,list(cluster.All$Barcode,cluster.350$Barcode,cluster.300$Barcode,cluster.250$Barcode,cluster.200$Barcode,cluster.150$Barcode,cluster.100$Barcode,cluster.075$Barcode,cluster.050$Barcode,cluster.037$Barcode,cluster.025$Barcode,cluster.012$Barcode))
for (i in downsamples){
assign(paste0("cluster.",i),get(paste0("cluster.",i))[get(paste0("cluster.",i))$Barcode %in% shared.cells,])
}
#for (i in downsamples){
# cluster <- all.cells
# cluster$Cluster <- 0
# cluster <- merge(cluster,get(paste0("cluster.",i)),all=TRUE,by.x="Barcode",by.y="Barcode",no.dups=TRUE)
# cluster[is.na(cluster)] <- 0
# cluster$Cluster <- cluster$Cluster.x+cluster$Cluster.y
# cluster <- cluster[,-2]
# cluster <- cluster[,-2]
# assign(paste0("cluster.",i),cluster)
# rm(cluster)
#}
for (i in downsamples[3:12]){
png(paste0("./analysis/",i,".png"),width=500,height=500,type="cairo")
assign(paste0("plot.",i),ggplot(melt(prop.table(table(cluster.350$Cluster,get(paste0("cluster.",i))$Cluster),1)*100),aes(x=factor(Var1),y=factor(Var2),fill=value))+geom_tile(color="black")+labs(x="350",y=i,fill="% of 350")+theme(line = element_blank())+scale_fill_gradientn(colours=c("white","black")))
plot(get(paste0("plot.",i)))
dev.off()
}
nmi <- data.frame(group1=character(),group2=character(),value=double())
for (i in downsamples[-1]){
for (j in downsamples[-1]){
nmi <- rbind(nmi,data.frame(group1=i,group2=j,nmi=NMI(get(paste0("cluster.",i)),get(paste0("cluster.",j)))))
}}
png(paste0("./analysis/NMI.png"),width=500,height=500,type="cairo")
plot.nmi <- ggplot(nmi,aes(x=factor(group1),y=factor(group2),fill=value))+geom_tile(color="black")+labs(x="",y="",fill="NMI")+theme(line = element_blank())+scale_fill_gradientn(colours=c("white","black"))
plot(plot.nmi)
dev.off()
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