-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMegaLMM_drawing.Rmd
170 lines (136 loc) · 5.34 KB
/
MegaLMM_drawing.Rmd
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
---
title: "MegaLMM plot drawing"
author: "Ye Bi"
date: "`r Sys.Date()`"
output: html_document
---
#TTT
```{r}
library(tidyverse)
library(ggplot2)
library(plyr)
library(ggpubr)
library(ggrepel)
library(tidyverse)
library(stargazer)
library(patchwork)
library(ggplot2)
```
## Drawing plots for h2, varE, varG
```{r}
source("../../Functions/functions.R")
met_names = met_name_func(mode = 'name')
```
```{r}
load("../../../temp/mega/fa4/Control_MegaLMM.rda")
corRL_con = corRL
load("../../../temp/mega/Stress_MegaLMM.rda")
corRL_trt = corRL
PreCorr_mega_func <- function(corRL, treatment, met_names){
corR.wide = do.call(rbind, corRL)
colnames(corR.wide) = met_names
corR.wide = cbind.data.frame(CV = 1:100,
corR.wide,
Treatment = treatment)
corR.long = tidyr::gather(corR.wide, key="Met", value="Corr", -c(CV, Treatment))
}
PreCorr_mega_G=rbind(PreCorr_mega_func(corRL=corRL_con, treatment="Control", met_names=met_names),
PreCorr_mega_func(corRL=corRL_trt, treatment="Stress", met_names=met_names))
PreCorr_mega_G$Met <- factor(PreCorr_mega_G$Met, levels = met_names)
PreCorr_mega_G$Kernel <- "Mega-G"
```
###Read in Mega-GK pred corr
```{r}
path = "../../../temp/mega/GK/GK_0.2"
PreCorr0.2 = load_pred_corr_func(path=path, kernel = "GK_0.2", namm="mega_")
path = "../../../temp/mega/GK/GK_0.4"
PreCorr0.4 = load_pred_corr_func(path=path, kernel = "GK_0.4", namm="mega_")
path = "../../../temp/mega/GK/GK_0.6"
PreCorr0.6 = load_pred_corr_func(path=path, kernel = "GK_0.6", namm="mega_")
path = "../../../temp/mega/GK/GK_0.8"
PreCorr0.8 = load_pred_corr_func(path=path, kernel = "GK_0.8", namm="mega_")
```
##Read in GBLUP pred corr
```{r}
path.bglr = "../../../ARC_outputs/Met_same_genotypes_per_treatment/GBLUP/outputs_GBLUP/"
PreCorr = load_pred_corr_func(path=path.bglr, kernel = "BGLR", namm=NULL)
```
##Calculate diff
```{r}
BGLR_G_mu <- pred_mean_generator(PreCorr)
mega_G_mu <- pred_mean_generator(PreCorr_mega_G) #Origin_MegaLMM_test.Rmd
mega_GK_mu0.2 <- pred_mean_generator(PreCorr0.2) #GK.Rmd
mega_GK_mu0.4 <- pred_mean_generator(PreCorr0.4)
mega_GK_mu0.6 <- pred_mean_generator(PreCorr0.6)
mega_GK_mu0.8 <- pred_mean_generator(PreCorr0.8)
mega_GK_comp = cbind(GK0.2 = mega_GK_mu0.2$corr.mean,
GK0.4 = mega_GK_mu0.4$corr.mean,
GK0.6 = mega_GK_mu0.6$corr.mean,
GK0.8 = mega_GK_mu0.8$corr.mean)
mega_GK_mu = apply(mega_GK_comp, 1, max)
mega_GK_mu = cbind.data.frame(mega_GK_mu0.2[,1:2],
corr.mean = mega_GK_mu)
```
```{r}
BGLR_G_mu$corr.mean[BGLR_G_mu$corr.mean < 0.1]=0
dff_mega_g=pred_dff_generator(df1=BGLR_G_mu,
df2=mega_G_mu,
Method="MegaLMM-G")
dff_mega_gk=pred_dff_generator(df1=BGLR_G_mu,
df2=mega_GK_mu,
Method="MegaLMM-GK")
my_colors <- RColorBrewer::brewer.pal(11, 'PiYG')[c(9, 2)]
ccc = rbind(dff_mega_g, dff_mega_gk)
ccc$Method = factor(ccc$Method, levels=c("RKHS", "MegaLMM-G", "MegaLMM-GK"))
ttt = ccc[!is.infinite(ccc$value), ]
ttt = ttt %>% filter(value >= 0) %>% droplevels()
limm = c(floor(min(ttt$value)), ceiling(max(ttt$value)))
dp_diff <- ggplot(ttt, aes(x=Met, y=value, fill=Method)) +
geom_bar(stat="identity",position="dodge")+
facet_grid(rows = vars(Treatment))+
labs(x="Metabolite accumulation", y = "Percentage difference (%)") +
theme_bw()+
geom_hline(aes(yintercept = 0), color = 'grey', linetype='solid', linewidth = 0.3)+
scale_y_continuous(limits=c(-25, 50), breaks=seq(-30,50,10)) +
scale_fill_manual(values = alpha(my_colors, 0.8))+
# scale_color_manual(values = my_colors)+
theme(axis.text.x=element_text(size=8, angle=90, hjust=0.95, vjust=0.2),
axis.text.y=element_text(size=8),
axis.title.y = element_text(margin = margin(r=6)),
legend.position = "right")
dp_diff
# dev.print(pdf, file="../temp/mega_bglr_diff_barplot.pdf", height = 6, width = 20)
```
```{r}
my_colors <- RColorBrewer::brewer.pal(11, 'Spectral')[c(10,3)]
dff_mega_g_dens=density_plot_generator(df=dff_mega_g,
my_colors=my_colors,
limits_range = c(-40,40),
breaks_range = seq(-40,40,10),
x_name = "Percentage difference (%)",
lines = F,
ylim = c(0, 0.2))
dff_mega_gkk_dens=density_plot_generator(df=dff_mega_gk,
my_colors=my_colors,
limits_range = c(-40,40),
breaks_range = seq(-40,40,10),
x_name = "Percentage difference (%)",
lines = F,
ylim = c(0, 0.2))
# print(p33)
# dev.print(pdf, file=paste0("../temp/G_GK_PredCorr_density.pdf"), height=4, width=8)
```
```{r}
library(ggpubr)
ggarrange(dp_diff,
NULL,
ggarrange(dff_mega_g_dens, dff_mega_gkk_dens,
ncol = 2, labels = c("(B)", "(C)"),
vjust=-0.1,
common.legend = T,
legend = "right"),
nrow = 3,
labels = "(A)",vjust=1.5, hjust=0,
heights = c(2, 0.1, 1))
dev.print(pdf, file="../../../temp/G_GK_Mega.pdf", height = 10, width = 10)
```