forked from lch14forever/hospital_microbiome
-
Notifications
You must be signed in to change notification settings - Fork 5
/
figure2.illumina_ar_gene_analysis.Rmd
105 lines (93 loc) · 3.53 KB
/
figure2.illumina_ar_gene_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
---
title: "Antibiotics resistance gene prevalence in illumina shotgun metagenomic data"
output:
html_document:
df_print: paged
---
### Antibiotics resistance gene prevalence in illumina shotgun metagenomic data
Load generic libraries
```{r message=FALSE, warning=FALSE}
source('configuration.r')
```
Load plot specific libraries
```{r message=FALSE, warning=FALSE}
library(pheatmap)
library(RColorBrewer)
```
Merge data
```{r}
metadata <-read.table("../metadata/illumina_metadata.txt",sep="\t",head=T) %>%
filter(timept %in% c(1,2))
anti <-read.table("../tables/illumina_AR_gene_assignment.dat",sep="\t",head=T)
df.anti <- merge(metadata, anti, by.x='Site', by.y='Lib') %>%
mutate(Anti_type=gsub('.*_','',Anti)) %>%
group_by(Sample_type,Anti_type,Anti,Library) %>%
summarise() %>%
group_by (Sample_type, Anti_type, Anti) %>%
tally()
plot.dat <- group_by(metadata, Sample_type) %>%
tally() %>%
merge(df.anti, by='Sample_type') %>%
mutate(prev=n.y/n.x) %>%
mutate(Sample_type= str_replace(Sample_type, "_"," ") %>%
str_replace("Door handle-interior", "Door Handle")) %>%
mutate(Anti= str_replace(Anti, "_[a-zA-Z]+$","") %>%
str_replace("_"," "))
```
Helper function to plot
```{r}
plot.heatmap <- function(anti_type, col='PuBu', cluster_rows=TRUE, cluster_cols=TRUE, log_mat=TRUE, title=NA){
plot.dat.w <- filter(plot.dat,Anti_type==anti_type) %>%
select(-Anti_type,-n.x,-n.y) %>%
spread(Sample_type, prev, fill=0) %>%
column_to_rownames("Anti")
if(!log_mat){
pheatmap(plot.dat.w*100,color=(colorRampPalette(brewer.pal(9, col))(1000)), main=anti_type,
fontsize = 12, fontsize_row = 10, fontsize_col = 10,
border_color="black",cluster_rows = cluster_rows, cluster_cols = cluster_cols, silent=TRUE)
}else{
pheatmap(log10(plot.dat.w*100+1),color=(colorRampPalette(brewer.pal(9, col))(1000))[1:round(1000*max(log10(plot.dat.w*100+1))/log10(101))],
main=title,
legend_breaks = log10(c(0,1, 2, 5, 10, 20, 50, 100, 120)+1),
legend_labels = as.character(c(0, 1, 2, 5, 10, 20, 50, 100, 120)),
fontsize = 12, fontsize_row = 10, fontsize_col = 10,
border_color="black",cluster_rows = cluster_rows, cluster_cols = cluster_cols, silent=TRUE)
}
}
```
Run plot
```{r fig.height=6, fig.width=4}
#Fig 1e
m1 <- plot.heatmap("Bla", 'Reds')
#Suppl 2
s1 <- plot.heatmap("AGly", 'Spectral', title = 'Aminoglycosides')
s2 <- plot.heatmap("Tet", 'Spectral', title = 'Tetracyclines')
s3 <- plot.heatmap("Phe", 'Spectral', title = 'Phenicols')
s4 <- plot.heatmap("MLS", 'Spectral', title = 'Macrolide-Lincosamide-\nStreptogramin')
s5 <- plot.heatmap("Sul", 'Spectral', title = 'Sulfonamides')
s6 <- plot.heatmap("Gly",'Spectral', title = 'Glycopeptides')
s7 <- plot.heatmap("Rif", 'Spectral', cluster_rows = F, cluster_cols = F, title = 'Rifampicin')
s8 <- plot.heatmap("Tmt", 'Spectral', title = 'Trimethoprim')
s9 <- plot.heatmap("Flq", 'Spectral', title = 'Fluoroquinolones')
```
Main
```{r fig.height=7, fig.width=4}
cowplot::plot_grid(m1$gtable)
ggsave('../plots/fig2e_antibiotics_profile.pdf', height = 7, width = 4)
```
Supplementary figures
```{r fig.height=10, fig.width=13}
cowplot::plot_grid(
cowplot::plot_grid(s1$gtable, s2$gtable, s3$gtable, s4$gtable, nrow=1),
NULL,
cowplot::plot_grid(s5$gtable, s6$gtable, s7$gtable, s8$gtable, s9$gtable, nrow=1, align='h'),
NULL,
ncol=1,
rel_heights = c(4,0.5,2,0.5)
)
ggsave('../plots/sup6_antibiotics_profile.pdf', height = 10, width = 13)
```
### Session informaton
```{r}
sessionInfo()
```