---
title: "hadexReport"
author: ""
date: ""
output:
  html_document:
    theme: united
    highlight: textmate
    toc: true
    toc_float: true
    number_sections: false
    df_print: paged
---

<style type="text/css">
span { 
      display: block;
      max-width: 100%;
      word-wrap: break-word;
    }
</style>



Report generated on `r Sys.time()` using the [HaDeX](http://github.com/michbur/HaDeX) R package.  

Detected input file: `r ifelse(is.null(input[["data_file"]][["name"]]), "none", input[["data_file"]][["name"]])`.  

MD5 hash of the input file: `r ifelse(is.null(input[["data_file"]][["name"]]), "none (example file)", tools::md5sum(as.character(input[["data_file"]][["datapath"]])))`.

# Summary

Protein name : `r as.character(unique(dat()[["Protein"]]))`

Protein sequence : <span>`r protein_sequence_colored()`</span>

Sequence length : `r input[["sequence_length"]]`

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}
knitr::kable(summary_data())
```

```{r, child="readmes/summary.md"}
```

<!--- OVERLAP DISTRIBUTION -->

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_overlap_dist"]]){
  
  cat("## Overlap Distribution \n")
  
  stateOverlapDist()

}

```

<!--- OVERLAP DISTRIBUTION DATA -->

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_overlap_dist_data"]]){

  cat("## Overlap Distribution Data \n")
  
  stateOverlapDist_data()
  
}

```

<!--- OVERLAP GRAPHICALLY -->

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_overlap_graph"]]){
    
  cat("## Overlap Graphically \n")
    
  stateOverlap_out() 
  
}


```

<!--- OVERLAP GRAPHICALLY DATA -->

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_overlap_graph_data"]]){
    
  cat("## Overlap Graphically Data \n")  
    
  stateOverlap_data()
  
}


```

<!--- COMPARISON PLOT --->

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_comparison_plot"]]){
    
  cat("## Comparison Plot \n")
  
  cat("### Relative values \n")
  
  if(has_modifications()){
    cat("Supplied file contains modified peptids. Maximal exchange control cannot be applied.")
  } else{
    if(input[["out_time"]] == 99999){
      cat(paste0("Chosen control: ", input[["chosen_control"]], "."))
    } else{
      cat("No chosen control. \n")
    }
  }
  

  p <- comparison_plot_exp() +
    scale_color_manual(values = as.vector(comparison_plot_colors_chosen()))
  
  if(!input[["theory"]] & input[["calc_type"]]=="relative"){
    
    p + 
      coord_cartesian(ylim = c(input[["comp_plot_y_range"]][[1]], input[["comp_plot_y_range"]][[2]]),
                      xlim = c(input[["plot_x_range"]][[1]], input[["plot_x_range"]][[2]])) +
      labs(title = input[["comparison_plot_title"]], 
           x = input[["comparison_plot_x_label"]],
           y = input[["comparison_plot_y_label"]])
      
  } else {
    
    p + 
      coord_cartesian(xlim = c(input[["plot_x_range"]][[1]], input[["plot_x_range"]][[2]])) + 
      labs(title = paste0("Fraction exchanged in state comparison in ", input[["chosen_time"]], " min"),
           x = "Position in sequence",
           y = "Fraction exchanged [%]") 
    
  }
  
}

```

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_comparison_plot"]]){

  cat("### Absolute values \n")
  
  p <- comparison_plot_exp_abs() +
    scale_color_manual(values = as.vector(comparison_plot_colors_chosen()))
  
  if (!input[["theory"]] & input[["calc_type"]]=="absolute"){
    
    p + 
      coord_cartesian(ylim = c(input[["comp_plot_y_range"]][[1]], input[["comp_plot_y_range"]][[2]]),
                      xlim = c(input[["plot_x_range"]][[1]], input[["plot_x_range"]][[2]])) +
      labs(title = input[["comparison_plot_title"]], 
           x = input[["comparison_plot_x_label"]],
           y = input[["comparison_plot_y_label"]])
    
  } else {
    
    p + 
      coord_cartesian(xlim = c(input[["plot_x_range"]][[1]], input[["plot_x_range"]][[2]])) +
      labs(title = paste0("Absolute value exchanged in state comparison in ", input[["chosen_time"]], " min"),
           x = "Position in sequence", 
           y = "Absolute value exchanged [Da]")
  }
  
 
}

