-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex_vivos.rmd
41 lines (34 loc) · 1.3 KB
/
ex_vivos.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
---
title: "R Notebook"
output: html_notebook
---
Read the metabolomics data
```{r}
library(data.table)
library(readxl)
library(magrittr)
abundance <- read_excel("../ex_vivos_2019/metabolon_quant.xlsx", sheet="abundance", col_names = FALSE)
mets <- read_excel("../ex_vivos_2019/metabolon_quant.xlsx", sheet="metabolites") %>% setDT()
samples <- read_excel("../ex_vivos_2019/metabolon_quant.xlsx", sheet="samples") %>% setDT()
colnames(abundance) <- samples$sample_id
abundance$metabolite_id <- mets$compound_id
abundance <- as.data.table(abundance) %>% melt(id.vars = "metabolite_id",
variable.name = "sample_id", value.name = "abundance")
abundance <- mets[abundance, on = c(compound_id = "metabolite_id")]
abundance <- samples[abundance, on = "sample_id"]
```
Now we read the inferred composition:
```{r}
diet <- fread("data/mgx/food_contents.csv")
compounds <- diet[source_type == "Compound"]
```
```{r, fig.width=20, fig.height=16}
library(pheatmap)
food <- fread("data/mgx/food_abundances.csv")
means <- food[, .(reads = mean(reads), relative = mean(fraction)), by="taxon"]
M <- dcast(food, taxon ~ sample_id, value.var = "fraction", fun.aggregate = mean, fill = 0)
n <- M[, taxon]
M <- as.matrix(M[, taxon := NULL])
rownames(M) <- n
pheatmap(M, cluster_cols=FALSE)
```