###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_cells<-read_csv(file="breast_cancer_cells.csv")
## make some new columns that store the log ratios
breast_cancer_cells_logs<-breast_cancer_cells %>% 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)))
## make a matrix of just the data
bc_c_matrix<-breast_cancer_cells_logs %>% select(log_MCF7:log_SKBR3) %>% as.matrix() %>% round(.,2)
## make a heatmap from the data
pheatmap(bc_c_matrix,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
neg_log_SKBR3_pv<-breast_cancer_cells_logs %>% mutate(neg_log_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
SKRB_vs_neglog_volcano_plot<-neg_log_SKBR3_pv%>%
ggplot(aes(x=log_SKBR3,y=neg_log_SKBR3,description=Gene_Symbol))+
geom_point(alpha=0.7,color="royalblue")
SKRB_vs_neglog_volcano_plot
## BETTER VOLCANO PLOT
## Define the significant ones so they can be colored
neg_log_SKBR3_pv_significant<-neg_log_SKBR3_pv %>% mutate(significance=ifelse((log_SKBR3>2 & neg_log_SKBR3>2.99),"UP", ifelse((log_SKBR3<c(-2) & neg_log_SKBR3>2.99),"DOWN","NOT SIG")))
## Some standard colors
plain_cols3<-c("red","gray","blue")
## volcano plot as before with some added graph features
neglog_SKBR3_better_volcano_plot<-neg_log_SKBR3_pv_significant %>% ggplot(aes(x=log_SKBR3,y=neg_log_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 cells in cancer patient(log_SKBR3)compared to control(neg_log_SKBR3)",y="-log(p-value)")
neglog_SKBR3_better_volcano_plot
## use ggplotly to see hover over the points to see the gene names
ggplotly(neglog_SKBR3_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_cells, cols = c(MCF10A_1:SKBR3_2), names_to = 'variable') %>%
select(-c(pvalue_MCF7_vs_MCF10A:pvalue_SKBR3_vs_MCF10A)) %>%
mutate(order = as.character(variable)) %>%
mutate(order = factor(order, levels = c('MCF10A_1', 'MCF10A_2', 'MCF7_1', 'MCF7_2', 'MDA231_1', 'MDA231_2', 'MDA468_1', 'MDA468_2', 'SKBR3_1', 'SKBR3_2')))
breast_cancer_long
## # A tibble: 51,440 × 6
## Gene_Symbol Description Pepti…¹ varia…² value order
## <chr> <chr> <dbl> <chr> <dbl> <fct>
## 1 NES Nestin OS=Homo sapiens GN=NES PE=1 S… 7 MCF10A… 9.54 MCF1…
## 2 NES Nestin OS=Homo sapiens GN=NES PE=1 S… 7 MCF10A… 4.58 MCF1…
## 3 NES Nestin OS=Homo sapiens GN=NES PE=1 S… 7 MCF7_1 5.07 MCF7…
## 4 NES Nestin OS=Homo sapiens GN=NES PE=1 S… 7 MCF7_2 5.42 MCF7…
## 5 NES Nestin OS=Homo sapiens GN=NES PE=1 S… 7 MDA231… 25.4 MDA2…
## 6 NES Nestin OS=Homo sapiens GN=NES PE=1 S… 7 MDA231… 27.4 MDA2…
## 7 NES Nestin OS=Homo sapiens GN=NES PE=1 S… 7 MDA468… 4.56 MDA4…
## 8 NES Nestin OS=Homo sapiens GN=NES PE=1 S… 7 MDA468… 3.88 MDA4…
## 9 NES Nestin OS=Homo sapiens GN=NES PE=1 S… 7 SKBR3_1 8.46 SKBR…
## 10 NES Nestin OS=Homo sapiens GN=NES PE=1 S… 7 SKBR3_2 5.64 SKBR…
## # … with 51,430 more rows, and 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
proteins_down<-breast_cancer_long %>% filter(Gene_Symbol=="MYO1B" | Gene_Symbol=="HLA-A" | Gene_Symbol=="APOA1" | Gene_Symbol=="HMGN5")
head(proteins_down)
## # A tibble: 6 × 6
## Gene_Symbol Description Pepti…¹ varia…² value order
## <chr> <chr> <dbl> <chr> <dbl> <fct>
## 1 HLA-A HLA class I histocompatibility antige… 3 MCF10A… 5.42 MCF1…
## 2 HLA-A HLA class I histocompatibility antige… 3 MCF10A… 6.62 MCF1…
## 3 HLA-A HLA class I histocompatibility antige… 3 MCF7_1 2.22 MCF7…
## 4 HLA-A HLA class I histocompatibility antige… 3 MCF7_2 2.69 MCF7…
## 5 HLA-A HLA class I histocompatibility antige… 3 MDA231… 4.56 MDA2…
## 6 HLA-A HLA class I histocompatibility antige… 3 MDA231… 4.23 MDA2…
## # … with abbreviated variable names ¹Peptides, ²variable
## make barplots facetted by Gene Symbol (if copying COVID example - change x=order to x = variable)
proteins_plot_down<-proteins_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")
proteins_plot_down
## Same process for the upregulated ones
proteins_up<-breast_cancer_long %>% filter(Gene_Symbol=="KRT23" | Gene_Symbol=="TDP2" | Gene_Symbol=="FNBP1L" | Gene_Symbol=="DENND4C" | Gene_Symbol=="GCLC")
head(proteins_up)
## # A tibble: 6 × 6
## Gene_Symbol Description Pepti…¹ varia…² value order
## <chr> <chr> <dbl> <chr> <dbl> <fct>
## 1 TDP2 Isoform 2 of Tyrosyl-DNA phosphodiest… 3 MCF10A… 2.36 MCF1…
## 2 TDP2 Isoform 2 of Tyrosyl-DNA phosphodiest… 3 MCF10A… 1.72 MCF1…
## 3 TDP2 Isoform 2 of Tyrosyl-DNA phosphodiest… 3 MCF7_1 5.89 MCF7…
## 4 TDP2 Isoform 2 of Tyrosyl-DNA phosphodiest… 3 MCF7_2 4.71 MCF7…
## 5 TDP2 Isoform 2 of Tyrosyl-DNA phosphodiest… 3 MDA231… 5.94 MDA2…
## 6 TDP2 Isoform 2 of Tyrosyl-DNA phosphodiest… 3 MDA231… 7.38 MDA2…
## # … with abbreviated variable names ¹Peptides, ²variable
proteins_plot_up<-proteins_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")
proteins_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<-neg_log_SKBR3_pv_significant %>% filter(Gene_Symbol=="MYO1B" | Gene_Symbol=="HLA-A" | Gene_Symbol=="APOA1" | Gene_Symbol=="HMGN5") %>% select(Gene_Symbol,Description,Peptides)
downregulated
## # A tibble: 7 × 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 HMGN5 High mobility group nucleosome-binding domain-containing … 4
## 5 MYO1B Isoform 2 of Myosin-Ib OS=Homo sapiens GN=MYO1B 22
## 6 HLA-A HLA class I histocompatibility antigen, A-1 alpha chain O… 1
## 7 APOA1 Apolipoprotein A-I OS=Homo sapiens GN=APOA1 PE=1 SV=1 2
## # … with abbreviated variable name ¹Peptides
#Upregulated
upregulated<-neg_log_SKBR3_pv_significant %>% filter(Gene_Symbol=="KRT23" | Gene_Symbol=="TDP2" | Gene_Symbol=="FNBP1L" | Gene_Symbol=="DENND4C" | Gene_Symbol=="GCLC") %>% select(Gene_Symbol,Description,Peptides)
upregulated
## # A tibble: 5 × 3
## Gene_Symbol Description Pepti…¹
## <chr> <chr> <dbl>
## 1 TDP2 Isoform 2 of Tyrosyl-DNA phosphodiesterase 2 OS=Homo sapi… 3
## 2 DENND4C Isoform 2 of DENN domain-containing protein 4C OS=Homo sa… 1
## 3 KRT23 Keratin, type I cytoskeletal 23 OS=Homo sapiens GN=KRT23 … 3
## 4 FNBP1L Isoform 2 of Formin-binding protein 1-like OS=Homo sapien… 6
## 5 GCLC Glutamate--cysteine ligase catalytic subunit OS=Homo sapi… 6
## # … with abbreviated variable name ¹Peptides