So, lets load RMarkdown
library(rmarkdown)
set messages to FALSE on everything (prevents certain boring things from being shown in the results)
knitr::opts_chunk$set(echo = TRUE, message=FALSE,warning=FALSE,collapse = TRUE)
PACKAGES
library(reshape2)
library(ggplot2)
library(dplyr)
library(plotly)
library(viridis)
library(data.table)
library(pheatmap)
library(tidyverse)
library(ggthemes)
library(clipr)
library(tidyr)
COLORS
mycolors<-c(viridis(15))
felix_cols<-mycolors[c(5,2)]
felix_4cols<-mycolors[c(15,10,8,2)]
plain_cols1<-c("blue","gray")
plain_cols2<-c("red","gray")
pats_cols<-colorRampPalette(c("#FDE725FF", "white","#440154FF"))(21)
leos_cols<-colorRampPalette(c("white","blue"))(10)
LOAD DATA AND MAKE AN OVERALL HEATMAP
## load the dataset
C19_data<-read_csv(file="COVID.csv")
## make some new columns that store the log ratios
C19_data<-C19_data %>% mutate(log_2h=log2((Virus_2h_1+Virus_2h_2)/(Control_2h_1+Control_2h_2)),
log_6h=log2((Virus_6h_1+Virus_6h_2)/(Control_2h_1+Control_2h_2)),
log_10h=log2((Virus_10h_1+Virus_10h_2)/(Control_2h_1+Control_2h_2)),
log_24h=log2((Virus_24h_1+Virus_24h_2)/(Control_2h_1+Control_2h_2)))%>%
arrange(-log_24h)
## make a matrix of just the data
C19_mat1<-C19_data %>%
select(Control_2h_1:Virus_24h_2) %>%
as.matrix() %>%
round(.,2)
## make a heatmap from the data (NOTE: this is set to cluster the rows. You can remove that if you like. You can also try clustering the columns to see how the samples cluster)
pheatmap(C19_mat1, color=pats_cols,cellwidth=30,cellheight=.06,cluster_cols=FALSE,cluster_rows=TRUE,
legend=TRUE,fontsize = 7,scale="row")

PLOTTING A VOLCANO
##BASIC VOLCANO PLOT
## Add a column that stores the negative log of the pvalue
C19_data<-C19_data %>% mutate(neglog_24h=-log10(P_value_24h))
## Use ggplot to plot the log ratio at 24 hours against the -log p-value at 24 hours
volcano_plot<-C19_data %>% ggplot(aes(x=log_24h,y=neglog_24h,description=Gene_Symbol))+
geom_point(alpha=0.7,color="blue")
volcano_plot

## BETTER VOLCANO PLOT
## Define the siginificant ones so they can be colored
C19_data<-C19_data %>% mutate(significance=ifelse((log_24h>2 & neglog_24h>2.99),"UP",
ifelse((log_24h<c(-2) & neglog_24h>2.99),"DOWN","NOT SIG")))
## Define some standard colors
plain_cols3<-c("red","gray","blue")
## volcano plot as before with some added things
optional_volcano_plot<-C19_data %>% ggplot(aes(x=log_24h,y=neglog_24h,description=Gene_Symbol,color=significance))+
geom_point(alpha=0.7)+
scale_color_manual(values=plain_cols3)+
xlim(-6,6)+
theme_bw()+
theme(axis.text = element_text(colour = "black",size=14))+
theme(text = element_text(size=14))+
labs(x="log ratio at 24 hrs COVID-19 infection compared to control",y="-log(p-value)")
optional_volcano_plot

## use ggplotly to see hover over the points to see the gene names
ggplotly(optional_volcano_plot)
HEATMAP
## EXAMPLES OF A COUPLE PROTEINS
## based on the gene symbols from plotly, select a few proteins from the table. Select just the data and gene symbols then melt
Examples_Down<-C19_data %>% filter(Gene_Symbol=="SHH" | Gene_Symbol=="APLP2;APP" | Gene_Symbol=="TSPYL1") %>%
select(Gene_Symbol,Control_2h_1:Virus_24h_2) %>%
melt()
## make barplots facetted by Gene Symbol
Example_plot_down<-Examples_Down %>% ggplot(aes(x=variable,y=value))+
geom_bar(stat="identity",fill="royalblue")+
facet_wrap(~Gene_Symbol)+
theme_bw()+
theme(axis.text = element_text(colour = "black",size=10))+
theme(text = element_text(size=14))+
theme(axis.text.x = element_text(angle=45, hjust=1))+
labs(x="sample",y="relative intensity")
Example_plot_down

## Same process for the upregulated ones (Here, for example are some of the viral proteins. It's clear that the virus is replicating in these cells)
Examples_Up<-C19_data %>% filter(Gene_Symbol=="Viral_Protein_4" | Gene_Symbol=="Viral_Protein_8") %>%
select(Gene_Symbol,Control_2h_1:Virus_24h_2) %>%
melt()
Example_plot_up<-Examples_Up %>% ggplot(aes(x=variable,y=value))+
geom_bar(stat="identity",fill="royalblue")+
facet_wrap(~Gene_Symbol)+
theme_bw()+
theme(axis.text = element_text(colour = "black",size=10))+
theme(text = element_text(size=14))+
theme(axis.text.x = element_text(angle=45, hjust=1))+
labs(x="sample",y="relative intensity")
Example_plot_up