```

<!--- COMPARISON PLOT DATA --->

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_comparison_plot_data"]]){
    
  cat("## Comparison Plot Data \n")
  
  cat("### Relative values \n")
  
if(has_modifications()){
    cat("Supplied file contains modified peptids. Maximal exchange control cannot be applied.")
  } else{
    if(input[["out_time"]] == 99999){
      cat(paste0("Chosen control: ", input[["chosen_control"]], "."))
    } else{
      cat("No chosen control. \n")
    }
  }
  comparison_plot_data_exp() 
  
  
    
}
```

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_comparison_plot_data"]]){
  
  cat("### Absolute values \n")
  
  comparison_plot_data_exp_abs()
  
}

```

<!--- THEORETICAL COMPARISON PLOT --->

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_theo_comparison_plot"]]){
    
  cat("## Theoretical Comparison Plot \n")
  
  cat("### Relative values \n")

  cat(paste0("Deuterium concentration: ", input[["deut_concentration"]], "%."))
  
  p <- comparison_plot_theo() + 
    scale_color_manual(values = as.vector(comparison_plot_colors_chosen()))
    
  if(input[["theory"]] & input[["calc_type"]]=="relative"){
    
    p + 
      coord_cartesian(ylim = c(input[["comp_plot_y_range"]][[1]], input[["comp_plot_y_range"]][[2]]),
                      xlim = c(input[["plot_x_range"]][[1]], input[["plot_x_range"]][[2]])) +
      labs(title = input[["comparison_plot_title"]], 
           x = input[["comparison_plot_x_label"]],
           y = input[["comparison_plot_y_label"]])
    
  } else {
    
    p + 
      coord_cartesian(xlim = c(input[["plot_x_range"]][[1]], input[["plot_x_range"]][[2]])) +
      labs(title = paste0("Theoretical fraction exchanged in state comparison in ", input[["chosen_time"]], " min"),
           x = "Position in sequence",
           y = "Theoretical fraction exchanged [%]")
      
  }
    
}
```

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_theo_comparison_plot"]]){
  
  cat("### Absolute values \n")
  
  p <- comparison_plot_theo_abs() +
    scale_color_manual(values = as.vector(comparison_plot_colors_chosen()))
  
  if(input[["theory"]] & input[["calc_type"]]=="absolute"){
    
    p + 
      coord_cartesian(ylim = c(input[["comp_plot_y_range"]][[1]], input[["comp_plot_y_range"]][[2]]),
                      xlim = c(input[["plot_x_range"]][[1]], input[["plot_x_range"]][[2]])) +
      labs(title = input[["comparison_plot_title"]], 
           x = input[["comparison_plot_x_label"]],
           y = input[["comparison_plot_y_label"]])
    
  } else {
    
    p + 
      coord_cartesian(xlim = c(input[["plot_x_range"]][[1]], input[["plot_x_range"]][[2]]))+
      labs(title = paste0("Theoretical absolute value exchanged in state comparison in ", input[["chosen_time"]], " min"),
           x = "Position in sequence",
           y = "Theoretical absolute value exchanged [Da]")
  }
  
}

```

<!--- THEORETICAL COMPARISON PLOT DATA --->

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_theo_comparison_plot_data"]]){
    
  cat("## Theoretical Comparison Plot Data \n")
  
  cat("### Relative values \n")
  
  cat(paste0("Deuterium concentration: ", input[["deut_concentration"]], "%."))
  
  comparison_plot_data_theo()
    
}

```

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_theo_comparison_plot_data"]]){
  
  cat("### Absolute values \n")
  
  comparison_plot_data_theo_abs()
  
}

