####Run through this example and try to understand what is going on with the data
####So, lets 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
B1 <- read_csv(file="breast_cancer_cells.csv")
#and then view it
#make a matrix of just raw the data
B1_mat<-B1 %>% select(MCF10A_1:SKBR3_2) %>% as.matrix() %>% round(.,2)
# what does that look like?
## make a heatmap from the data
pheatmap(B1_mat, color=pats_cols,cellwidth=30,cellheight=.03,cluster_cols=FALSE,cluster_rows=TRUE,legend=TRUE,fontsize = 7,scale="column")
##INTERPRETATION##
## What can you see in this figure? are the repeated measures/reps similar or different? What does this say about the precision and accuracy of them?
##How does the control compare to the variables? Is this what you might expect? Why? What would you look for in the literature to support this idea?
#looks like SKBR3 line is different than the other cells lines. We will take a closer look at that in the next section, once we've done some further data manipulations
## first, make new columns that combine the two reps for each variable by averaging them
B1_2<-B1 %>% mutate(
MCF10A= ((MCF10A_1 + MCF10A_2)/2),
MCF7= ((MCF7_1 + MCF7_2)/2),
MDA231= ((MDA231_1 + MDA231_2)/2),
MDA468= ((MDA468_1 + MDA468_2)/2),
SKBR3= ((SKBR3_1 + SKBR3_2)/2))
#did it create your new columns?
## then make some new columns that store the log ratios of the variable means you just created, as compared to the control
B1_2<-B1_2 %>% mutate(
log_MCF7=log2(MCF7/MCF10A),
log_MDA231=log2(MDA231/MCF10A),
log_MDA468=log2(MDA468/MCF10A),
log_SKBR3=log2(SKBR3/MCF10A))
#did it create your new columns?
## ALTERNATIVE CHOICE: make a matrix of just log values the data and a heat map of that. How do the two heat maps compare? This is not possible if your values contain 0's
B1_2log<-B1_2 %>% select(log_MCF7:log_SKBR3) %>% as.matrix() %>% round(.,2)
pheatmap(B1_2log, color=pats_cols,cellwidth=30,cellheight=.03,cluster_cols=FALSE,cluster_rows=TRUE,legend=TRUE,fontsize = 7,scale="column")
##BASIC VOLCANO PLOT
## Add a column that stores the negative log of the pvalue of interest (in this case, MDA231)
B1_3 <-B1_2 %>% mutate(neglog_MDA231=-log10(pvalue_MDA231_vs_MCF10A))
## Use ggplot to plot the log ratio of MDA231 against the -log p-value MDA231
volcano_plot<-B1_3 %>% ggplot(aes(x=log_MDA231,y=neglog_MDA231,description=Gene_Symbol))+
geom_point(alpha=0.7,color="blue")
#to view it, type:
## BETTER VOLCANO PLOT
## Define the significant ones (by using ifelse and setting # parameters) so they can be colored
B1_3 <- B1_3 %>% mutate(significance=ifelse((log_MDA231>1 & neglog_MDA231>4.1),"UP", ifelse((log_MDA231<c(-1) & neglog_MDA231>3.79),"DOWN","NOT SIG")))
## Some standard colors
plain_cols3<-c("red","gray","blue")
## volcano plot as before with some added things
better_volcano_plot<-B1_3 %>% ggplot(aes(x=log_MDA231,y=neglog_MDA231,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 cell lines from MDA231 vs MCF10A",y="-log(p-value)")
#to view it, type
better_volcano_plot
#check viewer and / or plots to see it
## use ggplotly to see hover over the points to see the gene names. Record these for the next step
ggplotly(better_volcano_plot)
##INTERPRETATION##
## Significant up regulated are: ATIC, EIF2B1 and PGK1
## Significant down regulated are: MIPEP, ADCK3 and ATAD1
#Why? How?
# Make a pivot longer table of the B1_3 data for MCF10A_1:SKBR3_2
Breast_long <- pivot_longer(B1_3, cols = c(MCF10A_1:SKBR3_2), names_to = 'variable')%>% select(-c(pvalue_MCF7_vs_MCF10A:significance))%>%select(-Peptides)
head(Breast_long)
## # A tibble: 6 × 4
## Gene_Symbol Description variable value
## <chr> <chr> <chr> <dbl>
## 1 NES Nestin OS=Homo sapiens GN=NES PE=1 SV=2 MCF10A_1 9.54
## 2 NES Nestin OS=Homo sapiens GN=NES PE=1 SV=2 MCF10A_2 4.58
## 3 NES Nestin OS=Homo sapiens GN=NES PE=1 SV=2 MCF7_1 5.07
## 4 NES Nestin OS=Homo sapiens GN=NES PE=1 SV=2 MCF7_2 5.42
## 5 NES Nestin OS=Homo sapiens GN=NES PE=1 SV=2 MDA231_1 25.4
## 6 NES Nestin OS=Homo sapiens GN=NES PE=1 SV=2 MDA231_2 27.4
## 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<-Breast_long %>% filter(Gene_Symbol=="MIPEP" | Gene_Symbol=="ADCK3" | Gene_Symbol=="ATAD1")
## 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=factor(variable,levels=c('MCF10A_1','MCF10A_2','MCF7_1','MCF7_2','MDA231_1','MDA231_2','MDA468_1','MDA468_2','SKBR3_1','SKBR3_2')),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
#check viewer and / or plots to see it
##INTERPRETATION## ## What can you see in this figure? are the repeated measures/reps similar or different? What does this say about the precision and accuracy of them? ##How does the control compare to the variables? Is this what you might expect? Why? What would you look for in the literature to support this idea?
## Same process for the upregulated ones
Examples_Up <- Breast_long %>% filter(Gene_Symbol=="ATIC" | Gene_Symbol=="EIF2B1" | Gene_Symbol=="PGK1")
Example_plot_up<-Examples_Up %>%
ggplot(aes(x=factor(variable,levels=c('MCF10A_1','MCF10A_2','MCF7_1','MCF7_2','MDA231_1','MDA231_2','MDA468_1','MDA468_2','SKBR3_1','SKBR3_2')),y=value))+
geom_bar(stat="identity",fill="blue")+
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
#check viewer and / or plots to see it
##INTERPRETATION## ## What can you see in this figure? are the repeated measures/reps similar or different? What does this say about the precision and accuracy of them? ##How does the control compare to the variables? Is this what you might expect? Why? What would you look for in the literature to support this idea?
#interpretation HINT:insert a chunk and create two seprate lines of code that filter for your specific upregulated genes/proteins of interest and selects for only their gene symbols and descriptions. Do this for the downregulated as well. This will generate two list of the descriptors for each gene of interest, helping you understand your figures. Be sure to view it, not just ask for the head of the table generated.
Upregulated <-Examples_Up %>% select(Gene_Symbol:Description) %>% as.matrix()
Downregulated <- Examples_Down %>% select(Gene_Symbol:Description) %>% as.matrix()
##now you can knit this and publish to save and share your code. Use this to work with either the brain or breast cells and the Part_C_template to complete your lab 6 ELN. ##Annotate when you have trouble and reference which line of code you need help on ## good luck and have fun!