#import "template.typ": *
#import "@preview/fletcher:0.5.8" as fletcher: diagram, node, edge
#import fletcher.shapes: diamond, brace, cylinder
#import "@preview/clean-cnam-template:1.2.0": *
#import "@preview/proteograph:0.2.2": *


#show: clean-cnam-template.with(
  title: "Spoms documentation",
  subtitle: "PeptidOMS-ANR-24-CE45-3296",
  author: "Olivier Langella",
  class: "technical documentation",
  affiliation: "PAPPSO",
  //logo: image("./assets/cnam_logo.svg"),
  start-date: datetime(day: 11, month: 7, year: 2025),
  main-color: navy,
  default-font: "New Computer Modern Math",
  code-font: "Andale Mono",
  outline-code: outline(
    title: "Table of content",
    depth: 2,
    indent: auto,
  ),
)

#set text(lang: "en")
#set heading(numbering: "1.1")



#let peptidoms = "PeptidOMS"
#let protein-matcher = "ProteinMatcher"
#let specglobtool = "SpecGlobTool"
#let specoms = "SpecOMS"
#let spoms = "Spoms"

= Introduction

#spoms aligns MS2 fragmentation spectra directly to protein sequences.
Algorithm is described in @benoist_specpeptidoms_2025.

= Source code

Current source code is available at #link("https://forge.inrae.fr/peptidoms/specpeptidoms","https://forge.inrae.fr/peptidoms/specpeptidoms").


= PSM CBOR file workflow

#set text(10pt)
#diagram(
	node-stroke: .1em,
	node-fill: gradient.radial(blue.lighten(80%), blue, center: (30%, 20%), radius: 80%),
	spacing: 4em,
	node((-1,0.5), `fasta file`, shape: diamond, fill: none, name: <fastafile>),
	node((-1,-0.5), `mzML file`, shape: diamond, fill: none, name: <mzmlfile>),
	node((0,0), `peptidoms`, radius: 3em, name: <peptidoms>),
	edge(``, "-|>"),
	node((1,0), `PSM cbor file`, shape: diamond, fill: none, name: <peptidomscbor>),
	edge(``, "-|>"),
	node((2,0), `psmfeatures`, radius: 3em),
	edge(``, "-|>"),
	node((3,0), `ODS export`, radius: 2em),
	node((2,1), `deeplc mumble`, radius: 2em, name: <deeplc>),
	edge(<peptidomscbor>, <deeplc>, ``, "-|>"),
	edge(<fastafile>,<peptidoms.west>, "-|>", bend: 20deg),
	edge(<mzmlfile>,<peptidoms.west>, "-|>", bend: -20deg),
)


= Command line interface

#spoms works on a collection of MS/MS spectra (mzML file typically) and a protein sequence database (FASTA file) and produces a PSM CBOR file as output.

#code-block("spoms -p params.json -m mzdata.mzml -f protein_sequences.fasta -o results.cbor", "bash")

To get a readable file results, use "spoms-export" to produce JSON or ODS files:

#code-block("spoms-export -i results.cbor --ods results.ods", "bash")

#code-block("spoms-export -i results.cbor --json results.json", "bash")





= JSON parameter file

#spoms parameters are specified in a JSON file

#let code_psm = read("json/spoms_parameters.json")
#code-block(code_psm, "json", title: "JSON parameter file")

== #raw("spectrum") section

/ #raw("fragment_tolerance_unit"): *string* "dalton" by default
/ #raw("fragment_tolerance"): *float* mass delta precision (0.02 dalton by default)
/ #raw("deisotope"): *boolean* if true, process spectrum to merge isotopes into single charge peaks
/ #raw("minimum_mz"): *float* minimum #mz ratio to consider peaks in the spectrum
/ #raw("n_most_intense"): *int* consider only the N most intense peaks in the spectrum


= CBOR peptidoms eval PSM structure

#spoms writes results in a PSM CBOR file.
For each PSM, #spoms uses the "eval" section to store its scores :

#let code_psm = read("json/spoms_psm_eval.json")
#code-block(code_psm, "json", title: "spoms PSM eval structure")



= Tests for #spoms


#code-block("./src/spoms -p ../doc/typst/json/spoms_parameters.json -f /gorgone/pappso/moulon/database/Genome_Z_mays_5a.fasta -m /gorgone/pappso/data_extraction_pappso/mzML/20120906_balliau_extract_1_A01_urnb-1.mzML -o /tmp/test.cbor -c 10", "bash")
#code-block("./src/spoms -p ../doc/typst/json/spoms_parameters.json -f /gorgone/pappso/moulon/database/Genome_Z_mays_5a.fasta -m /gorgone/pappso/data_extraction_pappso/mzcbor/20120906_balliau_extract_1_A01_urnb-1.mzcbor -o /tmp/test.cbor -c 10", "bash")

```bash
Process for spectrum index 2406 finished. Slowest one is 2287 2290
total 236
```

== Smaller dataset


#code-block("./src/spoms -p ../doc/typst/json/spoms_parameters_test.json -f ../tests/data/fasta/small_zea_mays.fasta -m ../tests/data/peaklists/peaklist_15046.mgf -o /tmp/test.cbor", "bash")



#code-block("./src/spoms -p ../tests/data/parameters/DATNVGDEGGFAPNIIENK_parameters.json -f ../tests/data/fasta/databankThreeProteinsHuman.fasta -m ../tests/data/peaklists/DATNVGDEGGFAPNIIENK.mgf -o DATNVGDEGGFAPNIIENK.cbor -c 10", "bash")



#bibliography(style:"frontiers", "bibliography.bib")