```

<!--- WOODS PLOT --->

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_woods_plot"]]){
    
  cat("## Woods Plot \n")  
  
  cat("### Relative values \n")
  
if(has_modifications()){
    cat("Supplied file contains modified peptids. Maximal exchange control cannot be applied.")
  } else{
    if(input[["out_time"]] == 99999){
      cat(paste0("Chosen control: ", input[["chosen_control"]], "."))
    } else{
      cat("No chosen control. \n")
    }
  }
  
  p <- differential_plot_exp()
  
  if(!input[["theory"]] & input[["calc_type"]] == "relative"){
    
    p + 
      coord_cartesian(ylim = c(input[["woods_plot_y_range"]][[1]], input[["woods_plot_y_range"]][[2]]),
                      xlim = c(input[["plot_x_range"]][[1]], input[["plot_x_range"]][[2]])) +
      labs(title = input[["woods_plot_title"]], 
           x = input[["woods_plot_x_label"]],
           y = input[["woods_plot_y_label"]])
    
  } else {
    
    p + 
      coord_cartesian(xlim = c(input[["plot_x_range"]][[1]], input[["plot_x_range"]][[2]])) +
      labs(title = paste0("Delta Fraction exchanged in ", input[["chosen_time"]], " min between ", gsub("_", " ", input[["state_first"]]), " and ", gsub("_", " ", input[["state_second"]])),
           x = "Position in sequence",
           y = "Delta Fraction exchanged between states [%]")
    
  }
    
}

```

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_woods_plot"]]){
  
  cat("### Absolute values \n")
  
  p <- differential_plot_exp_abs()
  
  if(!input[["theory"]] & input[["calc_type"]] == "absolute"){
    
    p + 
      coord_cartesian(ylim = c(input[["woods_plot_y_range"]][[1]], input[["woods_plot_y_range"]][[2]]),
                      xlim = c(input[["plot_x_range"]][[1]], input[["plot_x_range"]][[2]])) +
      labs(title = input[["woods_plot_title"]], 
           x = input[["woods_plot_x_label"]],
           y = input[["woods_plot_y_label"]])
    
  } else {
    
    p + 
      coord_cartesian(xlim = c(input[["plot_x_range"]][[1]], input[["plot_x_range"]][[2]])) +
      labs(title = paste0("Delta Fraction exchanged in ", input[["chosen_time"]], " min between ", gsub("_", " ", input[["state_first"]]), " and ", gsub("_", " ", input[["state_second"]])),
           x = "Position in sequence",
           y = "Delta Absolute value exchanged between states [Da]")
  }
  
}

```

<!--- WOODS PLOT DATA --->

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_woods_plot_data"]]){
    
  cat("## Woods Plot Data \n")
  
  cat("### Relative values \n")
  
if(has_modifications()){
    cat("Supplied file contains modified peptids. Maximal exchange control cannot be applied.")
  } else{
    if(input[["out_time"]] == 99999){
      cat(paste0("Chosen control: ", input[["chosen_control"]], "."))
    } else{
      cat("No chosen control. \n")
    }
  }
  
  differential_plot_data_exp()
    
}

```

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_woods_plot_data"]]){
  
  cat("### Absolute values \n")
  
  differential_plot_data_exp_abs()
  
}

```

<!--- THEORETICAL WOODS PLOT --->

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_theo_woods_plot"]]){
    
  cat("## Theoretical Woods Plot \n")  
  
  cat("### Relative values \n")
  
  cat(paste0("Deuterium concentration: ", input[["deut_concentration"]], "%."))
  
  p <- differential_plot_theo()
  
  if(input[["theory"]] & input[["calc_type"]] == "relative"){
    
    p + 
      coord_cartesian(ylim = c(input[["woods_plot_y_range"]][[1]], input[["woods_plot_y_range"]][[2]]),
                      xlim = c(input[["plot_x_range"]][[1]], input[["plot_x_range"]][[2]])) +
      labs(title = input[["woods_plot_title"]], 
           x = input[["woods_plot_x_label"]],
           y = input[["woods_plot_y_label"]])
    
  } else {
    
    p + 
      coord_cartesian(xlim = c(input[["plot_x_range"]][[1]], input[["plot_x_range"]][[2]])) +
      labs(title = paste0("Delta Theoretical fraction exchanged in ", input[["chosen_time"]], " min between ", gsub("_", " ", input[["state_first"]]), " and ", gsub("_", " ", input[["state_second"]])),
           x = "Position in sequence",
           y = "Delta Theoretical fraction exchanged between states [%]")
    
  }
    
}


```

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_theo_woods_plot"]]){
  
  cat("### Absolute values \n")
  
  p <- differential_plot_theo_abs()
  
  if(input[["theory"]] & input[["calc_type"]] == "absolute"){
    
    p + 
      coord_cartesian(ylim = c(input[["woods_plot_y_range"]][[1]], input[["woods_plot_y_range"]][[2]]),
                      xlim = c(input[["plot_x_range"]][[1]], input[["plot_x_range"]][[2]])) +
      labs(title = input[["woods_plot_title"]], 
           x = input[["woods_plot_x_label"]],
           y = input[["woods_plot_y_label"]])
    
  } else {
    
    p + 
      coord_cartesian(xlim = c(input[["plot_x_range"]][[1]], input[["plot_x_range"]][[2]])) +
      labs(title = paste0("Delta Theoretical fraction exchanged in ", input[["chosen_time"]], " min between ", gsub("_", " ", input[["state_first"]]), " and ", gsub("_", " ", input[["state_second"]])),
           x = "Position in sequence",
           y = "Delta Theoretical absoute value exchanged between states [Da]")
    
  }
    
}


