3 #runs genetic correlation analyis.
4 #correlation coeffiecients are stored in tabular and json formats
7 # Isaak Y Tecle (iyt2@cornell.edu)
18 allargs
<-commandArgs()
20 geneticDataFile
<- grep("combined_gebvs",
27 correTableFile
<- grep("genetic_corre_table",
34 correJsonFile
<- grep("genetic_corre_json",
41 geneticData
<- read
.table(geneticDataFile
,
49 coefpvalues
<- rcor
.test(geneticData
,
55 coefficients
<- coefpvalues$cor
.mat
56 allcordata
<- coefpvalues$cor
.mat
58 allcordata
[lower
.tri(allcordata
)] <- coefpvalues$p
.values
[, 3]
59 diag(allcordata
) <- 1.00
61 pvalues
<- as
.matrix(allcordata
)
62 pvalues
<- round(pvalues
,
66 coefficients
<- round(coefficients
,
70 allcordata
<- round(allcordata
,
74 #remove rows and columns that are all "NA"
75 if ( apply(coefficients
,
77 function(x
)any(is
.na(x
))
82 function(x
)any(is
.na(x
))
87 coefficients
<-coefficients
[-which(apply(coefficients
,
89 function(x
)all(is
.na(x
)))
91 -which(apply(coefficients
,
93 function(x
)all(is
.na(x
)))
99 pvalues
[upper
.tri(pvalues
)] <- NA
100 coefficients
[upper
.tri(coefficients
)] <- NA
102 coefficients2json
<- function(mat
){
103 mat
<- as
.list(as
.data
.frame(t(mat
)))
108 traits
<- colnames(coefficients
)
110 correlationList
<- list(
111 "traits"=toJSON(traits
),
112 "coefficients"=coefficients2json(coefficients
)
115 correlationJson
<- paste("{",paste("\"", names(correlationList
), "\":", correlationList
, collapse
=","), "}")
117 write
.table(coefficients
,
125 write
.table(correlationJson
,
131 q(save
= "no", runLast
= FALSE)