##
## when you see {{ something }} in a string, this means the string is
## a template, and the "{{ something }}" will be replaced by its value
## at runtime.
## This is usefull to build strings from other strings.
## to reference an item in a tree, you can use dots as branches:
##  {{ parameters.flags.help }}
## will be extrapolated to "Show this help"
## 
## But beware:
##  {{ parameters.mandatory }}
## will be extrapolated to
##  "{'input': 'input file path'}"
##

## this config is used for debug.
## it allows to define debug options before everything else is parsed
__meta_config__:
  __debug__: False
  __debug_stream__: stderr
  __only_root_debug__: False


## the cli parameters
parameters:
  mandatory:
    ## input is mandatory
    input: input file path
  flags:
    ## help, verbose and version can be provided with no parameter.
    help: Show this help
    verbose: More verbose outputs
    version: Show this tool's version
    debug: show debug outputs
    do_run_dry: Runs the whole process, without the server. Usefull for tests.
    embed_js: Embed js in html file instead of using a separated js file.
    firefox: Open firefox on the web page.
    chromium: Open chromium or chrome on the web page.
  optional:
    ## these optional parameters need a value "--opt value --opt2 value2"
    method: "default is {{ defaults.method }}"
    spectrum_type: "default is {{ defaults.spectrum_type }}"
    sample_type: "default is {{ defaults.sample_type }}"
    resolution: "default is {{ defaults.resolution }}"
    resolution: "default is {{ defaults.resolution }}"
    name: The precursor name
    peakforest.url: "default={{ defaults.peakforest.url }}"
    peakforest.token: The token to comunicate with peakforest api
    polarity: positive|negative
    raw_metadata: example - 1-1__INCHIKEY__=QNAYBMKLOCPYGJ-REOHCLBHSA-N_L-Alanine_MS_POS_plasma_RT__=0.84_filtree.csv
    scan_type: ms|msms|rmn
    run_dry_html: when "--run-dry", provides the output directory for {{ generated.html }}
    run_dry_js: when "--run-dry", provides the output directory for {{ generated.js }}
    raw_metadata_sep: "raw metadata separator"
    logging.std: "Either out, err, or anything else to not output"
    logging.file.path: "The file path to output logs to"
    validation: "Set the default validation to the provided value, TRUE or FALSE."
    output_json: "Provide a path to output a JSON file."
  meta:
    ## meta info about the tool itself
    author: Lain Pavot
    version: 1.1.0
  shortcuts:
    ## to define things like: "we can use -p instead of --polarity"
    peakforest.token: t
    polarity: p
    help: h
    version: v
    verbose: V
    debug: d
    logging.std: l

## some default parameters
## logging defines two elements: std and file.
## std should be either empty, err or out.
## it tells where to outputs logs:
##   - nowhere (empty value)
##   - in sterr (err)
##   - in stdout (out)
## and file. Id a path is provided, add outputs to this file.
## if append is true, outputs are appended to the file.
## otherwise, the file is emptied each time the app runs.
defaults:
  peakforest:
    url: https://nightly.peakforest.org
    token: ''
  spectrum_type: LC_MSMS
  method: cf_pfem_urine_method1_qtof-msms
    # api-msms-fia__idf-cea
    # cf_pfem_plasma_method1_qtof-msms
    # cf_pfem_urine_method1_qtof-msms
    # lc-msms__test
  scan_type: ms2
  resolution: high
  sample_type: compound-ref
  # sample_type: compound-mix
  polarity: positive
  raw_metadata: ''
  name: ''
  run_dry_html:
  run_dry_js:
  raw_metadata_sep: ','
  validation: "TRUE"
  verbose: false
  debug: true
  logging: 
    std: out ## out || err
    file: 
      path:
      append: False
  output_json: ''

## token related info
token:
  ## do you use a file to store your token?
  use_file: false
  ## if so, what path the file is located at?
  file_path: .token
  ## if not, you can provide you token here
  value:

network:
  ip: 0.0.0.0
  port: 8000

workdir:
  ## create a tmp directory
  create_tmp: true
  ## works in the created tmp directory, or if not created, in /tmp
  work_in_tmp: true
  ## generate outputs in the created tmp directory, or if not created, in /tmp
  generate_in_tmp: true

## the templates paths
templates:
  ## meta is what wrapps the whole page.
  main: meta.html
  main_mix: meta-compound-mix.html
  main_ref: meta-compound-ref.html
  ## form is one instance of a pf form
  # form: form.html
  # form: compound-ref.html
  form: form.html
  form_mix: compound-mix.html
  form_ref: compound-ref.html
  ## one item of the tab list
  tab_list: tab_list.html
  ## the js for one form
  js: add-one-spectrum-index.js
  ## placeholders for the html templates.
  ## this will not change the placeholders syntax for this file.
  placeholders:
    start: "{{ "
    stop: " }}"

