---
title: "ProTeomiX (PTX) Quality Control (QC) Report"
output:
  html_document:
    mathjax: null
    number_sections: yes
    toc: yes
  pdf_document:
    toc: yes
---


<!-- the TOC (table of content) will go here - use 'toc: no' above to disable the TOC -->


<style type="text/css">
  p { 
    padding: 5px 0;
  }

  .helpSymbol {
    border: 1px solid #AAAAAA;
    padding: 3px;
    text-align: center;
    width: 100px;
  }
  .helpText {
    clear: left;
  }
  
  .tooltipPTXQC {
    position: relative;
    display: inline-block;
    border-bottom: 1px dotted black;
  }
  
  .tooltipPTXQC .tooltiptext {
    visibility: hidden;
    width: 120px;
    background-color: black;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 5px 0;
  
    /* Position the tooltip */
    position: absolute;
    z-index: 1;
  }
  
  .tooltipPTXQC:hover .tooltiptext {
    visibility: visible;
  }
</style>

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

<a name="Overview"></a>

# Overview

## Checks

<!-- locale static -->
<div style="color:#008800">
  <input type="checkbox" disabled="disabled" checked="checked"> MaxQuant had an english locale (dot as decimal separator; otherwise you would receive an error when generating the report)
</div>

<!-- locale dynamic -->
<div class="tooltipPTXQC" id="locale_short"><span id="locale_shorttext"></span> (hover here for details)
  
<div class="tooltiptext" style="width:700px; border: 4px solid #73AD21; margin: auto; padding: 5px;" id="locale_box">
<font size="+2">Dynamic (at this very point in time) check of <b>this</b> system's locale (region) settings</font><br>
    (independent of how the txt-folder for this report was generated!)
<div id="locale_check">
<p>Decimal separator: <span id="locale_decimal"></span></p>
<span id="locale_explanation"></span>
</div>
</div>
</div>


<script type="text/javascript">
 /**
   * Returns an object containing decimal and thousand separator
   * based on user's locale
   */
  function getNumberSeparators() {
    
    // default
    var res = {
      "decimal": "",
      "thousand": ""
    };
    
    // convert a number formatted according to locale
    var str = parseFloat(1234.56).toLocaleString();
    
    // if the resulting number does not contain previous number
    // (i.e. in some Arabic formats), return defaults
    if (!str.match("1"))
      return res;
    
    // get decimal and thousand separators
    res.decimal = str.replace(/.*4(.*)5.*/, "$1");
    res.thousand = str.replace(/.*1(.*)2.*/, "$1");
    
    // return results
    return res;
  }
  
  function checkString(str) {
    if (str === " ")
      return "[space]";
    else if(str === ".")
      return "[dot]"
    else if(str === ",")
      return "[comma]"
    else if(str === "")
      return "<error>"
    else
      return str;
  }
  
  /**
    * Running the locale function
    */
  var separators = getNumberSeparators();
  
  document.getElementById("locale_decimal").innerHTML = checkString(separators.decimal);
  
  var sep_MQ_ok = (separators.decimal == ".")
  
  var bg_col = (sep_MQ_ok ? 'lightgreen' : '#FA8072')
  var border_col = (sep_MQ_ok ? 'green' : 'red')
  var text_col = (sep_MQ_ok ? '#009900' : '#FF0000')
  document.getElementById( 'locale_box' ).style.backgroundColor = bg_col
  document.getElementById( 'locale_box' ).style.borderColor  = border_col
  document.getElementById( 'locale_short' ).style.color = text_col
  var explanatation = (sep_MQ_ok ? "<b>All good</b>: The decimal separator is '.' [dot], which would allow MaxQuant to run just fine on <b>this</b> system!" :
                                   "<b>Warning</b>: your decimal separator is NOT '.' [dot]!<br>Running MaxQuant on this system would lead to broken MaxQuant txt output files!")
  document.getElementById("locale_explanation").innerHTML = explanatation;
  var shorttext = (sep_MQ_ok ? '<input type="checkbox" disabled="disabled" checked="checked"> Dynamic locale check for <b>this</b> system is dot! (MaxQuant would run fine)' :
                               '<input type="checkbox" disabled="disabled"                  > Dynamic locale check for <b>this</b> system is <b>not</b> dot! (MaxQuant would fail)')
