-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheggnog_MSP_analysis.Rmd
256 lines (169 loc) · 6.35 KB
/
eggnog_MSP_analysis.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
---
title: "eggnog_MSP_analysis"
author: "ruben"
date: "06/07/2022"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Librairies
```{r,message=F,warning=F}
library(dplyr)
library(readr)
library(pheatmap)
library(data.table)
library(tidyr)
library(tibble)
library("factoextra")
library("FactoMineR")
library(RColorBrewer)
library(stringr)
source(file = "functions.R")
```
## import MSP data
```{r,message=F,warning=F}
microbiome_resources = "/lustre/workgroups/microbiome_resources/reference/IGC/annotation/"
msp_genes = readr::read_tsv(paste0(microbiome_resources,"msp.tsv"))
## merge with the couple msp/sample
msp_sample_count <- readr::read_tsv("data-raw/MilieuInterieur/MilieuInterieur_samples_msp_module_counts.tsv")
## contains MSP with KO, EC, eggnog annotations
## ID = eggNOG_OGs
msp_file <- readr::read_tsv("test/IGC.eggNOG_v5.0.tsv", skip=2) %>%
dplyr::rename("gene_id" = "query") %>%
data.frame()
head(msp_file)
## gene richness and reads mapped
msp_gene_richness <- readr::read_tsv("data-raw/MilieuInterieur/MilieuInterieur_genes_richness.tsv")
###
msp_gene <- readr::read_tsv("/lustre/workgroups/microbiome_resources/reference/IGC/annotation/msp.tsv")
## MSP associated with taxonomy
MSP_taxonomy <- readr::read_tsv("/lustre/workgroups/microbiome_resources/reference/IGC/annotation/1661_msps.gtdb_r95_taxonomy.tsv")
name_milieu_interieur_bifidobacterium <- "MilieuInterieur_df_Bidobacterium.tsv"
## MSP df contain the count of genes (X1 = gene_id)
if(!(name_milieu_interieur_bifidobacterium %in% list.files())){
MSP_df <- get(load("data-raw/MilieuInterieur/MilieuInterieur_df_long.rda")) %>%
dplyr::rename(gene_id = X1)
## filter the msp modules associated with bifidobacterium genus
msp_specific_bifido <- MSP_taxonomy %>%
filter(., grepl("Bifidobacterium", gtdb_classification)) %>%
select(msp_name)
### filter the genes associated with these msp
gene_to_filter <- msp_gene %>%
filter(., grepl(msp_specific_bifido$msp_name, msp_name_module_name)) %>%
.$gene_name %>%
unique()
## these are the gene names to filter in the table
MSP_df_filtered <- MSP_df %>%
filter(gene_id %in%gene_to_filter) %>%
distinct()
write_tsv(MSP_df_filtered, file = name_milieu_interieur_bifidobacterium)
} else{
MSP_df_filtered <- readr::read_tsv(name_milieu_interieur_bifidobacterium)
}
```
## import eggnog data
```{r,message=F,warning=F}
eggnog_age_category <- readr::read_csv2("association_eggnogs_metadata_age_category.csv")
eggnog_grp_healthy <- readr::read_csv2("association_eggnogs_metadata_grp_healthy.csv")
eggnog_westernized <- readr::read_csv2("association_eggnogs_metadata_westernized.csv")
```
## filter p value eggnog data
```{r,message=F,warning=F}
egg_healthy_filtered <- eggnog_grp_healthy %>%
filter(p.value < 0.10) %>%
select(assigned_species, variable, eggnog)
egg_age_filtered <- eggnog_age_category %>%
filter(p.value < 0.10) %>%
select(assigned_species, variable, eggnog)
egg_wetsernized_filtered <- eggnog_westernized %>%
filter(p.value < 0.10) %>%
select(assigned_species, variable, eggnog)
all_eggnogs <- egg_age_filtered %>%
rbind(egg_healthy_filtered) %>%
rbind(egg_wetsernized_filtered) %>%
## need to remove any duplicate
arrange(eggnog) %>%
filter(duplicated(eggnog) == FALSE)
```
## import filter gene associated with eggnogs
```{r,message=F,warning=F}
select_eggnog_msp <- msp_file %>%
dplyr::rename("eggnog" = "eggNOG_OGs") %>%
filter(eggnog %in% all_eggnogs$eggnog) %>%
select(eggnog, gene_id) %>%
distinct()
```
## import bifidotypes
```{r,message=F,warning=F}
bifidotype <- fread("enterotype_DMM_msp") %>%
select(-V1) %>%
# delete X
mutate(sample_id = gsub("X", "", sample_id)) %>%
## transform bifidotype col to character
#transform(bifidotype = as.character(bifidotype)) %>%
## mutate 4 which is the "low_diversity" cluster
mutate(bifidotype = case_when(
bifidotype %in% c(4) ~ "low diversity",
TRUE ~ "high diversity"
))
```
## import eggnog data
```{r,message=F,warning=F}
## select the gene count to get the eggnog 0/1 per sample
eggnog_counts <- MSP_df_filtered %>%
## correct the sample ids
mutate(sample = sub("^0+", "", sample)) %>%
inner_join(select_eggnog_msp, by = "gene_id") %>%
select(- gene_id) %>%
distinct() %>%
## need to sum the count per gene x sample
group_by(eggnog, sample) %>%
summarise(count = sum(count)) %>%
ungroup() %>%
mutate(count = ifelse(. > 0, 1, .)) %>%
reshape2::dcast(eggnog~sample, value.var = "count", fill=0) %>%
tibble::column_to_rownames("eggnog") %>%
as.matrix() %>%
pheatmap::pheatmap(show_colnames = FALSE, show_rownames = FALSE, main = "", method = "ward.D",
annotation_row = all_eggnogs %>% column_to_rownames("eggnog"),
annotation_col = bifidotype %>% column_to_rownames("sample_id"))
## lignes : eggnogs
## colonnes : sample
```
## study specific eggnog signals in curated eggnog tables
```{r,message=F,warning=F}
eggnog_bifidum_healthy <- eggnog_grp_healthy %>%
filter(p.value < 0.10) %>%
filter(assigned_species %in% "Bifidobacterium bifidum") %>%
## filter phage eggnog
#filter(str_detect(Description, "Phage") | str_detect(Description, "phage")) %>%
## filter the eggnog with higher prevalence in unhealthy
#filter(prevalence_unhealthy > prevalence_healthy) %>%
select(assigned_species, variable, eggnog) %>%
distinct()
## filter eggnog
select_eggnog_msp <- msp_file %>%
dplyr::rename("eggnog" = "eggNOG_OGs") %>%
filter(eggnog %in% eggnog_bifidum_healthy$eggnog) %>%
select(eggnog, gene_id) %>%
distinct()
##
## filter the msp modules associated with bifidum
msp_specific_bifido <- MSP_taxonomy %>%
filter(., grepl("bifidum", gtdb_classification)) %>%
select(msp_name)
### filter the genes associated with bifidum msp & eggnog of interest
gene_to_filter <- msp_gene %>%
## filter bifidum
filter(grepl(msp_specific_bifido$msp_name, msp_name_module_name)) %>%
# filter bifidum gene/eggnogs
filter(., grepl(select_eggnog_msp$gene_id, gene_name)) %>%
.$gene_name %>%
unique()
## these are the gene names to filter in the table
## calculate the prevalence of this gene
## gene count per sample
count_gene_interest <- msp_gene_richness %>%
merge(MSP_df_filtered %>% filter(gene_id %in% gene_to_filter), by = sample, all=TRUE)
```