generated:
  ## what filename to give to the whole html file
  html: pf.html
  ## what filename to give to js files
  js: add-one-spectrum-{{ index }}.js

regex:
  values:
    ## reuse these smol regex in bigger regex!
    spectrum_type: "NMR|LC_MS|LC_MSMS|MRM(_\\d+)?"
    matrix: "[Uu]rine|[Pp]lasma|[Pp]las"
    mode: "POS|NEG"
    energy: "\\d+ev"
    pool: "[Pp]ool\\d+"
    rt: "\\d+\\.\\d+"
    runs: "\\d+-\\d+"
    inchikey: "[A-Z]{14}-[A-Z]{10}-[A-Z]"

  ## the "INCHIKEY" word
  ## one or more underscores
  ## may be followed by a equal sign
  ## captures in the "inchikey" variable:
  ##    14, 10 and 1 letters
  ##    in caps
  ##    separated by a hyphen
  inchikey: "INCHIKEY_+=?(?P<inchikey>{{ regex.values.inchikey }})"

  ## method is one of values defined bellow, between underscores
  spectrum_type: "_(?P<method>{{ regex.values.method }})_"

  ## matrix is one of values defined bellow, between underscores
  matrix: "_(?P<matrix>{{ regex.values.matrix }})_"

  ## pool is one of values defined bellow, between underscores
  pool: "_(?P<pool>{{ regex.values.pool }})_"

  ## molecule everything between inchikey and method.
  molecule: "{{ regex.inchikey }}_(?P<molecule>.*?){{ regex.method }}"

  ## mode is one of values defined bellow, between underscores
  mode: "_(?P<mode>{{ regex.values.mode }})_"

  ## energy is one of values defined bellow, between underscores
  energy: "_(?P<energy>{{ regex.values.energy }})_"

  ##  - A underscore,
  ##  - the "RT" word,
  ##  - some underscore(s),
  ##  - an optional interrogation mark,
  ##  - the actual RT value is captured here,
  ##  - there is a underscore at the end
  rt: "_RT_+=?(?P<rt>{{ regex.values.rt }})_"

  ## "runs" is at the beginning, and ends with an underscore.
  runs: "^(?P<runs>{{ regex.values.runs }})_"


  ## BEGIN
  ## anything
  ## the inchikey
  ## anything else can follow
  ## END
  # fragnot: ^.*{{ regex.inchikey }}.*$


  ## This is the most exhaustive regex I came with to extract info from
  ## fragnot files name.
  # fragnot:
  #   ^
  #   .*                                (?# there may be anything at the begining)
  #   (?P<runs>\d+-\d+)                 (?# the run numbers)
  #   _+                                (?# followed by anything - underscores usualy)
  #   INCHIKEY_+=?(?P<inchikey>{{ regex.inchikey }})              (?# we insert inchikey regex here - see above)
  #   _+                                (?# there is one or more underscores)
  #   (?P<molecule>.*?)                 (?# the molecule name follows the inchikey)
  #   _+                                (?# there is one or more underscores)
  #   (?P<method>{{ regex.method }})    (?# then, there is the method - nmr, ms or mrm???)
  #   _+                                (?# there may be some underscores to separate)
  #   (?P<matrix>{{ regex.matrix }})?   (?# the matrix - urine or plasma)
  #   _*                                (?# there may be some underscores to separate)
  #   (?P<mode>POS|NEG)                 (?# the acq mode - pos or neg)
  #   _+                                (?# there may be some underscores to separate)
  #   (?P<pool>{{ regex.pool }})?       (?# the pool - "Pool"+numbers, optional)
  #   _*                                (?# there may be some underscores to separate)
  #   (?P<energy>\d+ev)?                (?# the energy - only for nmr, so it's optional)
  #   _*                                (?# there may be some underscores to separate)
  #   (?P<pool2>{{ regex.pool }})?      (?# the pool - sometimes the pool if *after* the energy...)
  #   _*                                (?# there may be some underscores to separate)
  #   (?P<matrix2>{{ regex.matrix }})?  (?# the matrix is here, sometimes)
  #   _*                                (?# there may be anything here)
  #   RT_+=?(?P<rt>\d+\.\d+)            (?# the retension time is a decimal number)
  #   _*                                (?# there may be anything at the end)
  #   (?P<filtered>[fF]iltree)?         (?# sometimes, "Filtree" appears, lets capture it)
  #   \.[ct]sv                          (?# the extension)
  #   $