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 
breast_cancer<-read_csv(file="breast_cancer_cells.csv")
## make some new columns that store the log ratios  
data1<-breast_cancer %>% 
  mutate(log2_mcf7=log2((MCF7_1+MCF7_2)/(MCF10A_1+MCF10A_2)),
    log2_mda231=log2((MDA231_1+MDA231_2)/(MCF10A_1+MCF10A_2)),
    log2_mda468=log2((MDA468_1+MDA468_2)/(MCF10A_1+MCF10A_2)),
    log2_skbr3=log2((SKBR3_1+SKBR3_2)/(MCF10A_1+MCF10A_2)))
data1
## # A tibble: 5,144 × 21
##    Gene_…¹ Descr…² Pepti…³ MCF10…⁴ MCF10…⁵ MCF7_1 MCF7_2 MDA23…⁶ MDA23…⁷ MDA46…⁸
##    <chr>   <chr>     <dbl>   <dbl>   <dbl>  <dbl>  <dbl>   <dbl>   <dbl>   <dbl>
##  1 NES     Nestin…       7    9.54    4.58   5.07   5.42   25.4    27.4     4.56
##  2 ZC3HC1  Isofor…       2   14      11.6    6.49   6.64    9.8    10.3     6.84
##  3 CAMSAP… Isofor…       5   10.2     8.29  11.6   10.8    12.5    10.1     9.54
##  4 COBRA1  Negati…       3    9       6.35  13.4   14.8    14.9    11.3     6.87
##  5 HAUS6   Isofor…       5    8.21    4.44  12.1    9.82   16.5    12.3    15.4 
##  6 CHCHD4  Isofor…       5   12.5    15.8    8.05   8.38    6.78    8.46    4.48
##  7 DHX30   Isofor…      17   12.6     8.18   9.51   9.76   12.7    11.4     7.3 
##  8 SLC12A2 Isofor…      15    6.33    4.21  11.3   11.5     3.03    2.28   27.2 
##  9 PTPRJ   Recept…       5    9.7     6.2    4.58   4.94   25.7    21.2     5.89
## 10 ATP6AP2 Renin …       8    9.02    5.69  14.5   15.2     7.25    6.2    14.3 
## # … with 5,134 more rows, 11 more variables: MDA468_2 <dbl>, SKBR3_1 <dbl>,
## #   SKBR3_2 <dbl>, pvalue_MCF7_vs_MCF10A <dbl>, pvalue_MDA231_vs_MCF10A <dbl>,
## #   pvalue_MDA468_vs_MCF10A <dbl>, pvalue_SKBR3_vs_MCF10A <dbl>,
## #   log2_mcf7 <dbl>, log2_mda231 <dbl>, log2_mda468 <dbl>, log2_skbr3 <dbl>,
## #   and abbreviated variable names ¹​Gene_Symbol, ²​Description, ³​Peptides,
## #   ⁴​MCF10A_1, ⁵​MCF10A_2, ⁶​MDA231_1, ⁷​MDA231_2, ⁸​MDA468_1
## make a matrix of just the data
breast_cancer_mat1<-data1 %>%
  select(log2_mcf7:log2_skbr3) %>%
  as.matrix() %>% 
  round(.,2)