```

<!--- THEORETICAL WOODS PLOT DATA --->

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_theo_woods_plot_data"]]){
    
  cat("## Theoretical Woods Plot Data \n")
  
  cat("### Relative values \n")
  
  cat(paste0("Deuterium concentration: ", input[["deut_concentration"]], "%."))
    
  differential_plot_data_theo()
    
}

```

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_theo_woods_plot_data"]]){
  
  cat("### Absolute values \n")
    
  differential_plot_data_theo_abs()
    
}

```




<!--- KINETIC CHECK --->

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

kin_valid <- length(input[["peptide_list_data_rows_selected"]]) > 0


```

<!--- KINETIC PLOT --->

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_kin_plot"]]){
  
  cat("## Uptake curve \n")
  
  if (kin_valid) {
    
    cat("### Relative values \n")
    
 if(has_modifications()){
    cat("Supplied file contains modified peptids. Maximal exchange control cannot be applied.")
  } else{
    if(input[["out_time"]] == 99999){
      cat(paste0("Chosen control: ", input[["chosen_control"]], "."))
    } else{
      cat("No chosen control. \n")
    }
  }
    
    p <- kin_plot_exp()
    
    if(!input[["theory"]] & input[["calc_type"]]=="relative"){
    
      p + 
        coord_cartesian(ylim = c(input[["kin_plot_y_range"]][[1]], input[["kin_plot_y_range"]][[2]])) +
        labs(title = input[["kin_plot_title"]], 
             x = input[["kin_plot_x_label"]],
             y = input[["kin_plot_y_label"]]) +
        theme(legend.position = "bottom",
              legend.title = element_blank())
        
    } else {
      
      p + 
        labs(title = "Uptake curve for chosen peptides",
             x = "Time points [min]",
             y = "Deuteration [%]") +
        scale_y_continuous(limits = c(0, 110)) + 
        theme(legend.position = "bottom",
              legend.title = element_blank())
      
    }
    
  } else {
    
    "Uptake curve cannot be shown - no peptides were selected"
    
  }
  
}

```

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_kin_plot"]]){
  
  if (kin_valid) {
    
    cat("### Absolute values \n")
    
    p <- kin_plot_exp_abs()
    
    if (!input[["theory"]] & input[["calc_type"]]=="absolute"){
    
      p + 
        coord_cartesian(ylim = c(input[["kin_plot_y_range"]][[1]], input[["kin_plot_y_range"]][[2]])) +
        labs(title = input[["kin_plot_title"]], 
             x = input[["kin_plot_x_label"]],
             y = input[["kin_plot_y_label"]]) +
        theme(legend.position = "bottom",
              legend.title = element_blank())
      
    } else {
      
      p + 
        labs(title = "Uptake curve for chosen peptides",
             x = "Time points [min]",
             y = "Deuteration [Da]") +
        scale_y_continuous(limits = c(0, NA)) +
        theme(legend.position = "bottom",
              legend.title = element_blank())
    }
    
  }
  
}

```

