Commit 41df73b3 authored by Gervaise Henry's avatar Gervaise Henry 🤠
Browse files

Fix id subclust clusters with only one ident

parent c918d449
......@@ -1012,29 +1012,31 @@ scShinyOutput <- function(sc10x,anal="raw"){
clusters <- c("samples",paste0("integrated_snn_res.",res),"lin","pops","leu","scDWSpr")
clusters <- intersect(clusters,names(sc10x@meta.data))
for (i in clusters){
if (!dir.exists(paste0("./analysis/shiny/",anal,"/outs/analysis/clustering/",gsub("integrated_snn_res.","res_",i)))){
dir.create(paste0("./analysis/shiny/",anal,"/outs/analysis/clustering/",gsub("integrated_snn_res.","res_",i)))
}
clust <- as.matrix(sc10x[[i]])
colnames(clust) <- "Cluster"
clust <- cbind(clust,Barcode=rownames(clust))
clust <- clust[,c(2,1)]
clust <- as.data.frame(clust,row.names=FALSE)
clust[,2] <- paste0("Cluster ",clust[,2])
write_csv(clust,paste0("./analysis/shiny/",anal,"/outs/analysis/clustering/",gsub("integrated_snn_res.","res_",i),"/clusters.csv"),col_names=TRUE)
if (!dir.exists(paste0("./analysis/shiny/",anal,"/outs/analysis/diffexp/",gsub("integrated_snn_res.","res_",i)))){
dir.create(paste0("./analysis/shiny/",anal,"/outs/analysis/diffexp/",gsub("integrated_snn_res.","res_",i)))
}
Idents(sc10x) <- i
deg <- FindAllMarkers(sc10x,assay="RNA",slot="data",logfc.threshold=0,test.use="MAST",min.pct=0.25,min.diff.pct=0.25,max.cells.per.ident=500)
dexp <- data.frame("Feature ID"=unique(deg$gene),"Feature Name"=unique(deg$gene))
for (cluster in unique(deg$cluster)){
dexp[,paste0("Cluster.",cluster,".Mean.Counts")] <- deg$pct.1[deg$cluster==cluster][match(dexp$Feature.ID,deg$gene[deg$cluster==cluster])]
dexp[,paste0("Cluster.",cluster,".Log2.fold.change")] <- deg$avg_logFC[deg$cluster==cluster][match(dexp$Feature.ID,deg$gene[deg$cluster==cluster])]
dexp[,paste0("Cluster.",cluster,".Adjusted.p.value")] <- deg$p_val_adj[deg$cluster==cluster][match(dexp$Feature.ID,deg$gene[deg$cluster==cluster])]
if (nrow(unique(sc10x[[i]]))>1){
if (!dir.exists(paste0("./analysis/shiny/",anal,"/outs/analysis/clustering/",gsub("integrated_snn_res.","res_",i)))){
dir.create(paste0("./analysis/shiny/",anal,"/outs/analysis/clustering/",gsub("integrated_snn_res.","res_",i)))
}
clust <- as.matrix(sc10x[[i]])
colnames(clust) <- "Cluster"
clust <- cbind(clust,Barcode=rownames(clust))
clust <- clust[,c(2,1)]
clust <- as.data.frame(clust,row.names=FALSE)
clust[,2] <- paste0("Cluster ",clust[,2])
write_csv(clust,paste0("./analysis/shiny/",anal,"/outs/analysis/clustering/",gsub("integrated_snn_res.","res_",i),"/clusters.csv"),col_names=TRUE)
if (!dir.exists(paste0("./analysis/shiny/",anal,"/outs/analysis/diffexp/",gsub("integrated_snn_res.","res_",i)))){
dir.create(paste0("./analysis/shiny/",anal,"/outs/analysis/diffexp/",gsub("integrated_snn_res.","res_",i)))
}
Idents(sc10x) <- i
deg <- FindAllMarkers(sc10x,assay="RNA",slot="data",logfc.threshold=0,test.use="MAST",min.pct=0.25,min.diff.pct=0.25,max.cells.per.ident=500)
dexp <- data.frame("Feature ID"=unique(deg$gene),"Feature Name"=unique(deg$gene))
for (cluster in unique(deg$cluster)){
dexp[,paste0("Cluster.",cluster,".Mean.Counts")] <- deg$pct.1[deg$cluster==cluster][match(dexp$Feature.ID,deg$gene[deg$cluster==cluster])]
dexp[,paste0("Cluster.",cluster,".Log2.fold.change")] <- deg$avg_logFC[deg$cluster==cluster][match(dexp$Feature.ID,deg$gene[deg$cluster==cluster])]
dexp[,paste0("Cluster.",cluster,".Adjusted.p.value")] <- deg$p_val_adj[deg$cluster==cluster][match(dexp$Feature.ID,deg$gene[deg$cluster==cluster])]
}
colnames(dexp) <- gsub("\\."," ",colnames(dexp))
write_csv(dexp,paste0("./analysis/shiny/",anal,"/outs/analysis/diffexp/",gsub("integrated_snn_res.","res_",i),"/differential_expression.csv"),col_names=TRUE)
}
colnames(dexp) <- gsub("\\."," ",colnames(dexp))
write_csv(dexp,paste0("./analysis/shiny/",anal,"/outs/analysis/diffexp/",gsub("integrated_snn_res.","res_",i),"/differential_expression.csv"),col_names=TRUE)
}
}
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