###First, let’s load RMarkdown
library(rmarkdown)
knitr::opts_chunk$set(echo = TRUE, message=FALSE,warning=FALSE,collapse = TRUE)
library(reshape2)
library(ggplot2)
library(dplyr)
library(plotly)
library(viridis)
library(data.table)
library(pheatmap)
library(tidyverse)
library(ggthemes)
library(clipr)
library(tidyr)
library(Rcpp)
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 the dataset
Cancer_data<-read_csv(file="breast_cancer_cells.csv")
## make some new columns that store the log ratios
Cancer_data<-Cancer_data %>% 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)))
view(Cancer_data)
## make a matrix of just the data
Cancer_mat1<-Cancer_data %>% select(log_MCF7:log_SKBR3) %>% as.matrix() %>% round(.,4)
head(Cancer_mat1)
## log_MCF7 log_MDA231 log_MDA468 log_SKBR3
## [1,] -0.4287 1.9042 -0.7424 -0.0020
## [2,] -0.9621 -0.3471 -0.7144 0.0000
## [3,] 0.2733 0.2874 -0.0403 0.0016
## [4,] 0.8785 0.7752 -0.0536 0.0009
## [5,] 0.7918 1.1894 0.9197 0.0034
## [6,] -0.7870 -0.8955 -1.2818 -0.0015
## make a heatmap from the data
pheatmap(Cancer_mat1, color=pats_cols,cellwidth=30,cellheight=.03,cluster_cols=FALSE,cluster_rows=FALSE,legend=TRUE,fontsize = 7,scale="column")
##BASIC VOLCANO PLOT
## Add a column that stores the negative log of the pvalue of interest
Cancer_data<-Cancer_data %>% mutate(neglog_SKBR3=-log10(pvalue_SKBR3_vs_MCF10A))
## Use ggplot to plot the log ratio a column (cell line or treatment) of interest against the -log p-value of that same column of interest
volcano_plot<-Cancer_data %>% ggplot(aes(x=log_SKBR3,y=neglog_SKBR3,description=Gene_Symbol))+
geom_point(alpha=0.7,color="pink")
volcano_plot
## BETTER VOLCANO PLOT
## Define the significant ones so they can be colored
Cancer_data<-Cancer_data %>% mutate(significance=ifelse((log_SKBR3>2 & neglog_SKBR3>2.99),"UP", ifelse((log_SKBR3<c(-2) & neglog_SKBR3>2.99),"DOWN","NOT SIG")))
## Some standard colors
plain_cols3<-c("green","purple","blue")
## volcano plot as before with some added graph features
better_volcano_plot<-Cancer_data %>% ggplot(aes(x=log_SKBR3,y=neglog_SKBR3,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 of SKBR3 compared to MCF10A ",y="-log(p-value)")
better_volcano_plot
## use ggplotly to see hover over the points to see the gene names
ggplotly(better_volcano_plot)
## EXAMPLES OF A COUPLE PROTEINS or GENES
# Make a pivot longer table of the data for initial columns. Exclude the p-values and log columns
Cancer_long<-pivot_longer(Cancer_data, cols = c(MCF10A_1:SKBR3_2), names_to = 'variable')%>% select(-c(pvalue_MCF7_vs_MCF10A:significance))%>%select(-Description)
head(Cancer_long)
## # A tibble: 6 × 4
## Gene_Symbol Peptides variable value
## <chr> <dbl> <chr> <dbl>
## 1 NES 7 MCF10A_1 9.54
## 2 NES 7 MCF10A_2 4.58
## 3 NES 7 MCF7_1 5.07
## 4 NES 7 MCF7_2 5.42
## 5 NES 7 MDA231_1 25.4
## 6 NES 7 MDA231_2 27.4
## based on the gene symbols from plotly, select a few proteins from the table. Select just the data and gene symbols from the pivot longer table you just made
Examples_Down<-Cancer_long %>% filter(Gene_Symbol=="APOA1" | Gene_Symbol=="MYO1B" | Gene_Symbol=="HLA-A"| Gene_Symbol=="HMGN5")
head(Examples_Down)
## # A tibble: 6 × 4
## Gene_Symbol Peptides variable value
## <chr> <dbl> <chr> <dbl>
## 1 HLA-A 3 MCF10A_1 5.42
## 2 HLA-A 3 MCF10A_2 6.62
## 3 HLA-A 3 MCF7_1 2.22
## 4 HLA-A 3 MCF7_2 2.69
## 5 HLA-A 3 MDA231_1 4.56
## 6 HLA-A 3 MDA231_2 4.23
## make barplots facetted by Gene Symbol (if copying COVID example - change x=order to x = variable)
Example_plot_down<-Examples_Down %>%
ggplot(aes(x=variable,y=value))+
geom_bar(stat="identity",fill="green")+
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="variable",y="relative intensity")
Example_plot_down
## Same process for the upregulated ones
Examples_up<-Cancer_long %>% filter(Gene_Symbol=="GCLC" | Gene_Symbol=="FNP1L" | Gene_Symbol=="DENND4C"| Gene_Symbol=="KRT23"| Gene_Symbol=="TDP2")
head(Examples_up)
## # A tibble: 6 × 4
## Gene_Symbol Peptides variable value
## <chr> <dbl> <chr> <dbl>
## 1 TDP2 3 MCF10A_1 2.36
## 2 TDP2 3 MCF10A_2 1.72
## 3 TDP2 3 MCF7_1 5.89
## 4 TDP2 3 MCF7_2 4.71
## 5 TDP2 3 MDA231_1 5.94
## 6 TDP2 3 MDA231_2 7.38
## make barplots facetted by Gene Symbol (if copying COVID example - change x=order to x = variable)
Example_plot_up<-Examples_up %>%
ggplot(aes(x=variable,y=value))+
geom_bar(stat="identity",fill="blue")+
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="variable",y="relative intensity")
Example_plot_up
```