document.getElementById("locale_shorttext").innerHTML = shorttext;


</script>

**Quick guide**

  - navigate using the 'Table of Content' above or just scroll down
  - collapse sections by just clicking their name
  - click on the "&darr; Show Help" symbol to see a description for each metric and its scoring
  - edit the YAML config <a href="`r paste0("file:./", basename(rprt_fns$yaml_file))`">`r paste0("file:./", basename(rprt_fns$yaml_file))`</a> to
     - set the report format (HTML, plainPDF, or both)
     - disable metrics
     - customize the order of metrics
     - set individual target thresholds
  - edit `r paste0("file:./", basename(rprt_fns$filename_sorting))` to customize
     - the order of Raw files in plots and heatmap
     - abbreviations of Raw file names
  - edit the Html template `r paste0("file:./", basename(html_template))` to
     - alter the look and feel of this report (e.g. colors, font and image sizes, help texts, etc.)
  - report bugs and file requests via the [GitHub issue tracker](https://github.com/cbielow/PTXQC/issues)
  - full PTXQC manual available [here](https://github.com/cbielow/PTXQC)


## HeatMap
```{r MQparams, echo=FALSE, results="asis"}
hm[["plot"]]
```

## Name Mapping
```{r nameMapping, echo=FALSE, results="asis"}
if(!is.null(pl_nameMapping) && (!any(is.na(pl_nameMapping)))) {
  cat(pl_nameMapping$htmlTable)
}
```


## Metrics
```{r metrics, echo=FALSE, results="asis"}
  #for (qcm in lst_qcMetrics[1:3])
  for (qcm in lst_qcMetrics)
  {
    if (length(qcm$plots) == 0) next; # skip empty metrics
    #debug: 
    #cat(c("processing ", qcm$qcName))
    v_titles = qcm$getTitles(subtitle_sep = "\n<b>")
    plots = qcm$getPlots(withTitle = FALSE)
    if (length(v_titles) != length(plots)) {
      ## this is weird...
      stop("Number of titles is unequal to number of plots ...")
    }
    last_title = ""
    for (i in 1:length(v_titles))
    {
      if (last_title != v_titles[i]) {  ## print only new titles
        cat(paste0("\n\n### ", gsub("\n", "\n<br>", v_titles[i]), "</b>\n\n"))
      }
      if (i == 1) { ## print helpText only once
        cat(paste0('\n
<div>
  <div class="helpSymbol">&darr; Show Help</div>
  <div class="helpText">', qcm$helpText, "</div>
</div>"))
      }
      if (!is.na(qcm$htmlTable))
      { ## if there is an HTML table, prefer it over the plots
        cat(qcm$htmlTable)
        break;
      }
      print(plots[[i]])
      cat("\n<br>\n")
      last_title = v_titles[i]
    }
    cat('\n<p style="text-align: right">[back to top](#Overview)</p>\n\n')
  }
```



<script type="text/javascript">
jQuery(document).ready(function()
{
 // initially hide the help text
  jQuery(".helpText").hide();
  
  // toggle help text by clicking on the symbol
  jQuery(".helpSymbol").click(function(event)
  {
    var target = $( event.target );
    // "Show Help &darr;" is the first item in a <div> which encloses their section
    // so toggling its sibling (the actual text) will just leave the "Show Help &darr;" visible
    if ( target.is( "div" ) )
    {
      target.siblings().slideToggle(200);
      event.stopPropagation()
    }
  });
  
  
  // enable shortening the report
  jQuery(".section").click(function(event)
  {
    var target = $( event.target );
    // headings are the first item in a <div> which encloses their section
    // so toggling their siblings will just leave the heading visible
    if ( target.is( "h1, h2, h3, h4" ) )
    {
      target.siblings().slideToggle(200);
      event.stopPropagation()
    }
  });
});

</script>








