```{r setup, include=FALSE}
knitr::opts_chunk$set(
  results = 'asis',
  echo = FALSE,
  warning = FALSE,
  message = FALSE,
  fig.align = 'center'
)

#Load libraries
library(tidyverse)
library(gapminder)
library(kableExtra)
library(gganimate)
```


# Introduction
Hello! My name is Sophia, I am a molecular biologist working in proteomics, currently a Postdoctoral Fellow.  Before Data School, I coded using Macro (Excel). I used to spend a lot of time cleaning and tidying protein data; I always felt like I could do it faster if I had programming skills. These weeks learning R have changed my daily work. The skills I have obtained have allowed me to fast track the ordinary and focus on new perspectives of my research.

# My Project
 **Gluten** refers to a class of storage proteins found in cereal grains, including: wheat, rye, barley, and oats. Consumption of these gluten proteins leads to an autoimmune response in the case of coeliac disease. 
For my project, I want to characterise the known gluten proteins and peptides that are found in cereal grains to find a easy way of identified gluten in different cultivars.


## Preliminary results
I will analyse the amino acid composition of the proteins in my database. Since gluten proteins have a high composition of the amino acids glutamine (Q) and proline (P). I will search for all proteins that have over 20% glutamine.

**Tables**
```{r mytable, out.width='100%', echo = F}
my_database <- read.csv('Data/my_db.csv') 
knitr::kable(head(my_database, n = 5), format = "html", caption = "Protein database") %>% 
  kable_styling("striped", full_width = F) %>%
  column_spec(4, width_max = "30em", extra_css="overflow-y: auto") %>% 
  column_spec(2:3, bold=T, color= "blue") %>% 
  footnote(general= "5 examples of proteins found in the database. The column Sequence indicates the amino acids (letter code) that make up each protein.",
          footnote_as_chunk = T)
```

**Look for amino acids Q and P.**
```{r, echo=TRUE, message=FALSE}
library(tidyverse)
library(Biostrings)
my_database_comp <- mutate(my_database, totalAA= str_count(Sequence, '\\w'), Qcomp= str_count(Sequence,'Q')) %>% 
  mutate(Q100 =  Qcomp *100 / totalAA) %>% 
  mutate(Pcomp= str_count(Sequence,'P')) %>% 
  mutate(P100= Pcomp *100/totalAA)

my_database_comp[,'Q100']=round(my_database_comp[,'Q100'],2)
my_database_comp[,'P100']=round(my_database_comp[,'P100'],2)
```
```{r, echo=FALSE}
my_database_comp1 <- my_database_comp [,c(1,2,3,5,6,7,8,9)]
```
```{r, echo=FALSE}
knitr::kable(head(my_database_comp1, n = 5), format = "html", caption = "Aminoacid composition") %>% 
  kable_styling("striped", full_width = F) %>%
  column_spec(6:8, bold=T, color= "black") %>% 
  footnote(general= "totalAA = Number of total amino acids of the protein
           Qcomp= Number of glutamine found in the protein 
           Q100= Percentage of glutamine in the protein
           Pcomp= Number of proline found in the protein 
           P100= Percentage of proline in the protein",
           footnote_as_chunk = T)
```

**Working with Protein Data**





**Plotting**
```{r standard-plot, out.width='50%', fig.align='center', fig.show= 'hold', fig.height= 4, fig.width=6, fig.cap="Glutamine and Proline composition in database", out.extra='frontpage'}
gluten_q20 <- read.csv('Data/proteins_Q20.csv')
ggplot(my_database_comp)+
  geom_point(mapping = aes(x= P100, y=Q100), colour= 'palegreen3')+
  scale_x_log10()+
    labs(title='Proteins by composition',
         x='P%',
         y='Q%')+
  theme(title = element_text("bold"))+
  geom_point(data=gluten_q20, mapping = aes(x=P100, y=Q100), colour= 'maroon3')
  
ggplot(gluten_q20,aes(x=Q100))+
  geom_histogram(binwidth=1, fill="#69b3a2", color="#e9ecef", alpha=0.9)+
  labs(title='Proteins with >20% glutamine',
         x='Q%')+
  theme(title = element_text("bold"))


```
![](https://raw.githubusercontent.com/tidyverse/ggplot2/master/man/figures/logo.png){.pull-right width=100px}
![](Data/gganimate.jpg){width=100px}


**Now we see how the gluten proteins group in Wheat** <font size="3">
![](Data/gluten_wheat.gif){width=500px, height=500px}




# My Digital Toolbox
To work with Protein Databases, which are usually in the **.fasta** format, I have used the package `Biostrings`. For tidying the data,`Tidyverse` (my new best friend). 
Other packages I have used are: `dplyr` and `stringr`. For visualization `ggplot` and `gganimate`. 

![](Data/biostring.jpg){width=100px}
![](resources/img/tidyverse.png){width=100px}
![](Data/dplyr.jpg){width=100px}
![](Data/stringr.jpg){width=100px}


## Favourite tool 

My favorite package is `tidyverse`. With only learning a few functions in the first few days of Data School I already found ways to make my daily work much easier. It was love at second sight. I was able to clean and tidy my data. The functions that I used the most are **mutate**, **join** and of course pipe **%>%**.
Moreover, another of my favorite parts of working with R is using **Regex**, learn this was so useful for making scripts. 

![](resources/img/tidyverse.png){width=100px}


# My time went ...

tidying and cleaning protein raw data usually in Excel. At the beginning I thought it was going to be hard to work with Excel sheets in R but once you use *read. xlsx* is easy. I started creating a script to tidy and clean the protein data. In the beginning, it was hard to figure out how to tell the program to select variables, but once we learned *regex* is much faster. When I have doubts about functions or how to do something on R, I use *stackoverflow*. I also check on *twitter* because there is always good news or updates on there. 


# Next steps

I will keep working with R; I think there is a lot I haven't tried yet. I want to practice creating functions more.
In the future I would like to create a script that identifies non-gluten proteins - proteins that are similar to gluten or that generate and immune reaction in patients. But for that I will have to learn more things in R, like working with API. 

And maybe some day start with **python**......

# My Data School Experience

These months in Data School have been really helpful for my career and have reassured how much I like bioinformatics (somedays too much!). In the future, I will keep focusing on improving my coding skills. I hope that with this new skill I will be able to help my team and myself in making the process of tidying protein data much easier and faster. Since we started Data School I have been able to develop different scripts that will help myself and the team in future works. One of the scripts is **.proteins_fdr_report** for cleaning and tidying proteins reports using FDR threshold and selecting peptides with no modifications. Also, the one I showed here is for **.finding_gluten**. Moreover, I have been supported by my helper who is part of my team and we hope to create new scripts that help improve our team's capabilities.    

