This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.
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 log values the data
cancer_mat1<-cancer_data %>% select(log_MCF7:log_SKBR3) %>% as.matrix() %>% round(.,2)
head(cancer_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
## making 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_MDA468=-log10(pvalue_MDA468_vs_MCF10A))
## Use ggplot to plot the log ratio against the -log p-value
volcano_plot<-cancer_data %>% ggplot(aes(x=log_MDA468,y=neglog_MDA468,description=Gene_Symbol))+
geom_point(alpha=0.7,color="royalblue")
volcano_plot
## BETTER VOLCANO PLOT
## Define the significant ones (by using ifelse and setting # parameters) so they can be colored
cancer_data<-cancer_data %>% mutate(significance=ifelse((log_MDA468>2 & neglog_MDA468>2.99),"UP", ifelse((log_MDA468<c(-2) & neglog_MDA468>2.99),"DOWN","NOT SIG")))
## Some standard colors
plain_cols3<-c("red","gray","blue")
## volcano plot as before with some added things
better_volcano_plot<-cancer_data %>% ggplot(aes(x=log_MDA468,y=neglog_MDA468,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 Breast Cancer Cells MDA468 Compared to MCF10A",y="-log(p-value)")
better_volcano_plot
## use ggplotly to see hover over the points to see the gene names. Record these for the next step
ggplotly(better_volcano_plot)
## Significant up regulated are: ___, ___ and _____
## Significant down regulated are: _____. _____ and ____
# Make a pivot longer table of the data for Control_2h_1:Virus_24h_2
cancer_long<-pivot_longer(cancer_data, cols = c(MCF10A_1:SKBR3_2), names_to = 'variable')%>% select(-c(pvalue_MDA468_vs_MCF10A:significance))%>%select(-Description, Peptides)
head(cancer_long)
## # A tibble: 6 × 6
## Gene_Symbol Peptides pvalue_MCF7_vs_MCF10A pvalue_MDA231_vs_MC…¹ varia…² value
## <chr> <dbl> <dbl> <dbl> <chr> <dbl>
## 1 NES 7 0.542 0.0185 MCF10A… 9.54
## 2 NES 7 0.542 0.0185 MCF10A… 4.58
## 3 NES 7 0.542 0.0185 MCF7_1 5.07
## 4 NES 7 0.542 0.0185 MCF7_2 5.42
## 5 NES 7 0.542 0.0185 MDA231… 25.4
## 6 NES 7 0.542 0.0185 MDA231… 27.4
## # … with abbreviated variable names ¹​pvalue_MDA231_vs_MCF10A, ²​variable
## make sure that our timepoints will be in the proper order by adding a new column using the factor() function
#this should be excluded in other datasets where order is not needed
cancer_long$order <- as.character(cancer_long$variable)
cancer_long$order <- factor(cancer_long$order,levels=c('MCF10A_1','MCF10A_2','MCF7_1','MCF7_2','MDA231_1','MDA231_2','MDA468_1','MDA468_2','SKBR3_1','SKBR3_2'))
## based on the gene symbols from plotly, select a few proteins from the table. Select just the data and gene symbols and pivot longer
Examples_Down<-cancer_long %>% filter(Gene_Symbol=="PLAU" | Gene_Symbol=="PTPRE" | Gene_Symbol=="ADCK3")
head(Examples_Down)
## # A tibble: 6 × 7
## Gene_Symbol Peptides pvalue_MCF7_vs_MCF10A pvalue_MDA231…¹ varia…² value order
## <chr> <dbl> <dbl> <dbl> <chr> <dbl> <fct>
## 1 PTPRE 1 0.525 0.0470 MCF10A… 11.4 MCF1…
## 2 PTPRE 1 0.525 0.0470 MCF10A… 11.1 MCF1…
## 3 PTPRE 1 0.525 0.0470 MCF7_1 10.3 MCF7…
## 4 PTPRE 1 0.525 0.0470 MCF7_2 11.3 MCF7…
## 5 PTPRE 1 0.525 0.0470 MDA231… 23.9 MDA2…
## 6 PTPRE 1 0.525 0.0470 MDA231… 19.3 MDA2…
## # … with abbreviated variable names ¹​pvalue_MDA231_vs_MCF10A, ²​variable
## make barplots facetted by Gene Symbol (when working with other data sets - 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<-cancer_long %>% filter(Gene_Symbol=="PADI2" | Gene_Symbol=="CES1" | Gene_Symbol=="S100P")
head(Examples_Up)
## # A tibble: 6 × 7
## Gene_Symbol Peptides pvalue_MCF7_vs_MCF10A pvalue_MDA231…¹ varia…² value order
## <chr> <dbl> <dbl> <dbl> <chr> <dbl> <fct>
## 1 CES1 6 0.724 0.256 MCF10A… 1.97 MCF1…
## 2 CES1 6 0.724 0.256 MCF10A… 1.13 MCF1…
## 3 CES1 6 0.724 0.256 MCF7_1 1.32 MCF7…
## 4 CES1 6 0.724 0.256 MCF7_2 2.29 MCF7…
## 5 CES1 6 0.724 0.256 MDA231… 1 MDA2…
## 6 CES1 6 0.724 0.256 MDA231… 0.66 MDA2…
## # … with abbreviated variable names ¹​pvalue_MDA231_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
Downregulated <- cancer_data %>% filter(Gene_Symbol=='PLAU'| Gene_Symbol=="PTPRE" | Gene_Symbol=="ADCK3") %>% select(Gene_Symbol, Description, Peptides)
Upregulated <- cancer_data %>% filter(Gene_Symbol=="PADI2" | Gene_Symbol=="CES1" | Gene_Symbol=="S100P") %>% select(Gene_Symbol, Description, Peptides)