####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 (cells treated with COVID)
C19_data<-read_csv(file="COVID_test.csv")
#and then view it
view(C19_data)
#make a matrix of just raw the data
C19_mat1<-C19_data %>% select(Control_2h_1:Virus_24h_2) %>% as.matrix() %>% round(.,2)
# what does that look like?
head(C19_mat1)
## Control_2h_1 Control_2h_2 Virus_2h_1 Virus_2h_2 Virus_6h_1 Virus_6h_2
## [1,] 0.53 0.78 0.60 0.84 0.64 1.51
## [2,] 0.59 0.68 0.60 0.66 1.35 1.41
## [3,] 1.56 1.22 1.59 1.23 2.49 1.72
## [4,] 1.21 1.40 1.22 1.39 2.14 2.54
## [5,] 1.52 1.53 1.51 1.60 1.95 1.84
## [6,] 1.13 1.22 0.98 1.41 2.17 4.34
## Virus_10h_1 Virus_10h_2 Virus_24h_1 Virus_24h_2
## [1,] 1.44 7.00 12.00 74.66
## [2,] 4.83 6.25 28.34 55.28
## [3,] 5.43 3.97 43.58 37.22
## [4,] 6.56 9.58 32.37 41.59
## [5,] 4.63 4.44 50.15 30.82
## [6,] 6.21 20.90 13.58 48.05
## make a heatmap from the data
pheatmap(C19_mat1, 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 24hrs is different than the other cells lines. We can 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
C19_data2<-C19_data %>% mutate(
mean_control= ((Control_2h_1 + Control_2h_2)/2),
mean_2h= ((Virus_2h_1 + Virus_2h_2)/2),
mean_6h= ((Virus_6h_1 + Virus_6h_2)/2),
mean_10h= ((Virus_10h_1 + Virus_10h_2)/2),
mean_24h= ((Virus_24h_1 + Virus_24h_2)/2))
view(C19_data2)
#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
C19_data2<-C19_data2 %>% mutate(
log_2h=log2(mean_2h/mean_control),
log_6h=log2(mean_6h/mean_control),
log_10h=log2(mean_10h/mean_control),
log_24h=log2(mean_24h/mean_control))
colnames(C19_data2)
## [1] "Accession" "Gene_Symbol" "Control_2h_1" "Control_2h_2" "Virus_2h_1"
## [6] "Virus_2h_2" "Virus_6h_1" "Virus_6h_2" "Virus_10h_1" "Virus_10h_2"
## [11] "Virus_24h_1" "Virus_24h_2" "P_value_2h" "P_value_6h" "P_value_10h"
## [16] "P_value_24h" "mean_control" "mean_2h" "mean_6h" "mean_10h"
## [21] "mean_24h" "log_2h" "log_6h" "log_10h" "log_24h"
#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
C19_mat2<-C19_data2 %>% select(log_2h:log_24h) %>% as.matrix() %>% round(.,2)
pheatmap(C19_mat2, 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, Virus_24h)
C19_data2<-C19_data2 %>% mutate(neglog_24h=-log10(P_value_24h))
## Use ggplot to plot the log ratio at 24 hours against the -log p-value at 24 hours
volcano_plot<-C19_data2 %>% ggplot(aes(x=log_24h,y=neglog_24h,description=Gene_Symbol))+
geom_point(alpha=0.7,color="royalblue")
#to view it, type:
volcano_plot
## BETTER VOLCANO PLOT
## Define the significant ones (by using ifelse and setting # parameters) so they can be colored
C19_data2<-C19_data2 %>% mutate(significance=ifelse((log_24h>2 & neglog_24h>2.99),"UP", ifelse((log_24h<c(-2) & neglog_24h>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<-C19_data2 %>% ggplot(aes(x=log_24h,y=neglog_24h,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 at 24 hrs COVID-19 infection compared to control",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: ___, ___ and _____
## Significant down regulated are: _____. _____ and ____
#Why? How?
# Make a pivot longer table of the C19 data for Control_2h_1:Virus_24h_2
C19_long<-pivot_longer(C19_data2, cols = c(Control_2h_1:Virus_24h_2), names_to = 'variable')%>% select(-c(P_value_2h:significance))%>%select(-Accession)
head(C19_long)
## # A tibble: 6 × 3
## Gene_Symbol variable value
## <chr> <chr> <dbl>
## 1 Viral_Protein_1 Control_2h_1 0.53
## 2 Viral_Protein_1 Control_2h_2 0.78
## 3 Viral_Protein_1 Virus_2h_1 0.6
## 4 Viral_Protein_1 Virus_2h_2 0.84
## 5 Viral_Protein_1 Virus_6h_1 0.64
## 6 Viral_Protein_1 Virus_6h_2 1.51
## 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<-C19_long %>% filter(Gene_Symbol=="SHH" | Gene_Symbol=="APLP2;APP" | Gene_Symbol=="TSPYL1")
head(Examples_Down)
## # A tibble: 6 × 3
## Gene_Symbol variable value
## <chr> <chr> <dbl>
## 1 TSPYL1 Control_2h_1 14.5
## 2 TSPYL1 Control_2h_2 13.4
## 3 TSPYL1 Virus_2h_1 11.4
## 4 TSPYL1 Virus_2h_2 13.1
## 5 TSPYL1 Virus_6h_1 10.9
## 6 TSPYL1 Virus_6h_2 12.2
## 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('Control_2h_1','Control_2h_2','Virus_2h_1','Virus_2h_2','Virus_6h_1','Virus_6h_2','Virus_10h_1','Virus_10h_2','Virus_24h_1','Virus_24h_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<-C19_long %>% filter(Gene_Symbol=="Viral_Protein_4" | Gene_Symbol=="Viral_Protein_8")
head(Examples_Up)
## # A tibble: 6 × 3
## Gene_Symbol variable value
## <chr> <chr> <dbl>
## 1 Viral_Protein_4 Control_2h_1 1.21
## 2 Viral_Protein_4 Control_2h_2 1.4
## 3 Viral_Protein_4 Virus_2h_1 1.22
## 4 Viral_Protein_4 Virus_2h_2 1.39
## 5 Viral_Protein_4 Virus_6h_1 2.14
## 6 Viral_Protein_4 Virus_6h_2 2.54
Example_plot_up<-Examples_Up %>% ggplot(aes(x=factor(variable,levels=c('Control_2h_1','Control_2h_2','Virus_2h_1','Virus_2h_2','Virus_6h_1','Virus_6h_2','Virus_10h_1','Virus_10h_2','Virus_24h_1','Virus_24h_2')),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
#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.
##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!