
rm(list=ls())
library(tidyverse)
library(ggpubr)
library(egg)
library(survival)
library(survminer)

coulor2 = c("#00AFBB", "#FC4E07")
coulor3 = c("#00AFBB", "#E7B800", "#FC4E07")
coulor4 = c("#00AFBB", "#E7B800", "#7bc043", "#FC4E07")

## TIDE
## clinical
hrs = read.csv("0105 Glycolysis.lasson.csv")
tme = read.csv("00202 TME.lasson.csv")
tme = tme[,-c(2,3,4)]
data = dplyr::full_join(hrs, tme, by = "ID")

surv = dplyr::filter(data, Cohort %in% c("TCGA_GBM", "TCGA_LGG"))
surv$GRS <- ifelse(surv$GRSscore > median(surv$GRSscore),'GRSHigh', 'GRSLow')
surv$TME <- ifelse(surv$TMEscore > median(surv$TMEscore),'TMELow', 'TMEHigh') 

surv$group = paste(surv$GRS, surv$TME, sep = "/")
table(surv$group)

surv$GRSTME = forcats::fct_collapse(surv$group, Mixed = c("GRSHigh/TMEHigh", "GRSLow/TMELow"))
surv$GRSTME = factor(surv$GRSTME, 
                     levels = c("GRSLow/TMEHigh", "Mixed", "GRSHigh/TMELow"),
                     labels = c("GRSLow/TMEHigh", "Mixed", "GRSHigh/TMELow"))

##
TIDE = read.csv("TIDE.csv")
dat = dplyr::inner_join(TIDE, surv, by="ID")

colnames(dat)
my_com = list(c("GRSHigh/TMELow", "Mixed"), 
              c("Mixed", "GRSLow/TMEHigh"), 
              c("GRSHigh/TMELow", "GRSLow/TMEHigh"))

dat$class = dat$GRSTME

dat$TIDE = dat$Dysfunction + dat$Exclusion
p1 = ggplot(dat, aes(x=class, y=TIDE)) +
  geom_violin(aes(fill=class)) +
  geom_boxplot(width = 0.2, position = position_dodge(width = 1.0)) +
  theme_article() +
  theme(legend.position = "none",
        axis.text = element_text(colour = "black")) +
  labs(x="", y="TIDE score") +
  stat_compare_means(comparisons = my_com, label = "p.signif") 
  #scale_fill_manual(values = coulor3) 

p1


p2 = ggplot(dat, aes(x=class, y=Dysfunction)) +
  geom_violin(aes(fill=class)) +
  geom_boxplot(width = 0.2, position = position_dodge(width = 1.0)) +
  theme_article() +
  theme(legend.position = "none",
        axis.text = element_text(colour = "black")) +
  labs(x="", y="Dysfunction score") +
  stat_compare_means(comparisons = my_com, label = "p.signif") 
  #scale_fill_manual(values = coulor3) 

p2


p3 = ggplot(dat, aes(x=class, y=Exclusion)) +
  geom_violin(aes(fill=class)) +
  geom_boxplot(width = 0.2, position = position_dodge(width = 1.0)) +
  theme_article() +
  theme(legend.position = "none",
        axis.text = element_text(colour = "black")) +
  labs(x="", y="Exclusion score") +
  stat_compare_means(comparisons = my_com, label = "p.signif") 
  #scale_fill_manual(values = coulor3) 

p3


p4 = ggplot(dat, aes(x=class, y=MSI.Expr.Sig)) +
  geom_violin(aes(fill=class)) +
  geom_boxplot(width = 0.2, position = position_dodge(width = 1.0)) +
  theme_article() +
  theme(legend.position = "none",
        axis.text = element_text(colour = "black")) +
  labs(x="", y="MSI score") +
  stat_compare_means(comparisons = my_com, label = "p.signif") 
  #scale_fill_manual(values = coulor3) 

p4


## Hypoxia.riskscore
compaired <- list(c("FALSE","TRUE"))
p5 = ggplot(dat, aes(x=Responder, y=GRSscore)) +
  #geom_violin(aes(fill=Response)) +
  geom_boxplot(aes(fill=Responder)) +
  theme_article() +
  theme(legend.position = "none",
        axis.text = element_text(colour = "black")) +
  labs(x="", y="GRS score") +
  stat_compare_means(comparisons = compaired, label = "p.signif") +
  #scale_fill_manual(values = coulor2)   
  scale_x_discrete(labels=c("TRUE"="Response", "FALSE"="Nonresponse"))

p5


## TME.riskscore
dat$TMEscore = -1*(dat$TMEscore)
p6 = ggplot(dat, aes(x=Responder, y=TMEscore)) +
  #geom_violin(aes(fill=Response)) +
  geom_boxplot(aes(fill=Responder)) +
  theme_article() +
  theme(legend.position = "none",
        axis.text = element_text(colour = "black")) +
  labs(x="", y="TME score") +
  stat_compare_means(comparisons = compaired, label = "p.signif") +
  #scale_fill_manual(values = coulor2)  
  scale_x_discrete(labels=c("TRUE"="Response", "FALSE"="Nonresponse"))

p6


library(patchwork)
pa = p1|p3|p5|p6















