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
breast_cancer<-read_csv(file="breast_cancer_cells.csv")
## make some new columns that store the log ratios
breast_cancer<-breast_cancer %>% mutate(log_MCF7=log2((MCF7_1+MCF7_2)/(MCF10A_1+MCF10A_2)),log_MDA231=log2((MDA231_1+MDA231_2)/(MCF10A_1+MCF10A_2)),log_MDA468=log2((MDA468_1+MDA468_2)/(MCF10A_1+MCF10A_2)),log_SKBR3=log2((SKBR3_1+SKBR3_2)/(MCF10A_1+MCF10A_2)))%>%arrange(-log_MCF7)
## make a matrix of just the data
BC_matrix1<-breast_cancer %>% select(MCF10A_1:SKBR3_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(BC_matrix1,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
breast_cancer<-breast_cancer %>% mutate(neglog_MCF=-log10(pvalue_MCF7_vs_MCF10A))
## Use ggplot to plot the log ratio at 24 hours against the -log p-value at 24 hours
volcano_plot<-breast_cancer %>% ggplot(aes(x=log_MCF7,y=neglog_MCF,description=Gene_Symbol))+geom_point(alpha=0.7,color="blue")
volcano_plot

## BETTER VOLCANO PLOT
## Define the siginificant ones so they can be colored
breast_cancer<-breast_cancer %>% mutate(significance=ifelse((log_MCF7>2& neglog_MCF>2.99),"UP",ifelse((log_MCF7<c(-2)& neglog_MCF>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<-breast_cancer%>% ggplot(aes(x=log_MCF7,y=neglog_MCF,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 MCF7 compared to control",y="-log(p-value)")
optional_volcano_plot

## use ggplotly to see hover over the points to see the gene names
optional_volcano_plot<-breast_cancer%>% ggplot(aes(x=log_MCF7,y=neglog_MCF,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 MCF7 compared to control",y="-log(p-value)")
optional_volcano_plot

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
BC_Down<-breast_cancer %>% filter(Gene_Symbol=="CTSZ" |Gene_Symbol=="APOA1" | Gene_Symbol=="HLA-A" |Gene_Symbol=="ADCK3") %>% select(Gene_Symbol,MCF10A_1:SKBR3_2) %>% melt()
## make barplots facetted by Gene Symbol
BC_plot_down<-BC_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")
BC_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)
BC_Up<-breast_cancer %>% filter(Gene_Symbol=="C17orf28" | Gene_Symbol=="VAV2" | Gene_Symbol=="EPPK1" ) %>%
select(Gene_Symbol,MCF10A_1:SKBR3_2) %>%
melt()
BC_plot_up<-BC_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")
BC_plot_up
