Working from the COVID.rmd model, fill in the blank chunks with code to analize the dataset of your choice. You will need to think about what you are copying and pasting and what needs to be updated to make the code relevant to your chosen dataset. Double check all syntax and be precise!

###First, let’s load RMarkdown

library(rmarkdown)

set messages to FALSE on everything (prevents certain boring things from being shown in the results)

knitr::opts_chunk$set(echo = TRUE, message=FALSE,warning=FALSE,collapse = TRUE)

PACKAGES

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)

COLORS

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 DATA AND MAKE AN OVERALL HEATMAP

## load the dataset 
BCC_data<-read_csv(file="breast_cancer_cells.csv")

## make some new columns that store the log ratios
BCC_data <- BCC_data %>%  mutate(
  log_MCF7=log2((MCF7_1+MCF7_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)),
  log_MDA231=log2((MDA231_1+MDA231_2)/(MCF10A_1+MCF10A_2))) 
  
## make a matrix of just the data
BCC_mat1<-BCC_data %>% select(log_MCF7:log_MDA231) %>% as.matrix() %>% round(.,2)

head(BCC_mat1)
##      log_MCF7 log_MDA468 log_SKBR3 log_MDA231
## [1,]    -0.43      -0.74         0       1.90
## [2,]    -0.96      -0.71         0      -0.35
## [3,]     0.27      -0.04         0       0.29
## [4,]     0.88      -0.05         0       0.78
## [5,]     0.79       0.92         0       1.19
## [6,]    -0.79      -1.28         0      -0.90
## make a heatmap from the data
pheatmap(BCC_mat1, color=pats_cols,cellwidth=30,cellheight=.03,cluster_cols=FALSE,cluster_rows=FALSE,legend=TRUE,fontsize = 7,scale="column")

PLOTTING A VOLCANO

##BASIC VOLCANO PLOT

