diff --git a/figures/src/PathoFact_AMR_Figures.R b/figures/src/PathoFact_AMR_Figures.R new file mode 100644 index 0000000000000000000000000000000000000000..56df94a5a0eacc69ca952bf27956714276e061fa --- /dev/null +++ b/figures/src/PathoFact_AMR_Figures.R @@ -0,0 +1,96 @@ +# To generate figures for PathoFact output +library(tidyverse) +library(ggplot2) +################# +# Preprocessing # +################# +ONT <- read.csv("~/Documents/R_data/nanopore_ONT/pathofact_AMR/PathoFact_ONT.csv", row.names=1) +# Toxin prediction +Toxin_confidence_level <- c("-","1","2") +Toxin_prediction <- c("non-pathogenic","secreted","non-secreted") +Toxin <- data.frame(Toxin_confidence_level,Toxin_prediction) +Toxin_ONT <- ONT %>% group_by(Toxin_confidence_level, Sample) %>% summarise(RNum_Gi=sum(RNum_Gi)) +Toxin_ONT <- left_join(Toxin_ONT, Toxin, by="Toxin_confidence_level") +# Virulence prediction +Virulence_confidence_level <- c("-","1","2","3","4") +virulence_prediction <- c("non-pathogenic","secreted","non-secreted","non-pathogenic","non-pathogenic") +Virulence <- data.frame(Virulence_confidence_level,virulence_prediction) +Virulence_ONT <- ONT %>% group_by(Virulence_confidence_level, Sample) %>% summarise(RNum_Gi=sum(RNum_Gi)) +Virulence_ONT <- left_join(Virulence_ONT, Virulence) +Virulence_ONT <- Virulence_ONT %>% group_by(virulence_prediction, Sample) %>% summarise(RNum_Gi=sum(RNum_Gi)) +# AMR prediction +AMR_ONT <- ONT %>% select(10,15,16) +AMR_ONT$AMR <- ifelse(AMR_ONT$AMR_Category == "-", "-", "AMR") +## Overall AMR +AMR_ONT_overall <- AMR_ONT %>% group_by(AMR, Sample) %>% summarise(RNum_Gi=sum(RNum_Gi)) +## AMR category +AMR_ONT_category <- AMR_ONT %>% group_by(AMR_Category, Sample) %>% summarise(RNum_Gi=sum(RNum_Gi)) + +ONT <- read.csv("~/Documents/R_data/nanopore_ONT/pathofact_AMR/PathoFact_ONT.csv", row.names=1) +# Toxin prediction +Toxin_confidence_level <- c("-","1","2") +Toxin_prediction <- c("non-pathogenic","secreted","non-secreted") +Toxin <- data.frame(Toxin_confidence_level,Toxin_prediction) +Toxin_ONT <- ONT %>% group_by(Toxin_confidence_level, Sample) %>% summarise(RNum_Gi=sum(RNum_Gi)) +Toxin_ONT <- left_join(Toxin_ONT, Toxin, by="Toxin_confidence_level") +# Virulence prediction +Virulence_confidence_level <- c("-","1","2","3","4") +virulence_prediction <- c("non-pathogenic","secreted","non-secreted","non-pathogenic","non-pathogenic") +Virulence <- data.frame(Virulence_confidence_level,virulence_prediction) +Virulence_ONT <- ONT %>% group_by(Virulence_confidence_level, Sample) %>% summarise(RNum_Gi=sum(RNum_Gi)) +Virulence_ONT <- left_join(Virulence_ONT, Virulence) +Virulence_ONT <- Virulence_ONT %>% group_by(virulence_prediction, Sample) %>% summarise(RNum_Gi=sum(RNum_Gi)) +# AMR prediction +AMR_ONT <- ONT %>% select(10,15,16) +AMR_ONT$AMR <- ifelse(AMR_ONT$AMR_Category == "-", "-", "AMR") +## Overall AMR +AMR_ONT_overall <- AMR_ONT %>% group_by(AMR, Sample) %>% summarise(RNum_Gi=sum(RNum_Gi)) +## AMR category +AMR_ONT_category <- AMR_ONT %>% group_by(AMR_Category, Sample) %>% summarise(RNum_Gi=sum(RNum_Gi)) + +########### +# Figures # +########### +#FIGURES +#set theme +theme_set(theme_bw() + + theme(strip.background = element_rect(colour = "black", fill = "white"), strip.text = element_text(size=14, family="Arial")) + + theme(axis.text.x = element_text(angle = 90, size = 12, family = "Arial", hjust = 0.95), + axis.text.y = element_text(size = 14, family = "Arial"), + axis.title.y = element_text(size = 12, family = "Arial"), + axis.title.x=element_text(size = 14, face = "bold", family = "Arial"), + axis.ticks.x=element_blank()) + + theme(plot.title = element_text(hjust = 0.5)) + + theme(legend.text = element_text(size = 9, family = "Arial"), + legend.title = element_text(size = 9, family = "Arial", face = "bold"), legend.direction = "vertical", legend.box = "vertical")) +# Toxin Figure +Toxin_ONT_figure <- Toxin_ONT %>% filter(Toxin_prediction != "non-pathogenic") +Toxin_plot <- Toxin_ONT_figure %>% ggplot(aes(x=Sample, y=RNum_Gi, fill = Sample)) + + geom_bar(stat = "identity") + + facet_grid(~ Toxin_prediction) + + xlab(element_blank()) + + ylab("relative abundance (RNum_Gi)") + + ggtitle("Toxin") + + theme(legend.position = "none") # out comment for legend +# Virulence Figure +Virulence_ONT_figure <- Virulence_ONT %>% filter(virulence_prediction != "non-pathogenic") +Virulence_plot <- Virulence_ONT_figure %>% ggplot(aes(x=Sample, y=RNum_Gi, fill = Sample)) + + geom_bar(stat = "identity") + + facet_grid(~ virulence_prediction) + + xlab(element_blank()) + + ylab("relative abundance (RNum_Gi)") + + ggtitle("Virulence") + + theme(legend.position = "none") +# AMR overall Figure +AMR_ONT_overall_Figure <- AMR_ONT_overall %>% filter(AMR != "-") +AMR_plot <- AMR_ONT_overall_Figure %>% ggplot(aes(x=Sample, y=RNum_Gi, fill = Sample)) + + geom_bar(stat = "identity") + + facet_grid(~ AMR) + + xlab(element_blank()) + + ylab("relative abundance (RNum_Gi)") + + ggtitle("AMR") + +# Combine figures +library(cowplot) +plot_grid(Virulence_plot, Toxin_plot, AMR_plot, nrow = 1, labels = "auto") +