3 #visualizes genetic gain using boxplot.
6 # Isaak Y Tecle (iyt2@cornell.edu)
12 #library(phenoAnalysis)
20 allArgs
<- commandArgs()
22 outputFiles
<- scan(grep("output_files", allArgs
, value
= TRUE),
25 inputFiles
<- scan(grep("input_files", allArgs
, value
= TRUE),
28 trGebvFiles
<- grep("training", inputFiles
, value
= TRUE)
30 message('training file: ', trGebvFiles
)
32 slGebvFiles
<- grep("selection", inputFiles
, value
= TRUE)
34 message('selection file: ', slGebvFiles
)
36 boxplotFile
<- grep("genetic_gain_plot", outputFiles
, value
= TRUE)
37 message('boxplot file: ', boxplotFile
)
39 plotDataFile
<- grep("genetic_gain_data", outputFiles
, value
= TRUE)
40 message('boxplot file: ', plotDataFile
)
45 for (trGebvFile
in trGebvFiles
) {
46 gebv
<- data
.frame(fread(trGebvFile
, header
= TRUE))
47 trait
<- names(gebv
)[2]
48 colnames(gebv
)[2] <- gebvsCol
50 trGebv
<- bind_rows(trGebv
, gebv
)
53 trGebv$pop
<- 'training'
56 for (slGebvFile
in slGebvFiles
) {
57 gebv
<- data
.frame(fread(slGebvFile
, header
= TRUE))
58 trait
<- names(gebv
)[2]
59 colnames(gebv
)[2] <- gebvsCol
61 slGebv
<- bind_rows(slGebv
, gebv
)
64 slGebv$pop
<- 'selection'
66 boxplotData
<- bind_rows(trGebv
, slGebv
)
67 boxplotData$pop
<- as
.factor(boxplotData$pop
)
68 boxplotData$trait
<- as
.factor(boxplotData$trait
)
70 boxplotData$pop
<- with(boxplotData
, relevel(pop
, "training"))
73 ## training <- 'training'
74 ## selection <- 'selection'
78 bp
<- ggplot(boxplotData
,
79 aes(y
=GEBVs
, x
=pop
, fill
=pop
)) +
80 geom_boxplot(width
=0.4) +
81 stat_summary(geom
="text", fun
.y
=quantile
, size
=5,
82 aes(label
=sprintf("%1.3f", ..y
..), color
=pop
),
83 position
=position_nudge(x
=0.35)) +
85 facet_wrap(~trait
, ncol
=2, scales
="free") +
86 theme(legend
.position
="none",
87 axis
.text
=element_text(color
='blue', size
=12, face
='bold'),
88 axis
.title
.y
=element_text(color
='blue'),
89 axis
.title
.x
=element_blank(),
90 strip
.text
.x
=element_text(color
='blue', face
='bold'))
92 wid
<- 480 * if(length(trGebvFiles
) > 1) 2 else 1;
94 png(boxplotFile
, width
=wid
)
98 if (length(plotDataFile
) != 0 ) {
108 q(save
= "no", runLast
= FALSE)