## Add a column that stores the negative log of the pvalue of interest
BCC_data<-BCC_data %>% mutate(neglog_MDA468=-log10(pvalue_MDA468_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<-BCC_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 so they can be colored
BCC_data<-BCC_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 graph features 
better_volcano_plot<-BCC_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 MDA468 compared to MCF10A",y="-log(p-value)")
  

better_volcano_plot

## use ggplotly to see hover over the points to see the gene names
ggplotly(better_volcano_plot)

Barplots of significant points of interest

## 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
BCC_long<-pivot_longer(BCC_data, cols = c(MCF10A_1:SKBR3_2), names_to = 'variable')%>% select(-c(pvalue_MCF7_vs_MCF10A:significance))

head(BCC_long)
## # A tibble: 6 × 5
##   Gene_Symbol Description                             Peptides variable value
##   <chr>       <chr>                                      <dbl> <chr>    <dbl>
## 1 NES         Nestin OS=Homo sapiens GN=NES PE=1 SV=2        7 MCF10A_1  9.54
## 2 NES         Nestin OS=Homo sapiens GN=NES PE=1 SV=2        7 MCF10A_2  4.58
## 3 NES         Nestin OS=Homo sapiens GN=NES PE=1 SV=2        7 MCF7_1    5.07
## 4 NES         Nestin OS=Homo sapiens GN=NES PE=1 SV=2        7 MCF7_2    5.42
## 5 NES         Nestin OS=Homo sapiens GN=NES PE=1 SV=2        7 MDA231_1 25.4 
## 6 NES         Nestin OS=Homo sapiens GN=NES PE=1 SV=2        7 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 from the pivot longer table you just made 
Examples_Down<-BCC_long %>% filter(Gene_Symbol=="PLAU" | Gene_Symbol=="HLA-A" | Gene_Symbol=="HLA-B"| Gene_Symbol=="CTNNA1"| Gene_Symbol=="ADCK3"| Gene_Symbol=="PTPRE"| Gene_Symbol=="FMNL1"| Gene_Symbol=="EXOG"| Gene_Symbol=="P4HA1"| Gene_Symbol=="PYGL"| Gene_Symbol=="CTSZ")

head(Examples_Down)
## # A tibble: 6 × 5
##   Gene_Symbol Description                                  Pepti…¹ varia…² value
##   <chr>       <chr>                                          <dbl> <chr>   <dbl>
## 1 PYGL        Glycogen phosphorylase, liver form OS=Homo …      11 MCF10A…  8.86
## 2 PYGL        Glycogen phosphorylase, liver form OS=Homo …      11 MCF10A…  9.15
## 3 PYGL        Glycogen phosphorylase, liver form OS=Homo …      11 MCF7_1   9.13
## 4 PYGL        Glycogen phosphorylase, liver form OS=Homo …      11 MCF7_2   8.92
## 5 PYGL        Glycogen phosphorylase, liver form OS=Homo …      11 MDA231… 21.4 
## 6 PYGL        Glycogen phosphorylase, liver form OS=Homo …      11 MDA231… 19.4 
## # … with abbreviated variable names ¹​Peptides, ²​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<-BCC_long %>% filter(Gene_Symbol=="SYT7" | Gene_Symbol=="UGP2" | Gene_Symbol=="CAPN1"| Gene_Symbol=="SOD1"| Gene_Symbol=="COMMD9"| Gene_Symbol=="MYO6"| Gene_Symbol=="CDK5"| Gene_Symbol=="IFT27"| Gene_Symbol=="GNL1"| Gene_Symbol=="SH3BP1"|Gene_Symbol=="PSAT1"| Gene_Symbol=="ARFIP1"| Gene_Symbol=="AGR2"| Gene_Symbol=="AKR1C2"| Gene_Symbol=="NLRP2"| Gene_Symbol=="PADI2"| Gene_Symbol=="CES1"|Gene_Symbol=="ALDH1A3"| Gene_Symbol=="S100P")



head(Examples_Up)
## # A tibble: 6 × 5
##   Gene_Symbol Description                                  Pepti…¹ varia…² value
##   <chr>       <chr>                                          <dbl> <chr>   <dbl>
## 1 PSAT1       Phosphoserine aminotransferase OS=Homo sapi…      22 MCF10A…  4.15
## 2 PSAT1       Phosphoserine aminotransferase OS=Homo sapi…      22 MCF10A…  3.49
## 3 PSAT1       Phosphoserine aminotransferase OS=Homo sapi…      22 MCF7_1   2.76
## 4 PSAT1       Phosphoserine aminotransferase OS=Homo sapi…      22 MCF7_2   3.5 
## 5 PSAT1       Phosphoserine aminotransferase OS=Homo sapi…      22 MDA231…  8.38
## 6 PSAT1       Phosphoserine aminotransferase OS=Homo sapi…      22 MDA231…  7.08
## # … with abbreviated variable names ¹​Peptides, ²​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

BONUS CODE- for figuring out what the gene symbols are

#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 <-BCC_data %>% filter(significance == 'DOWN') %>% select(Gene_Symbol,Description,Peptides)
downregulated
## # A tibble: 12 × 3
##    Gene_Symbol Description                                               Pepti…¹
##    <chr>       <chr>                                                       <dbl>
##  1 PYGL        Glycogen phosphorylase, liver form OS=Homo sapiens GN=PY…      11
##  2 FMNL1       Isoform 2 of Formin-like protein 1 OS=Homo sapiens GN=FM…       1
##  3 P4HA1       Isoform 2 of Prolyl 4-hydroxylase subunit alpha-1 OS=Hom…       9
##  4 HLA-B       HLA class I histocompatibility antigen, B-52 alpha chain…       1
##  5 CTSZ        Cathepsin Z OS=Homo sapiens GN=CTSZ PE=1 SV=1                   8
##  6 PTPRE       Isoform 2 of Receptor-type tyrosine-protein phosphatase …       1
##  7 PLAU        Isoform 2 of Urokinase-type plasminogen activator OS=Hom…       2
##  8 ADCK3       Isoform 3 of Chaperone activity of bc1 complex-like, mit…       2
##  9 CTNNA1      Isoform 2 of Catenin alpha-1 OS=Homo sapiens GN=CTNNA1         30
## 10 EXOG        Nuclease EXOG, mitochondrial OS=Homo sapiens GN=EXOG PE=…       3
## 11 HLA-A       HLA class I histocompatibility antigen, A-1 alpha chain …       1
## 12 APOA1       Apolipoprotein A-I OS=Homo sapiens GN=APOA1 PE=1 SV=1           2
## # … with abbreviated variable name ¹​Peptides

#Upregulated
upregulated <-BCC_data %>% filter(significance == 'UP') %>% select(Gene_Symbol,Description,Peptides)
upregulated
## # A tibble: 23 × 3
##    Gene_Symbol Description                                               Pepti…¹
##    <chr>       <chr>                                                       <dbl>
##  1 PSAT1       Phosphoserine aminotransferase OS=Homo sapiens GN=PSAT1 …      22
##  2 CES1        Isoform 2 of Liver carboxylesterase 1 OS=Homo sapiens GN…       6
##  3 AKR1C2      Aldo-keto reductase family 1 member C2 OS=Homo sapiens G…      27
##  4 NLRP2       Isoform 2 of NACHT, LRR and PYD domains-containing prote…       2
##  5 SH3BP1      Isoform 2 of SH3 domain-binding protein 1 OS=Homo sapien…       3
##  6 SYT7        Synaptotagmin-7 OS=Homo sapiens GN=SYT7 PE=1 SV=3               1
##  7 AGR2        Anterior gradient protein 2 homolog OS=Homo sapiens GN=A…      37
##  8 CDKN2A      Isoform 2 of Cyclin-dependent kinase inhibitor 2A, isofo…       1
##  9 SULT1A1     Sulfotransferase 1A1 OS=Homo sapiens GN=SULT1A1 PE=1 SV=3       3
## 10 ALDH1A3     Aldehyde dehydrogenase family 1 member A3 OS=Homo sapien…      16
## # … with 13 more rows, and abbreviated variable name ¹​Peptides