-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenericPlotCluster.R
More file actions
64 lines (63 loc) · 2.23 KB
/
GenericPlotCluster.R
File metadata and controls
64 lines (63 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
PlotMyCluster<-function(Exp,Procs=4,Bootstraps=25,RowNames=1,skip=0,log=FALSE,SaveMatrices=FALSE,Features='Features',tissue='Tissue',Corr=FALSE,Boxplot=FALSE) {
library(snow)
library(pvclust)
library(tools)
library(corrplot)
library(ggfortify)
library(phylogram)
dist<-"euclidian"
Exp<-read.table(Exp,row.names=RowNames,header=TRUE)
Exp<-Exp[,-skip]
print(names(Exp))
Exp<-Exp[which(rowSums(Exp)>0),]
cl<-makeCluster(Procs,type="SOCK")
if (log) {
Exp<-log2(Exp+1)
res<-parPvclust(cl,Exp,method.hclust="ward.D", method.dist=dist,nboot=Bootstraps)
pdf(paste(Features,tissue,"_ward.D_",Bootstraps,".pdf",sep=""), width=30, height=20)
plot(res)
dev.off()
res2<-parPvclust(cl,Exp,method.hclust="ward.D2",method.dist=dist,nboot=Bootstraps)
pdf(paste(Features,"_",tissue,"_","ward.D2.",Bootstraps,".pdf",sep=""), width=30, height=20)
plot(res2)
dev.off()
stopCluster(cl)
}
else{
res<-parPvclust(cl,Exp,method.hclust="ward.D", method.dist=dist,nboot=Bootstraps)
pdf(paste(Features,tissue,"_ward.D_",Bootstraps,".pdf",sep=""), width=30, height=20)
plot(res)
dev.off()
res2<-parPvclust(cl,Exp,method.hclust="ward.D2",method.dist=dist,nboot=Bootstraps)
pdf(paste(Features,"_",tissue,"_","ward.D2.",Bootstraps,".pdf",sep=""), width=30, height=20)
plot(res2)
dev.off()
stopCluster(cl)
}
if(SaveMatrices){
write.dendrogram(as.dendrogram(res),paste(Features,tissue,Bootstraps,'wardD','.gram',sep=''),quote=FALSE,sep='\t')
write.dendrogram(as.dendrogram(res2),paste(Features,tissue,Bootstraps,'wardD2','.gram',sep=''),quote=FALSE,sep='\t')
}
else{
warning('Proceeding without saving matrices')
}
if(Corr){
co<-cor(Exp)
pdf(paste("Corrplot_",,tissue,".TPM.pdf",sep=""), width=40, height=40)
corrplot.mixed(co,upper="circle", lower="number", order="hclust",tl.pos="lt")
dev.off()
}
else{
warning('Proceeding without Correlation Plot')
}
if(Boxplot){
boxExp<-Exp[which(rowSums(Exp)>0),]
png(paste("BoxPlot_",Features,tissue,"_",".png",sep=""),width=2000,height=1000)
par(cex.axis=0.9,mai=c(2.8,0.82,0.82,0.42))
boxplot(boxExp,las=2,main="BoxploxNormalizedLog2")
dev.off()
}
else{
warning('Proceeding without BoxPlot')
}
}