<!--- KINETIC PLOT DATA --->

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_kin_plot_data"]]){
  
  cat("## Uptake curve Data \n")
  
  if (kin_valid){
    
    cat("### Relative values \n")
    
      if(has_modifications()){
        cat("Supplied file contains modified peptids. Maximal exchange control cannot be applied.")
      } else{
        if(input[["out_time"]] == 99999){
          cat(paste0("Chosen control: ", input[["chosen_control"]], "."))
        } else{
          cat("No chosen control. \n")
        }
      }
    
    kin_plot_exp_data()

  } else {
    
    "Uptake curve data cannot be shown - no peptides were selected"
    
  }

}

```

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_kin_plot_data"]]){
  
  if (kin_valid) {
    
    cat("### Absolute values \n")
  
    kin_plot_exp_abs_data()
  
  }
  
}

```

<!--- THEORETICAL KINETIC PLOT --->

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_theo_kin_plot"]]){
  
  cat("## Theoretical Uptake curve Data \n")
  
  if (kin_valid){
    
    cat("### Relative values \n")
    
    cat(paste0("Deuterium concentration: ", input[["deut_concentration"]], "%."))
    
    p <- kin_plot_theo()
    
    if(input[["theory"]] & input[["calc_type"]]=="relative"){
    
      p + 
        coord_cartesian(ylim = c(input[["kin_plot_y_range"]][[1]], input[["kin_plot_y_range"]][[2]])) +
        labs(title = input[["kin_plot_title"]], 
             x = input[["kin_plot_x_label"]],
             y = input[["kin_plot_y_label"]]) +
        theme(legend.position = "bottom",
              legend.title = element_blank())
      
    } else {
      
      p + 
        labs(title = "Theoretical uptake curve for chosen peptides",
             x = "Time points [min]",
             y = "Deuteration [%]") +
        scale_y_continuous(limits = c(0, 110)) + 
        theme(legend.position = "bottom",
              legend.title = element_blank())
        
    }
    
  } else {
    
    "Theoretical uptake curve plot cannot be shown - no peptides were selected"
    
  }

}

```

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_theo_kin_plot"]]){
  
  if (kin_valid) {
    
    cat("### Absolute values \n")
    
    p <- kin_plot_theo_abs()
    
    if(input[["theory"]] & input[["calc_type"]]=="absolute"){
    
      p + 
        coord_cartesian(ylim = c(input[["kin_plot_y_range"]][[1]], input[["kin_plot_y_range"]][[2]])) +
        labs(title = input[["kin_plot_title"]], 
             x = input[["kin_plot_x_label"]],
             y = input[["kin_plot_y_label"]]) +
        theme(legend.position = "bottom",
              legend.title = element_blank())
      
    } else {
      
      p + 
        labs(title = "Theoretical uptake curve for chosen peptides",
             x = "Time points [min]",
             y = "Deuteration [Da]") +
        scale_y_continuous(limits = c(0, NA)) +
        theme(legend.position = "bottom",
              legend.title = element_blank())
    }
    
  }
  
}

```

<!--- THEORETICAL KINETIC PLOT DATA --->

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_theo_kin_plot_data"]]){
  
  cat("## Theoretical uptake curve Data \n")
  
  if (kin_valid){
    
    cat("### Relative values \n")
    
    cat(paste0("Deuterium concentration: ", input[["deut_concentration"]], "%."))
  
    kin_plot_theo_data()
  
  } else {
    
    "Theoretical uptake curve data cannot be shown - no peptides were selected"
    
  }
  
}

```

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_theo_kin_plot_data"]]){
  
  if (kin_valid){
  
    cat("### Absolute values \n")
  
    kin_plot_theo_abs_data()
    
  }
  
}

```

<!--- QUALITY CONTROL PLOT --->

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_quality_control_plot"]]){
  
  cat("## Quality Control Plot \n")
  
  cat("Quality control plot is based purely on experimental values.")
  
  qc_out()
  
}

```

<!--- QUALITY CONTROL PLOT DATA --->

```{r echo = FALSE, results = "asis", warning = FALSE, message = FALSE}

if (input[["export_quality_control_plot_data"]]){
  
  cat("## Quality Control Plot Data \n")
  
  cat("Quality control plot data is based purely on experimental values.")
  
  quality_control_plot_data_out()
  
}

```


# R Session

```{r, echo=FALSE}

pander::pander(sessionInfo())

```
