Commit 0f7116a9 authored by Gervaise Henry's avatar Gervaise Henry 🤠
Browse files

Fix cutoff scale/unscale

parent 7e42e192
......@@ -225,10 +225,10 @@ scQC <- function(sc10x,sp="hu"){
plots.s[[j]] <- ggplotGrob(ggplot(data.frame(cbind(sc10x.temp$nCount_RNA,sc10x.temp[[i]][,1])))+geom_point(aes(x=X1,y=X2,color=densities.s[[j]]),size=0.1)+scale_x_continuous(limits=c(0,max.ct))+scale_y_continuous(limits=c(0,max.y))+scale_color_viridis(option="inferno")+labs(x="nCount",y=i,color="Density")+ggtitle(j)+cowplot::theme_cowplot()+theme(plot.title=element_text(size=7.5),axis.title=element_text(size=7.5),axis.text=element_text(size=5,angle=45),legend.position="bottom",legend.title=element_text(size=5,face="bold",vjust=1),legend.text=element_text(size=5,angle=45))+guides(color=guide_colourbar(barwidth=5,barheight=0.5))+geom_hline(yintercept=cutoff.l,size=0.1,color="red")+geom_hline(yintercept=cutoff.h,size=0.1,color="red"))
cells.remove[[j]] <- c(cells.remove[[j]],rownames(sc10x[[j]][[i]])[sc10x[[j]][[i]][,1] < cutoff.l | sc10x[[j]][[i]][,1] > cutoff.h])
}
}
ggsave(paste0("./analysis/qc/Violin_qc.raw.",i,".eps"),marrangeGrob(grobs=plots.v,nrow=1,ncol=length(sc10x),top=NULL))
if (i %in% c("nFeature_RNA","percent.mito")){
ggsave(paste0("./analysis/qc/Plot_qc.raw.",i,".eps"),marrangeGrob(grobs=plots.s,nrow=1,ncol=length(sc10x),top=NULL))
ggsave(paste0("./analysis/qc/Violin_qc.raw.",i,".",j,".eps"),plot=plots.v[[j]])
if (i %in% c("nFeature_RNA","percent.mito")){
ggsave(paste0("./analysis/qc/Plot_qc.raw.",i,".",j,".eps"),plot=plots.s[[j]])
}
}
}
......@@ -335,12 +335,14 @@ scThresh <- function(sc10x,feature,sub=FALSE){
scale[[i]] <- data.frame(Score=sc10x[[i]][[feature]])
colnames(scale[[i]]) <- "Score"
scale[[i]] <- data.frame(Score=scale[[i]]$Score[!is.na(scale[[i]]$Score)])
scale.scaled[[i]] <- as.integer(scales::rescale(scale[[i]]$Score,to=c(0,1))*360)
h[[i]] <- hist(scale[[i]]$Score,breaks=50,plot=FALSE)
scale.scaled[[i]] <- as.integer((scale[[i]]$Score-min(scale[[i]]$Score))/(max(scale[[i]]$Score)-min(scale[[i]]$Score))*360)
#scale.scaled[[i]] <- as.integer(scales::rescale(scale[[i]]$Score,to=c(0,1))*360)
h[[i]] <- hist(scale[[i]]$Score,breaks=100,plot=FALSE)
thresh[[i]] <- purrr::map_chr(thresh_methods, ~auto_thresh(scale.scaled[[i]], .)) %>%
tibble(method = thresh_methods, threshold = .)
thresh[[i]]$threshold <- as.numeric(thresh[[i]]$threshold)
thresh[[i]] <- thresh[[i]] %>% mutate(threshold=(scales::rescale(threshold/360,to=range(scale[[i]]$Score))))
thresh[[i]]$threshold <- ((thresh[[i]]$threshold/360)*(max(scale[[i]]$Score)-min(scale[[i]]$Score)))+min(scale[[i]]$Score)
#thresh[[i]] <- thresh[[i]] %>% mutate(threshold=(scales::rescale(as.numeric(threshold)/360,to=range(scale[[i]]$Score))))
postscript(paste0(folder,"Hist_qc.",i,".",feature,".eps"))
plot(h[[i]],main=paste0("Histogram of ",feature," of sample ",i),xlab=feature)
abline(v=thresh[[i]]$threshold)
......
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