3 #commands for running correlation analyis,
4 #and generating heatmap and the correlation
5 #coefficients and their p-values
9 # Isaak Y Tecle (iyt2@cornell.edu)
18 allargs
<-commandArgs()
20 phenodata
<-grep("phenodata",
27 cortable
<-grep("corre_table",
34 print(c("correlation table file:", cortable
))
36 heatmap
<-grep("heatmap",
43 print(c("heatmap file:", heatmap
))
45 #reading phenotype data into an R object
46 phenodata
<-read
.csv(phenodata
,
50 na
.strings
=c("NA", "-")
55 #running Pearson correlation analysis
56 coefpvalues
<-rcor
.test(phenodata
,
61 coefficients
<-coefpvalues$cor
.mat
62 allcordata
<-coefpvalues$cor
.mat
63 allcordata
[lower
.tri(allcordata
)]<-coefpvalues$p
.values
[, 3]
64 diag(allcordata
)<-1.00
67 pvalues
<-as
.matrix(allcordata
)
70 pvalues
<-round(pvalues
,
75 #rounding correlation coeficients into 2 decimal places
76 coefficients
<-round(coefficients
,
80 allcordata
<-round(allcordata
,
84 #remove rows and columns that are all "NA"
85 if ( apply(coefficients
,
87 function(x
)any(is
.na(x
))
92 function(x
)any(is
.na(x
))
97 coefficients
<-coefficients
[-which(apply(coefficients
,
99 function(x
)all(is
.na(x
)))
101 -which(apply(coefficients
,
103 function(x
)all(is
.na(x
)))
108 print("correlation coeffients:")
111 pvalues
[upper
.tri(pvalues
)]<-NA
112 coefficients
[upper
.tri(coefficients
)]<-NA
121 heatmap
.2(coefficients
,
126 col
= rev(colorRampPalette(brewer
.pal(10,"Spectral"))(128)),
132 lmat
=rbind( c(0,3), c(2,1), c(0,4)),
133 lhei
=c(0.25, 4, 0.75),
142 write
.table(coefficients
,
150 q(save
= "no", runLast
= FALSE)