###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
C24_data<-read_csv(file="breast_cancer_cells.csv")
## make some new columns that store the log ratios
C24_data<-C24_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(C24_data)
## make a matrix of just the data
C24_mat1<-C24_data %>% select(log_MCF7:log_SKBR3) %>% as.matrix() %>% round(.,2)
head(C24_mat1)
## log_MCF7 log_MDA231 log_MDA468 log_SKBR3
## [1,] -0.43 1.90 -0.74 0
## [2,] -0.96 -0.35 -0.71 0
## [3,] 0.27 0.29 -0.04 0
## [4,] 0.88 0.78 -0.05 0
## [5,] 0.79 1.19 0.92 0
## [6,] -0.79 -0.90 -1.28 0
## make a heatmap from the data
pheatmap(C24_mat1, color=pats_cols,cellwidth=30,cellheight=.03,cluster_cols=FALSE,cluster_rows=FALSE,legend=TRUE,fontsize = 7,scale="column")
#looks like 24hrs is different than the other cells lines. Let's take a closer look at that
##BASIC VOLCANO PLOT
## Add a column that stores the negative log of the pvalue of interest
C24_data<-C24_data %>% mutate(neglog_MCF7=-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<-C24_data %>% ggplot(aes(x=log_MCF7,y=neglog_MCF7,description=Gene_Symbol))+
geom_point(alpha=0.7,color="royalblue")
volcano_plot
## BETTER VOLCANO PLOT
## Define the significant ones so they can be colored
C24_data<-C24_data %>% mutate(significance=ifelse((log_MCF7>2 & neglog_MCF7>2.99),"UP", ifelse((log_MCF7<c(-2) & neglog_MCF7>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<-C24_data %>% ggplot(aes(x=log_MCF7,y=neglog_MCF7,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 MCF10A",y="-log(MCF7)")
better_volcano_plot
## use ggplotly to see hover over the points to see the gene names
ggplotly(better_volcano_plot)
## chose 3 most significant
## 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
C24_long<-pivot_longer(C24_data, cols = c(MCF10A_1:SKBR3_2), names_to = 'variable')%>% select(-c(pvalue_MCF7_vs_MCF10A:significance))%>%select(-Description & -Peptides)
head(C24_long)
## # A tibble: 6 × 3
## Gene_Symbol variable value
## <chr> <chr> <dbl>
## 1 NES MCF10A_1 9.54
## 2 NES MCF10A_2 4.58
## 3 NES MCF7_1 5.07
## 4 NES MCF7_2 5.42
## 5 NES MDA231_1 25.4
## 6 NES MDA231_2 27.4
### need a pivot longer table (C19 long or breastcancer long) only want to combine the original raw data columns not including p-value!
### that puts them all in one column (variable) and the rest is rid so everything after + accession column is getting rid
## 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<-C24_long %>% filter(Gene_Symbol=="CTSZ" | Gene_Symbol=="APOA1" | Gene_Symbol=="HLA-A")
head(Examples_Down)
## # A tibble: 6 × 3
## Gene_Symbol variable value
## <chr> <chr> <dbl>
## 1 HLA-A MCF10A_1 5.42
## 2 HLA-A MCF10A_2 6.62
## 3 HLA-A MCF7_1 2.22
## 4 HLA-A MCF7_2 2.69
## 5 HLA-A MDA231_1 4.56
## 6 HLA-A 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="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<-C24_long %>% filter(Gene_Symbol=="C17orf28" | Gene_Symbol=="EPPK1" | Gene_Symbol=="VAV2")
head(Examples_Up)
## # A tibble: 6 × 3
## Gene_Symbol variable value
## <chr> <chr> <dbl>
## 1 EPPK1 MCF10A_1 2.76
## 2 EPPK1 MCF10A_2 2.89
## 3 EPPK1 MCF7_1 22.4
## 4 EPPK1 MCF7_2 22.3
## 5 EPPK1 MDA231_1 1.9
## 6 EPPK1 MDA231_2 1.76
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
Downregulated<-C24_data %>% filter(Gene_Symbol=="CTSZ" | Gene_Symbol=="APOA1" | Gene_Symbol=="HLA-A") %>% select(Gene_Symbol,Description,Peptides)
#Upregulated
Upregulated<-C24_data %>% filter(Gene_Symbol=="C17orf28" | Gene_Symbol=="EPPK1" | Gene_Symbol=="VAV2") %>% select(Gene_Symbol,Description,Peptides)
head(Upregulated)
## # A tibble: 4 × 3
## Gene_Symbol Description Pepti…¹
## <chr> <chr> <dbl>
## 1 EPPK1 Uncharacterized protein OS=Homo sapiens GN=EPPK1 PE=4 SV=1 4
## 2 EPPK1 Epiplakin OS=Homo sapiens GN=EPPK1 PE=1 SV=2 71
## 3 VAV2 Isoform 2 of Guanine nucleotide exchange factor VAV2 OS=H… 4
## 4 C17orf28 Isoform 2 of UPF0663 transmembrane protein C17orf28 OS=Ho… 3
## # … with abbreviated variable name ¹Peptides
head(Downregulated)
## # A tibble: 6 × 3
## Gene_Symbol Description Pepti…¹
## <chr> <chr> <dbl>
## 1 HLA-A HLA class I histocompatibility antigen, A-23 alpha chain … 3
## 2 HLA-A HLA class I histocompatibility antigen, A-30 alpha chain … 1
## 3 HLA-A HLA class I histocompatibility antigen, A-2 alpha chain O… 21
## 4 CTSZ Cathepsin Z OS=Homo sapiens GN=CTSZ PE=1 SV=1 8
## 5 HLA-A HLA class I histocompatibility antigen, A-1 alpha chain O… 1
## 6 APOA1 Apolipoprotein A-I OS=Homo sapiens GN=APOA1 PE=1 SV=1 2
## # … with abbreviated variable name ¹Peptides