###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
breast_cancer_data <- read_csv(file="breast_cancer_cells.csv")
## make some new columns that store the log ratios
breast_cancer_data <- breast_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))) %>% arrange(-log_MCF7)
## make a matrix of just the data
Breast_Cancer_matrix <-breast_cancer_data %>% select(MCF10A_1:SKBR3_2) %>% as.matrix() %>% round(.,2)
head(Breast_Cancer_matrix)
## MCF10A_1 MCF10A_2 MCF7_1 MCF7_2 MDA231_1 MDA231_2 MDA468_1 MDA468_2
## [1,] 0 0 23.16 18.89 3.85 4.11 9.97 17.04
## [2,] 0 0 13.77 12.28 2.62 4.54 13.78 10.42
## [3,] 0 0 12.06 13.46 2.79 3.14 11.24 11.59
## [4,] 0 0 13.41 11.71 5.87 4.61 9.34 10.50
## [5,] 0 0 10.91 13.05 8.61 5.15 17.83 15.20
## [6,] 0 0 10.64 11.44 0.80 0.00 30.50 29.84
## SKBR3_1 SKBR3_2
## [1,] 9.25 13.73
## [2,] 19.67 22.91
## [3,] 21.97 23.75
## [4,] 18.95 25.61
## [5,] 12.39 16.85
## [6,] 9.57 7.21
## make a heatmap from the data
pheatmap(Breast_Cancer_matrix, color=pats_cols,cellwidth=30,cellheight=.06,cluster_cols=FALSE,cluster_rows=FALSE,legend=TRUE,fontsize = 7,scale="row")
##BASIC VOLCANO PLOT
## Add a column that stores the negative log of the pvalue of interest
breast_cancer_data<-breast_cancer_data %>% mutate(neglog_MCF=-log10(pvalue_MCF7_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<-breast_cancer_data %>% ggplot(aes(x=log_MCF7,y=neglog_MCF,description=Gene_Symbol))+
geom_point(alpha=0.7,color="royalblue")
volcano_plot
## BETTER VOLCANO PLOT
## Define the significant ones so they can be colored
breast_cancer_data<-breast_cancer_data %>% mutate(significance=ifelse((log_MCF7>2 & neglog_MCF>2.99),"UP", ifelse((log_MCF7<c(-2) & neglog_MCF>2.99),"DOWN","NOT SIG")))
## Some standard colors
plain_cols3<-c("red","gray","blue")
## volcano plot as before with some added graph features
better_volcano_plot<-breast_cancer_data %>% 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 of MCF7 compared to control",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
Breast_Cancer_long<-pivot_longer(breast_cancer_data, cols = c(MCF10A_1:SKBR3_2), names_to = 'variable')%>% select(-c(pvalue_MCF7_vs_MCF10A:significance))
head(Breast_Cancer_long)
## # A tibble: 6 × 5
## Gene_Symbol Description Pepti…¹ varia…² value
## <chr> <chr> <dbl> <chr> <dbl>
## 1 CDC37L1 Hsp90 co-chaperone Cdc37-like 1 OS=Homo sa… 1 MCF10A… 0.001
## 2 CDC37L1 Hsp90 co-chaperone Cdc37-like 1 OS=Homo sa… 1 MCF10A… 0.001
## 3 CDC37L1 Hsp90 co-chaperone Cdc37-like 1 OS=Homo sa… 1 MCF7_1 23.2
## 4 CDC37L1 Hsp90 co-chaperone Cdc37-like 1 OS=Homo sa… 1 MCF7_2 18.9
## 5 CDC37L1 Hsp90 co-chaperone Cdc37-like 1 OS=Homo sa… 1 MDA231… 3.85
## 6 CDC37L1 Hsp90 co-chaperone Cdc37-like 1 OS=Homo sa… 1 MDA231… 4.11
## # … with abbreviated variable names ¹Peptides, ²variable
## 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<-Breast_Cancer_long %>% filter(Gene_Symbol=="METTL7A" | Gene_Symbol=="FMNL1" | Gene_Symbol=="EXOG")
## 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="red")+
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
Examples_Up<-Breast_Cancer_long %>% filter(Gene_Symbol=="AGR3" | Gene_Symbol=="SYT7"|Gene_Symbol=="FBP2")
head(Examples_Up)
## # A tibble: 6 × 5
## Gene_Symbol Description Pepti…¹ varia…² value
## <chr> <chr> <dbl> <chr> <dbl>
## 1 FBP2 Fructose-1,6-bisphosphatase isozyme 2 OS=Ho… 2 MCF10A… 1.13
## 2 FBP2 Fructose-1,6-bisphosphatase isozyme 2 OS=Ho… 2 MCF10A… 0.76
## 3 FBP2 Fructose-1,6-bisphosphatase isozyme 2 OS=Ho… 2 MCF7_1 43.9
## 4 FBP2 Fructose-1,6-bisphosphatase isozyme 2 OS=Ho… 2 MCF7_2 41.4
## 5 FBP2 Fructose-1,6-bisphosphatase isozyme 2 OS=Ho… 2 MDA231… 2.24
## 6 FBP2 Fructose-1,6-bisphosphatase isozyme 2 OS=Ho… 2 MDA231… 1.7
## # … with abbreviated variable names ¹Peptides, ²variable
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
#your original table contains descriptions of each gene. Write some code to create yourself a table to filter for your gene symbols of interest and select for the gene symbol, description, and peptides. Do this for both the significantly upregulated and downregulated points of interest.
#Downregulated
Breast_Cancer_table_DR <- breast_cancer_data %>% filter(Gene_Symbol=="METTL7A" | Gene_Symbol=="FMNL1" | Gene_Symbol=="EXOG") %>% select(Gene_Symbol,Description,Peptides)
head(Breast_Cancer_table_DR)
## # A tibble: 3 × 3
## Gene_Symbol Description Pepti…¹
## <chr> <chr> <dbl>
## 1 EXOG Nuclease EXOG, mitochondrial OS=Homo sapiens GN=EXOG PE=1… 3
## 2 METTL7A Methyltransferase-like protein 7A OS=Homo sapiens GN=METT… 3
## 3 FMNL1 Isoform 2 of Formin-like protein 1 OS=Homo sapiens GN=FMN… 1
## # … with abbreviated variable name ¹Peptides
#Upregulated
Breast_Cancer_table_UR <- breast_cancer_data %>% filter(Gene_Symbol=="AGR3" | Gene_Symbol=="SYT7"|Gene_Symbol=="FBP2") %>% select(Gene_Symbol,Description,Peptides)
head(Breast_Cancer_table_UR)
## # A tibble: 3 × 3
## Gene_Symbol Description Pepti…¹
## <chr> <chr> <dbl>
## 1 FBP2 Fructose-1,6-bisphosphatase isozyme 2 OS=Homo sapiens GN=… 2
## 2 AGR3 Anterior gradient protein 3 homolog OS=Homo sapiens GN=AG… 5
## 3 SYT7 Synaptotagmin-7 OS=Homo sapiens GN=SYT7 PE=1 SV=3 1
## # … with abbreviated variable name ¹Peptides