head(breast_cancer_mat1)
##      log2_mcf7 log2_mda231 log2_mda468 log2_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
## make a heatmap from the data
pheatmap(breast_cancer_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
volcano<-data1 %>%
  mutate(neglog_MDA468=-log10(pvalue_MCF7_vs_MCF10A))
volcano
## # A tibble: 5,144 × 22
##    Gene_…¹ Descr…² Pepti…³ MCF10…⁴ MCF10…⁵ MCF7_1 MCF7_2 MDA23…⁶ MDA23…⁷ MDA46…⁸
##    <chr>   <chr>     <dbl>   <dbl>   <dbl>  <dbl>  <dbl>   <dbl>   <dbl>   <dbl>
##  1 NES     Nestin…       7    9.54    4.58   5.07   5.42   25.4    27.4     4.56
##  2 ZC3HC1  Isofor…       2   14      11.6    6.49   6.64    9.8    10.3     6.84
##  3 CAMSAP… Isofor…       5   10.2     8.29  11.6   10.8    12.5    10.1     9.54
##  4 COBRA1  Negati…       3    9       6.35  13.4   14.8    14.9    11.3     6.87
##  5 HAUS6   Isofor…       5    8.21    4.44  12.1    9.82   16.5    12.3    15.4 
##  6 CHCHD4  Isofor…       5   12.5    15.8    8.05   8.38    6.78    8.46    4.48
##  7 DHX30   Isofor…      17   12.6     8.18   9.51   9.76   12.7    11.4     7.3 
##  8 SLC12A2 Isofor…      15    6.33    4.21  11.3   11.5     3.03    2.28   27.2 
##  9 PTPRJ   Recept…       5    9.7     6.2    4.58   4.94   25.7    21.2     5.89
## 10 ATP6AP2 Renin …       8    9.02    5.69  14.5   15.2     7.25    6.2    14.3 
## # … with 5,134 more rows, 12 more variables: MDA468_2 <dbl>, SKBR3_1 <dbl>,
## #   SKBR3_2 <dbl>, pvalue_MCF7_vs_MCF10A <dbl>, pvalue_MDA231_vs_MCF10A <dbl>,
## #   pvalue_MDA468_vs_MCF10A <dbl>, pvalue_SKBR3_vs_MCF10A <dbl>,
## #   log2_mcf7 <dbl>, log2_mda231 <dbl>, log2_mda468 <dbl>, log2_skbr3 <dbl>,
## #   neglog_MDA468 <dbl>, and abbreviated variable names ¹​Gene_Symbol,
## #   ²​Description, ³​Peptides, ⁴​MCF10A_1, ⁵​MCF10A_2, ⁶​MDA231_1, ⁷​MDA231_2,
## #   ⁸​MDA468_1

## 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<-volcano %>%
  ggplot(aes(x=log2_mcf7,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
better_volcano<-volcano %>% 
  mutate(significance=ifelse((log2_mcf7>2 & neglog_MDA468>2.99),"UP", ifelse((log2_mcf7<c(-2) & neglog_MDA468>2.99),"DOWN","NOT SIG")))
better_volcano
## # A tibble: 5,144 × 23
##    Gene_…¹ Descr…² Pepti…³ MCF10…⁴ MCF10…⁵ MCF7_1 MCF7_2 MDA23…⁶ MDA23…⁷ MDA46…⁸
##    <chr>   <chr>     <dbl>   <dbl>   <dbl>  <dbl>  <dbl>   <dbl>   <dbl>   <dbl>
##  1 NES     Nestin…       7    9.54    4.58   5.07   5.42   25.4    27.4     4.56
##  2 ZC3HC1  Isofor…       2   14      11.6    6.49   6.64    9.8    10.3     6.84
##  3 CAMSAP… Isofor…       5   10.2     8.29  11.6   10.8    12.5    10.1     9.54
##  4 COBRA1  Negati…       3    9       6.35  13.4   14.8    14.9    11.3     6.87
##  5 HAUS6   Isofor…       5    8.21    4.44  12.1    9.82   16.5    12.3    15.4 
##  6 CHCHD4  Isofor…       5   12.5    15.8    8.05   8.38    6.78    8.46    4.48
##  7 DHX30   Isofor…      17   12.6     8.18   9.51   9.76   12.7    11.4     7.3 
##  8 SLC12A2 Isofor…      15    6.33    4.21  11.3   11.5     3.03    2.28   27.2 
##  9 PTPRJ   Recept…       5    9.7     6.2    4.58   4.94   25.7    21.2     5.89
## 10 ATP6AP2 Renin …       8    9.02    5.69  14.5   15.2     7.25    6.2    14.3 
## # … with 5,134 more rows, 13 more variables: MDA468_2 <dbl>, SKBR3_1 <dbl>,
## #   SKBR3_2 <dbl>, pvalue_MCF7_vs_MCF10A <dbl>, pvalue_MDA231_vs_MCF10A <dbl>,
## #   pvalue_MDA468_vs_MCF10A <dbl>, pvalue_SKBR3_vs_MCF10A <dbl>,
## #   log2_mcf7 <dbl>, log2_mda231 <dbl>, log2_mda468 <dbl>, log2_skbr3 <dbl>,
## #   neglog_MDA468 <dbl>, significance <chr>, and abbreviated variable names
## #   ¹​Gene_Symbol, ²​Description, ³​Peptides, ⁴​MCF10A_1, ⁵​MCF10A_2, ⁶​MDA231_1,
## #   ⁷​MDA231_2, ⁸​MDA468_1
## Some standard colors
plain_cols3<-c("red","gray","blue")

## volcano plot as before with some added graph features 
better_volcano_plot<-better_volcano %>% ggplot(aes(x=log2_mcf7,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 at mcf7 compared to control",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
long_data<-pivot_longer(better_volcano, cols = c(MCF10A_1:SKBR3_2), names_to = 'variable')%>%
  select(-c(pvalue_MCF7_vs_MCF10A:significance))

head(long_data)
## # 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<-long_data %>%
  filter(Gene_Symbol=="HLA-A" | Gene_Symbol=="APOA1" | Gene_Symbol=="CTSZ") 

head(examples_down)
## # A tibble: 6 × 5
##   Gene_Symbol Description                                  Pepti…¹ varia…² value
##   <chr>       <chr>                                          <dbl> <chr>   <dbl>
## 1 HLA-A       HLA class I histocompatibility antigen, A-2…       3 MCF10A…  5.42
## 2 HLA-A       HLA class I histocompatibility antigen, A-2…       3 MCF10A…  6.62
## 3 HLA-A       HLA class I histocompatibility antigen, A-2…       3 MCF7_1   2.22
## 4 HLA-A       HLA class I histocompatibility antigen, A-2…       3 MCF7_2   2.69
## 5 HLA-A       HLA class I histocompatibility antigen, A-2…       3 MDA231…  4.56
## 6 HLA-A       HLA class I histocompatibility antigen, A-2…       3 MDA231…  4.23
## # … 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<-long_data %>%
  filter(Gene_Symbol=="C17orf28" | Gene_Symbol=="FBP2" | Gene_Symbol=="DICER1") 

head(examples_up)
## # A tibble: 6 × 5
##   Gene_Symbol Description                                  Pepti…¹ varia…² value
##   <chr>       <chr>                                          <dbl> <chr>   <dbl>
## 1 FBP2        Fructose-1,6-bisphosphatase isozyme 2 OS=Ho…       2 MCF10A…  1.13
## 2 FBP2        Fructose-1,6-bisphosphatase isozyme 2 OS=Ho…       2 MCF10A…  0.76
## 3 FBP2        Fructose-1,6-bisphosphatase isozyme 2 OS=Ho…       2 MCF7_1  43.9 
## 4 FBP2        Fructose-1,6-bisphosphatase isozyme 2 OS=Ho…       2 MCF7_2  41.4 
## 5 FBP2        Fructose-1,6-bisphosphatase isozyme 2 OS=Ho…       2 MDA231…  2.24
## 6 FBP2        Fructose-1,6-bisphosphatase isozyme 2 OS=Ho…       2 MDA231…  1.7 
## # … with abbreviated variable names ¹​Peptides, ²​variable

example_plot_up<-examples_up %>% 
  ggplot(aes(x=variable,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

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<-data1 %>%
  filter(Gene_Symbol=="HLA-A" | Gene_Symbol=="APOA1" | Gene_Symbol=="CTSZ") %>% 
  select(Gene_Symbol,Description,Peptides)
downregulated
## # A tibble: 6 × 3
##   Gene_Symbol Description                                                Pepti…¹
##   <chr>       <chr>                                                        <dbl>
## 1 HLA-A       HLA class I histocompatibility antigen, A-23 alpha chain …       3
## 2 HLA-A       HLA class I histocompatibility antigen, A-30 alpha chain …       1
## 3 HLA-A       HLA class I histocompatibility antigen, A-2 alpha chain O…      21
## 4 CTSZ        Cathepsin Z OS=Homo sapiens GN=CTSZ PE=1 SV=1                    8
## 5 HLA-A       HLA class I histocompatibility antigen, A-1 alpha chain O…       1
## 6 APOA1       Apolipoprotein A-I OS=Homo sapiens GN=APOA1 PE=1 SV=1            2
## # … with abbreviated variable name ¹​Peptides
#Upregulated
upregulated<-data1 %>%
  filter(Gene_Symbol=="C17orf28" | Gene_Symbol=="FBP2" | Gene_Symbol=="DICER1") %>% 
  select(Gene_Symbol,Description,Peptides)
upregulated
## # A tibble: 3 × 3
##   Gene_Symbol Description                                                Pepti…¹
##   <chr>       <chr>                                                        <dbl>
## 1 FBP2        Fructose-1,6-bisphosphatase isozyme 2 OS=Homo sapiens GN=…       2
## 2 DICER1      Endoribonuclease Dicer OS=Homo sapiens GN=DICER1 PE=1 SV=3       1
## 3 C17orf28    Isoform 2 of UPF0663 transmembrane protein C17orf28 OS=Ho…       3
## # … with abbreviated variable name ¹​Peptides