---
title: "MQmetrics Report"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output: pdf_document
params:
  input_dir: ''
  remove_contaminants: ''
  log_base: ''
  long_names: ''
  sep_names: ''
  intensity_type: ''
  palette: ''
  UniprotID: ''
  segment_width: ''
  show_shade: ''
  percent_proteins: ''
  show_calibrated_rt: ''
  tolerance: ''
  show_max_value: ''
  peptides_modified: ''
  show_median: ''
  size_median: ''
  binwidth: ''
  plot_unmodified_peptides: ''
  plots_per_page: ''
---

```{r setup, include=FALSE}
## global options
knitr::opts_chunk$set(echo=FALSE,
                      warning=FALSE,
                      error=TRUE,
                      message=FALSE, 
                      fig.height = 12,
                      fig.width = 10)
```

```{r library}
library(MQmetrics)
MQPathCombined <- params$input_dir
MQCombined <- make_MQCombined(MQPathCombined,
                              remove_contaminants = params$remove_contaminants) 
```



```{r ExperimentDuration}
MaxQuantAnalysisInfo(MQCombined) 
```

\newpage

```{r PlotProteins}
PlotProteinsIdentified(MQCombined,
                       intensity_type =params$intensity_type,
                       long_names = params$long_names, 
                       sep_names = params$sep_names, 
                       palette = params$palette)
```

\newpage
```{r protein_coverage_all}
PlotProteinOverlap(MQCombined)

```

\newpage
```{r PeptidesIdentified}
PlotPeptidesIdentified(MQCombined, 
                       long_names = params$long_names, 
                       sep_names = params$sep_names, 
                       palette = params$palette)
```

\newpage
```{r ratio}
PlotProteinPeptideRatio(MQCombined,
                        intensity_type = params$intensity_type, 
                        long_names = params$long_names, 
                        sep_names = params$sep_names)
```


\newpage
```{r PlotMSMS}
PlotMsMs(MQCombined,
         long_names = params$long_names, 
         sep_names = params$sep_names, 
         palette = params$palette)
```


\newpage
```{r PlotPeaks}
PlotPeaks(MQCombined, 
          long_names = params$long_names, 
          sep_names = params$sep_names, 
          palette = params$palette)
```


\newpage
```{r isotope}
PlotIsotopePattern(MQCombined,
                   long_names = params$long_names, 
                   sep_names = params$sep_names, 
                   palette = params$palette)
```


\newpage
```{r Charge}
PlotCharge(MQCombined, 
           palette = params$palette,
           plots_per_page = params$plots_per_page)
```

\newpage
```{r missed_cleavages}
PlotProteaseSpecificity(MQCombined, 
                        palette = params$palette,
                        plots_per_page = params$plots_per_page)
```


\newpage
```{r PlotHydrophobicity}
PlotHydrophobicity(MQCombined,
                   palette = params$palette,
                   show_median =  params$show_median,
                   size_median = params$size_median,
                   binwidth = params$binwidth,
                   plots_per_page = params$plots_per_page)
```

\newpage
```{r PlotAndromedaScore}
PlotAndromedaScore(MQCombined, 
                   palette = params$palette,
                   plots_per_page = params$plots_per_page)
```


\newpage
```{r IdentificationType}
if(MQCombined$parameters.txt$Value[
    MQCombined$parameters.txt$Parameter == 'Match between runs'] == 'True'){
    PlotIdentificationType(MQCombined,
                           palette = params$palette,
                           long_names = params$long_names, 
                           sep_names = params$sep_names)  
} else{
    cat('Match Between Runs was not used during the MaxQuant analysis.
        No Identification Type to show.')
}
```



\newpage
```{r PlotIntensity}
PlotIntensity(MQCombined, 
              intensity_type = params$intensity_type, 
              log_base = params$log_base, 
              long_names = params$long_names, 
              sep_names = params$sep_names,
              palette = params$palette)
```
\newpage

```{r PlotPCA}
PlotPCA(MQCombined,
        intensity_type = params$intensity_type,
        palette = params$palette)
```

\newpage
```{r DynamicRange}
PlotCombinedDynamicRange(MQCombined,
                         show_shade = params$show_shade, 
                         percent_proteins = params$percent_proteins) 
```
\newpage
```{r DynamicRangeAll}
PlotAllDynamicRange(MQCombined,
                    show_shade = params$show_shade, 
                    percent_proteins = params$percent_proteins)
```

\newpage

```{r ProteinCoverage}
if(is.null(params$UniprotID)){
    print('No UniprotID provided.')
} else{
    PlotProteinCoverage(MQCombined, 
                        UniprotID = params$UniprotID, 
                        log_base = params$log_base,
                        segment_width = params$segment_width,
                        palette = params$palette,
                        plots_per_page = params$plots_per_page)
}
```



\newpage
```{r irt_peps1}
PlotiRT(MQCombined, 
        show_calibrated_rt = params$show_calibrated_rt,
        tolerance =  params$tolerance)
```
\newpage

```{r irt_peps2}
PlotiRTScore(MQCombined,
             tolerance =  params$tolerance)
```



\newpage
```{r TotalIonCurrent}
PlotTotalIonCurrent(MQCombined,
                    show_max_value = params$show_max_value,
                    palette = params$palette,
                    plots_per_page = params$plots_per_page)
```


\newpage
```{r PlotAcquisition}
PlotAcquisitionCycle(MQCombined, 
                     palette = params$palette,
                     plots_per_page = params$plots_per_page)
```

\newpage
```{r PTM}
PlotPTM(MQCombined, 
        peptides_modified = params$peptides_modified,
        log_base = params$log_base,
        plot_unmodified_peptides = params$plot_unmodified_peptides,
        palette = params$palette,
        plots_per_page = params$plots_per_page)
```

\newpage
```{r, echo=FALSE, message=FALSE, warning=FALSE}
a <- ReportTables(MQCombined,
                  log_base = params$log_base,
                  intensity_type = params$intensity_type,
                  long_names = params$long_names, 
                  sep_names = params$sep_names)


kable(a[[1]], caption = 'Protein Information')
kable(a[[2]], caption =  paste0('Information of: Log',
                                params$log_base,
                                ' ',
                                params$intensity_type))   
kable(a[[3]], caption = 'Charge Information')
kable(a[[4]], caption = 'Peptide hydrophobicity (GRAVY)')
kable(a[[5]], caption = 'Missed Enzymatic Cleavages')
kable(a[[6]], caption = 'Protein Identification Overlap Between Samples')

```
