###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")
## name the data - import the file
## 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)))
## from the breast cancer data make new rows for log ratios - controls are added together on the bottom of each fraction and the 2 experimentals added together on top of each fraction
view(breast_cancer_data)
## make a matrix of just the data
bcancer_mat1<-breast_cancer_data %>% select(log_MCF7:log_SKBR3) %>% as.matrix() %>% round(.,2)
## name the new matrix - use the breast cancer data - select the new log columns
head(bcancer_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
## display the matrix
## make a heatmap from the data
pheatmap(bcancer_mat1, color=pats_cols,cellwidth=30,cellheight=.03,cluster_cols=FALSE,cluster_rows=FALSE,legend=TRUE,fontsize = 7,scale="column")
## looks like SKBR3 is different than the other genes so I will take a closer look at that
##BASIC VOLCANO PLOT
## Add a column that stores the negative log of the pvalue of interest (in this case gene SKBR3)
breast_cancer_data<-breast_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<-breast_cancer_data %>% ggplot(aes(x=log_SKBR3,y=neglog_SKBR3,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_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("red","gray","blue")
## volcano plot as before with some added graph features
better_volcano_plot<-breast_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 gene SKBR3 to control",y="-log(p-value compared to control)")
better_volcano_plot
## use ggplotly to see hover over the points to see the gene names
ggplotly(better_volcano_plot)
## Significant up regulated are: ___, ___ and _____
## Significant down regulated are: _____. _____ and ____
## 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
bcancer_long<-pivot_longer(breast_cancer_data, cols = c(MCF10A_1:SKBR3_2), names_to = 'variable')%>% select(-c(pvalue_SKBR3_vs_MCF10A:significance))
head(bcancer_long)
## # A tibble: 6 × 8
## Gene_Symbol Description Pepti…¹ pvalu…² pvalu…³ pvalu…⁴ varia…⁵ value
## <chr> <chr> <dbl> <dbl> <dbl> <dbl> <chr> <dbl>
## 1 NES Nestin OS=Homo sapi… 7 0.542 0.0185 0.374 MCF10A… 9.54
## 2 NES Nestin OS=Homo sapi… 7 0.542 0.0185 0.374 MCF10A… 4.58
## 3 NES Nestin OS=Homo sapi… 7 0.542 0.0185 0.374 MCF7_1 5.07
## 4 NES Nestin OS=Homo sapi… 7 0.542 0.0185 0.374 MCF7_2 5.42
## 5 NES Nestin OS=Homo sapi… 7 0.542 0.0185 0.374 MDA231… 25.4
## 6 NES Nestin OS=Homo sapi… 7 0.542 0.0185 0.374 MDA231… 27.4
## # … with abbreviated variable names ¹Peptides, ²pvalue_MCF7_vs_MCF10A,
## # ³pvalue_MDA231_vs_MCF10A, ⁴pvalue_MDA468_vs_MCF10A, ⁵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<-bcancer_long %>% filter(Gene_Symbol=="APOA1" | Gene_Symbol=="MYO1B" | Gene_Symbol=="HMGN5" | Gene_Symbol=="HLA-A")
head(Examples_Down)
## # A tibble: 6 × 8
## Gene_Symbol Description Pepti…¹ pvalu…² pvalu…³ pvalu…⁴ varia…⁵ value
## <chr> <chr> <dbl> <dbl> <dbl> <dbl> <chr> <dbl>
## 1 HLA-A HLA class I histoco… 3 0.0312 0.122 0.0131 MCF10A… 5.42
## 2 HLA-A HLA class I histoco… 3 0.0312 0.122 0.0131 MCF10A… 6.62
## 3 HLA-A HLA class I histoco… 3 0.0312 0.122 0.0131 MCF7_1 2.22
## 4 HLA-A HLA class I histoco… 3 0.0312 0.122 0.0131 MCF7_2 2.69
## 5 HLA-A HLA class I histoco… 3 0.0312 0.122 0.0131 MDA231… 4.56
## 6 HLA-A HLA class I histoco… 3 0.0312 0.122 0.0131 MDA231… 4.23
## # … with abbreviated variable names ¹Peptides, ²pvalue_MCF7_vs_MCF10A,
## # ³pvalue_MDA231_vs_MCF10A, ⁴pvalue_MDA468_vs_MCF10A, ⁵variable
## 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<-bcancer_long %>% filter(Gene_Symbol=="GCLC" |Gene_Symbol=="KRT23" | Gene_Symbol=="FNBP1L" | Gene_Symbol=="DENND4C" | Gene_Symbol=="TDP2")
head(Examples_Up)
## # A tibble: 6 × 8
## Gene_Symbol Description Pepti…¹ pvalu…² pvalu…³ pvalu…⁴ varia…⁵ value
## <chr> <chr> <dbl> <dbl> <dbl> <dbl> <chr> <dbl>
## 1 TDP2 Isoform 2 of Tyrosy… 3 0.0400 0.0281 0.100 MCF10A… 2.36
## 2 TDP2 Isoform 2 of Tyrosy… 3 0.0400 0.0281 0.100 MCF10A… 1.72
## 3 TDP2 Isoform 2 of Tyrosy… 3 0.0400 0.0281 0.100 MCF7_1 5.89
## 4 TDP2 Isoform 2 of Tyrosy… 3 0.0400 0.0281 0.100 MCF7_2 4.71
## 5 TDP2 Isoform 2 of Tyrosy… 3 0.0400 0.0281 0.100 MDA231… 5.94
## 6 TDP2 Isoform 2 of Tyrosy… 3 0.0400 0.0281 0.100 MDA231… 7.38
## # … with abbreviated variable names ¹Peptides, ²pvalue_MCF7_vs_MCF10A,
## # ³pvalue_MDA231_vs_MCF10A, ⁴pvalue_MDA468_vs_MCF10A, ⁵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.
##makes tables but messy and needs work
#Downregulated
##downregulated_genes <- c("APOA1", "HLA-A", "HMGN5", "MYO1B")
##downregulated_table <- breast_cancer_data %>%
## filter(Gene_Symbol %in% downregulated_genes) %>%
## select(Gene_Symbol, Description, Peptides)
##head(downregulated_table)
#Upregulated
##upregulated_genes <- c("GCLC", "KRT23", "FNBP1L", "DENND4C", "TDP2")
##upregulated_table <- breast_cancer_data %>%
## filter(Gene_Symbol %in% upregulated_genes) %>%
## select(Gene_Symbol, Description, Peptides)
##head(upregulated_table)