---
title: "Proteomic Sample Information"
author: "Celeste Valdivia"
date: "2024-04-25"
output: html_document
---

```{r setup, include=FALSE}
library(knitr)
library(tidyverse)
library(tidyr)
library(dplyr)
library(hrbrthemes)
library(ggplot2)
library(RColorBrewer)
library(ggpubr)
library(stringr)
knitr::opts_chunk$set(echo = TRUE,
                      eval = FALSE)
```

# Objective

Determine which 12 of the 39 RNA samples available from the Autumn 2023 nickel trials to send off for RNAseq. We are targeting all late stage (C2-D) and high (45 mg/L nickel) vs control.

# Revtrieve Data
We will need both the morphometric data

```{r, engine='bash', eval=FALSE}
cd ..

curl -L https://docs.google.com/spreadsheets/d/10uM3N3PD9xIP4yUnadfhkcXa8TPMRMD-adOIKbmkYzY/export?exportFormat=csv | tee data/morph.csv
```


Read in the data to your local R environment.

```{r, eval=TRUE}
setwd('..')
morph <- read.csv(file = "data/morph.csv")  
```

# Cleaning up Data for Morph

```{r, eval=TRUE}
morph$date <- mdy(morph$date) #convert the date column from characters to true date
```

```{r, eval=TRUE}
morph <- morph %>%
  separate(jar_id, c("treatment", "replicate"), sep = "-") #create two new columns, treatment and replicate from jar id 
```

```{r, eval=TRUE}
morph <- morph %>%
  mutate(treatment = as.factor(treatment)) %>%
  mutate(animal_id = as.factor(animal_id)) %>%
  mutate(experiment = as.factor(experiment))
```

```{r}
# Create a new column 'simple_stage' based on conditions
morph <- morph %>%
  mutate(simple_stage = case_when(
    stage %in% c("A1", "A2") ~ "A",
    stage %in% c("B1", "B2") ~ "B",
    stage %in% c("C1", "C2") ~ "C",
    stage == "TO" ~ "D",
    TRUE ~ NA_character_  # This will handle any other cases or return NA if none match
  ))
```

clean up data frame to only include rows from the 24 hour mark and samples available for proteomics (half were used for dissections E1 and E2)
```{r}
morph_24 <- morph[morph$hpe == 24, ]

summary(morph_24)

morph_prot <- morph_24[morph_24$experiment %in% c("E3", "E4"), ]
```


# Reduce data frame to only columns of interest
Major Note: The system that was actually saved on the 24 hour mark is system 1 for the RNA work. System 2 was set aside for the proteomic work. If only one of them was tied it was the one that was set aside for proteomics. 


```{r}
df <- morph_prot[, c(1, 2, 4, 5, 6, 7, 8, 9, 12, 13, 15)] # get only relevant columns for proteomics

df <- df %>%
  mutate(attachment_sys2 = case_when(
    attachment == "attached" ~ "attached",
    attachment %in% c("both tied", "one tied", "tied") ~ "tied", # simplify the column attachment so that we know if the system intended for proteomics was attached or tied to the glass slide at freezing
    TRUE ~ NA_character_ #handle any other cases or return NA if none match
  ))

df <- df[, -11] # get rid of the original attachment column since we are only interested in the proteomics one
```


```{r}
setwd('..')
write.csv(df, file ="output/Proteomics_sampleID.csv")
```