Skip to content

How rules-driven conversion works

APB2 uses a rules.json document for each vendor rule variant. Each document has a nonempty tables list. A table declares its input and levels, including observation and feature keys, axis columns, measurement layers and semantic roles. Most new layouts fit in a table declaration.

APB2 accepts schema 0.11. The document schema describes the authored document and its physical inputs. APB2 validates each rule against the effective-rule schema after composing the table's base and level. A document of an older schema is refused; APB2 has no migration tool. Document schema · Effective-rule schema

One software, multiple input tables

Software metadata belongs at the document root. Each tables entry contains input, base, levels, and optionally prepare, for example {"how": "maxquant_wide"}. The registered how values are alphadia, maxquant_wide, maxquant_evidence, metamorpheus, msangel, mztab and wombat. A document can contain both direct and prepared groups. Shared declarations merge within their table, and each level belongs to one group. Prepared tables leave input.sheet_name, input.encoding, input.delimiter and input.numbers unset because the preparation selects the reader.

MaxQuant's document has two groups, one for evidence at run resolution and one for joined exports at experiment resolution. MaxQuant rules

Input file Shape Level
evidence.txt long peptidoform_ion
modificationSpecificPeptides.txt wide peptidoform
peptides.txt wide peptide
proteinGroups.txt wide protein

join_wide accepts any nonempty subset of the three higher-level exports and resolves their foreign keys through shared evidence IDs. It reads the declared columns plus id and Evidence IDs. The joined table has one row per related feature-ID tuple, with experiment columns side by side. Row count therefore scales with the relationships. All three levels inherit the Experiment observation key from their group's base and capture it from headers such as peptide.Intensity <experiment>. Each level sets its shared prefix once, for example "source_prefix": "peptide.". An entry from another table declares its own prefix. The same repeated-cell policy keeps identical quantities from repeated relationships and rejects disagreements.

join_evidence keeps every evidence row and adds the Protein IDs of the group that contains the row's leading razor protein. It looks up the group among the row's Protein group IDs. The ion rule calls that output Protein_IDs, the same name as the protein level's key. It uses Raw_file for observations, keeps Experiment and Fraction as metadata, and ranks repeated cells by PEP with keep_best. APB2 supports all 15 nonempty subsets of the four files. MaxQuant preparation

The AlphaDIA 1.12 hook adds precursor metadata to matrix intensities and returns long rows. The compiler prepares each requested group once. Each level then projects from the shared frame and excludes rows with wholly absent identities before decomposition. The hook is independent of rule validation and parser orchestration. After parsing, APB2 aligns observation axes when it finds an explicit bijection and writes incompatible axes separately. AlphaDIA preparation · Output naming

The MetaMorpheus hook keeps FlashLFQ peaks mapped to exactly one peptidoform and drops random-RT match-between-runs peaks, which carry their target's identity. It casts Peak intensity to a number. The rule uses keep_best to take the highest-intensity peak's values for each ion and run. Decoy peptides are kept and marked apb_Decoy. MetaMorpheus preparation

The WOMBAT-P hook drops and counts ambiguous FlashLFQ peaks whose modified_peptide names several peptides, such as SEQA|SEQB. Preparation reads .csv with commas and other delimited tables with tabs. Workbook hooks name the sheets to read. WOMBAT-P preparation

The MSAngel hook reads "Protein sets" and "Quantified peptide ions" as text and joins them on protein_set_id. The ion sheet lists shared peptides once per protein set. The ion rule keeps the best-scoring set with "rank_rows": {"by": "protein_set_score", "best": "highest"} and "per_feature": "best_row". The same row supplies the ion's quantities and its samesets_accessions for protein_assignment. The Proteins column supplies fasta_accessions. The protein rule uses samesets_accessions as its key and reads each set's own columns. With only the ion sheet, APB2 converts the ion level. MSAngel preparation

Use an explicit rule document with "prepare": {"how": "mztab"} for mzTab input. The reader binds the file from its metadata and first section header. It turns each section with per-sample values into long rows for its sample axes (assay, ms_run or study_variable), resolves sample references from metadata, and stacks the tables. A level selects its own section and sample axis through its keys, for example PRT.accession and assay. The reader rejects pre-1.0 files with a unit_id column and files with no per-sample values. Explicit rule document · mzTab reader

Column evidence without a parameter file

With --software alone, APB2 can use input.without_parameter_file to distinguish rule variants that otherwise accept the same header. Its required_columns and forbidden_columns apply only to this route. For example, DIA-NN 1.8/1.9 looks for PG.Normalised and Lib.PG.Q.Value, and 2.x looks for PG.TopN. When supplied, parameter files provide the parsed software version. Repeat --params for a tool that takes two files, such as the versions YAML and Nextflow params JSON from quantms.

acquisition_method.DDA_if_any_column lists the headers that establish DDA. otherwise gives the fallback. Set it to unknown when the header cannot establish the method. DIA-NN 2.x uses Ms1.Q.Value or Global.Ms1.Q.Value for DDA and falls back to DIA. Validate that signature against supported exports before declaring a fallback. An unresolved setting such as Sage's charge combination raises an error.

A level's forbidden columns

WOMBAT-P ion tables carry all the columns the peptidoform level needs, plus charge. The peptidoform rule lists charge in forbidden_columns so ProteoBench's ion tables convert at the ion level.

"peptidoform": {
  "forbidden_columns": ["charge"],
  "axis": {"var_keys": ["ProForma_peptidoform"]},
  ...
}
  • A match excludes that level. Other levels can still use the table. In WOMBAT-P, tables with charge convert as ions and tables without it convert as peptidoforms
  • Use the literal header the level reads, including any prefix already present in a prepared header such as evidence.Charge
  • Declare the field on the level and list only columns outside its source projection. Omit it when the level has no forbidden columns
  • This check applies whether or not the caller supplies a parameter file. The table-wide input.without_parameter_file.forbidden_columns instead distinguishes rule variants on the parameter-free route

Conversion preserves the hierarchy level reported by the input. Aggregation is a separate operation.

Long format

In a long table, every row holds one observation-variable measurement.

long.tsv
protein sample  Intensity
P1  a   10
P1  b   11
P2  a   20
P2  b   21
rules.json
{
  "schema_version": "0.11",
  "file_version": "1",
  "software_name": "MinimalLongExample",
  "software_version_pattern": "^1$",
  "hierarchy": "lfq",
  "parameter_file": "required",
  "tables": [
    {
      "input": {"shape": "long", "extensions": [".tsv"]},
      "base": {
        "defaults": {
          "var": {"type": "string", "required": true, "per_feature": "first"},
          "obs": {"type": "string", "required": true},
          "layers": {"encoding_mode": "numeric", "type": "number", "required": false}
        }
      },
      "levels": {
        "protein": {
          "axis": {"obs_keys": ["sample"], "var_keys": ["protein"]},
          "measurements": {
            "primary_layer": "Intensity",
            "repeated_cells": {"mode": "error"},
            "layers": [{"name": "Intensity", "source": "Intensity", "roles": ["abundance"]}]
          },
          "columns": {
            "obs": [{"name": "sample", "source": "sample"}],
            "var": [
              {
                "name": "protein",
                "source": "protein",
                "roles": ["protein_assignment", "fasta_accessions"]
              },
              {"name": "apb_Decoy", "how": "unmarked"},
              {"name": "apb_Contaminant", "how": "unmarked"}
            ]
          }
        }
      }
    }
  ]
}

hierarchy selects the hierarchy that contains every declared level. The lfq hierarchy runs from peptidoform_fragment through protein to gene. It identifies protein and gene features through protein_assignment and gene_assignment, respectively. Use psm for PSM tables and ptm_site for modification-site tables. Hierarchy definitions

Convert it with:

apb2 convert long.tsv protein --rule-config rules.json --output long

Wide format

In a wide table, every row holds one variable and observations are spread across measurement columns. A layer source therefore names a column per sample: {sample} marks where the header names its sample.

wide.tsv
protein Intensity_a Intensity_b
P1  10  11
P2  20  21
rules.json
{
  "schema_version": "0.11",
  "file_version": "1",
  "software_name": "MinimalWideExample",
  "software_version_pattern": "^1$",
  "hierarchy": "lfq",
  "parameter_file": "required",
  "tables": [
    {
      "input": {"shape": "wide", "extensions": [".tsv"]},
      "base": {
        "defaults": {
          "var": {"type": "string", "required": true, "per_feature": "first"},
          "layers": {"encoding_mode": "numeric", "type": "number", "required": false}
        },
        "sample_pattern": "(?P<sample>.+)"
      },
      "levels": {
        "protein": {
          "axis": {"obs_keys": ["sample"], "var_keys": ["protein"]},
          "measurements": {
            "primary_layer": "Intensity",
            "repeated_cells": {"mode": "error"},
            "layers": [
              {"name": "Intensity", "source": "Intensity_{sample}", "roles": ["abundance"]}
            ]
          },
          "columns": {
            "var": [
              {
                "name": "protein",
                "source": "protein",
                "roles": ["protein_assignment", "fasta_accessions"]
              },
              {"name": "apb_Decoy", "how": "unmarked"},
              {"name": "apb_Contaminant", "how": "unmarked"}
            ]
          }
        }
      }
    }
  ]
}

The source matches both measurement headers and captures a and b as observation keys. Long and wide inputs produce the same observations-by-variables result contract.

The text around {sample} matches literally, with source_prefix prepended. Define sample_pattern as a regular expression with a sample capture group. A level can override its base's pattern. Use (?P<sample>.+) for a plain sample name. PEAKS also accepts an optional file suffix.

"sample_pattern": "(?P<sample>.+?)(?:\\.raw|_raw)?"

Use a regular expression with a sample group for headers such as Sage's file-name columns that lack fixed text. With source_prefix, start the expression with ^ so composition can insert the literal prefix. The stored rule_json holds the effective regular expressions.

By default, the primary layer's captures define the sample names. Other layers keep columns that match those names. Set measurements.sample_layer when the primary pattern also matches columns such as group averages. PEAKS uses the required per-run m_z layer to define samples from <run> m/z headers and exclude group averages such as A Normalized Area. Long rules use columns.obs to define observations.

Table defaults

Each table declares its column and layer defaults once in base.defaults.

"defaults": {
  "var": {"type": "string", "required": true, "per_feature": "first"},
  "obs": {"type": "string", "required": true},
  "layers": {"encoding_mode": "numeric", "type": "number", "required": false}
}
  • Declare every defaults field for the table's shape. Include obs for long tables
  • Choose the defaults for each table. MaxQuant's two tables make var columns optional because most of their columns are optional
  • An entry writes a value only where it differs from its table's, such as "required": false on an optional column
  • A var column can declare missing text, such as "missing_tokens": ["NaN"] for MaxQuant's Score. APB2 handles it as missing before interpreting the value, as it does for layers
  • Factor layers take encoding_mode and required. The numeric type applies to numeric layers
  • Composition sets required to true for the effective primary layer, sample layer and keep_best ranking layer. Leave required unset on those entries. A search-parameter override changes which layer is the required primary
  • Computed entries use their computation fields in place of column defaults
  • The stored rule_json expands defaults onto each applicable entry

required: true excludes the level when a source column is missing. An absent optional source is left out with computations that depend on it. Computations such as coalesce and join_nonempty can use their available inputs.

Write each choice where it applies. Put hierarchy and parameter_file at the top, and declare measurements.repeated_cells.mode with by and best for keep_best. Also declare rank_rows.best, the sequence computation's case_sensitive and unknown_policy, and the syntax settings token_position, delimiter and site_base as applicable. Omit fixed fields and unused optional fields such as note, roles or missing_values.

Column entries

columns.obs and columns.var are ordered lists. Every physical column entry carries its own facts:

  • name: logical output name
  • source: physical vendor column
  • required and type inherit the table's defaults unless specified. Types are string, integer, number and boolean
  • roles states what the entry represents
  • note records a reason for the declaration or source interpretation. Parsing ignores it. Layers and computed entries also accept notes
  • version is a regex searched against the software version, like software_version_pattern. Omit it for a source used across all versions. Layers on long tables also accept it. Columns that differ by version
  • per_feature applies to var columns and inherits the table's default unless specified. first keeps the first nonblank value and records var_disagreements. min and max select the numerical extreme, for example to avoid a placeholder repeated on some rows. best_row uses the row chosen by rank_rows

Declare rank_rows once per level beside columns. Set by to the required numeric var column and best to highest or lowest. APB2 selects the winning row before building the feature table and layers, so they describe the same feature assignment, such as a shared peptide's protein set. For a long table, that assignment determines which rows to keep across runs.

Put experiment-wide feature values in columns.var, even when a long report repeats them in every run. Use a layer for values that vary by run and feature. DIA-NN's experiment-wide protein-group q-value is a var column with a 1.0 placeholder on precursors without a global q-value.

{
  "name": "Global_PG_Q_Value",
  "source": "Global.PG.Q.Value",
  "type": "number",
  "required": false,
  "per_feature": "min",
  "note": "Experiment-wide; DIA-NN writes 1.0 in rows of precursors without one, so the smallest value is the group's"
}

Use how and inputs for computed entries and place them after the entries they read. The computation determines the output type. When a computed entry also declares its own source, that source is required. FragPipe's Protein does this before joining with Mapped_Proteins.

"obs": [
  {"name": "R_Label", "source": "R.Label", "required": false},
  {"name": "R_FileName", "source": "R.FileName", "required": false},
  {"name": "Run", "how": "coalesce", "inputs": ["R_Label", "R_FileName"]}
]

Supported computations are coalesce, join_nonempty, stripped_sequence, proforma_sequence, proforma_ion, proforma_fragment, decoy, contaminant and unmarked. Within each axis group and among the layers, name matching ignores case, as it does in DuckDB. Version-tagged alternatives may share one exact name under the rules below. Final axis keys must name required materialized entries.

Columns that differ by version

A rule can cover several versions of a tool. Use version when a column appears only in some versions or changes its header. MaxQuant 1.5.2.8 writes Leading Proteins and later versions write Leading proteins. Both map to the same output column.

{"name": "Leading_proteins", "source": "Leading Proteins", "version": "^1\\.5\\.[0-2](\\.|$)"},
{"name": "Leading_proteins", "source": "Leading proteins", "version": "^(1\\.5\\.([3-9]|\\d{2,})|1\\.6|2\\.)"}
  • Alternatives share the exact output name and may differ only in source, version and note
  • A tagged entry is never required. MaxQuant's tables default var columns to optional; in a table whose defaults say "required": true, write "required": false on each tagged entry. Keys and the primary, sample and ranking layers need a source in every supported version
  • MaxQuant reads its decoy flag the same way: a Reverse entry with source Reverse up to 2.7 and one with source Decoy from 2.8, which apb_Decoy reads as Reverse
  • APB2 selects the entry whose source appears in the header. Two matching alternatives for one name make the level incompatible
  • If parameter files supply a software version, the selected entry's pattern must match it
  • Use one tagged entry for a column that only some versions write
  • rule_json keeps all alternatives. plan_json records the selected entries in obs.versions, var.versions or layer_versions

Decoys and contaminants

Declare apb_Decoy and apb_Contaminant once on each level's var axis. APB2 keeps the rows and sets both Boolean columns. The rule handles contaminants the vendor flags or adds. The protein_fasta workflow marks contaminants defined by the search FASTA, such as ProteoBench's Cont_ entries.

{"name": "apb_Decoy", "inputs": ["Reverse"], "how": "decoy", "equals": "+"}
{"name": "apb_Contaminant", "inputs": ["protein_group"], "how": "contaminant", "prefix": "CON__", "separator": ";"}
{"name": "apb_Decoy", "how": "unmarked"}
  • equals marks a row when the input equals the specified value. Boolean inputs read as true or false
  • prefix: a row is marked when an input starts with it, or, with separator, when any member of the list does
  • decoy and contaminant read at least one input, in exactly one of these two ways
  • unmarked sets every row to false when the report supplies no flag
  • With several inputs, any match marks the row. APB2 skips absent inputs and still writes the output column

Independent sequence computations

Map vendor columns to logical names first. Each sequence computation reads its own ordered inputs. Place this fragment alongside the axis and measurements in the table's base or level.

{
  "sequence_syntax": {
    "vendor_sequence": {
      "parser": "token_regex",
      "token_pattern": "^n\\[(?P<nterm>[^\\]]+)\\]|\\[(?P<residue>[^\\]]+)\\]",
      "token_position": "after_residue"
    }
  },
  "modification_map": {"57.0215": "UNIMOD:4"},
  "columns": {
    "var": [
      {"name": "Modified_Sequence", "source": "Modified Sequence"},
      {"name": "Charge", "source": "Charge", "type": "integer"},
      {"name": "ProForma_peptide", "how": "stripped_sequence", "inputs": ["Modified_Sequence"]},
      {
        "name": "ProForma_peptidoform", "how": "proforma_sequence",
        "inputs": ["Modified_Sequence"], "case_sensitive": false, "unknown_policy": "preserve"
      },
      {
        "name": "ProForma_ion", "how": "proforma_ion",
        "inputs": ["ProForma_peptidoform", "Charge"]
      }
    ]
  }
}

vendor_sequence names the grammar locally. The computed column's inputs and name supply its source and output names. During composition, a level replaces any same-named syntax from the base. APB2 validates references after composition. A column can omit syntax when the level has a single grammar. With several grammars, as in AlphaDIA's plain and vendor syntaxes, each column names its grammar. The level uses one modification_map from vendor tokens to Unimod accessions. A map declared on the level replaces the whole base map.

Syntax parser Normalization inputs Settings
token_regex sequence token_pattern, token_position, marker_pattern
site_list sequence, modifications, sites delimiter, site_base
embedded_site_list sequence, modifications delimiter, entry_pattern, site_base

A token pattern names each capture group nterm, cterm or residue. The group determines the token's site. A residue token modifies the preceding residue with "token_position": "after_residue", or the following one with "token_position": "before_residue"; the syntax must declare one.

  • DIA-NN's rule treats …C(UniMod:4) as a residue modification on cysteine
  • AlphaPept treats cC… as a token before cysteine. Its pattern ^(?P<nterm>a) names N-terminal acetyl
  • PEAKS writes N-terminal acetyl after the first residue or its carbamidomethyl token. The pattern captures both positions with (?:(?<=^[A-Z])|(?<=^C\(\+57\.02\)))\((?P<nterm>\+42\.01|\+42\.0106)\)

Outside a declared token, the parser accepts the twenty amino acid letters plus U, O, B, J, Z and X. It strips _, - and . only at the ends. Other characters raise UnrecognizedSequenceCharacterError. Anchor terminal forms such as FragPipe's n[…] and c[…] and ProForma's […]- and -[…] in the token pattern. Use marker_pattern to strip vendor markers such as AlphaPept's _decoy suffix before tokenizing.

Use a proforma_sequence column named ProForma_peptidoform_unlocalized with embedded_site_list syntax when the vendor gives a modification without its position. A residue-only site such as MaxQuant's Oxidation (M) goes into ProForma's unknown-position group, as in [UNIMOD:35]?PEPTMIDEMK. Terminal sites keep their terminus. A count group in entry_pattern repeats the modification, giving [UNIMOD:35][UNIMOD:35]?… for 2 Oxidation (M). An entry such as Unmodified can match without a token group. The localized ProForma_peptidoform column requires positions.

Stripping takes one logical sequence input with token-regex syntax or {"parser": "plain_sequence"} for a bare sequence. Normalization uses the level's modification_map for Unimod lookup. Its column declares case_sensitive (true or false) and unknown_policy (preserve, drop or error). APB2 records unresolved tokens in diagnostic metadata. Each operation runs on its own distinct inputs.

Result readers preserve stored rule provenance even when that rule's schema is older than the one a fresh conversion needs.

Semantic roles

Roles identify what a column or layer measures. APB2 uses the two protein roles to normalize identifier lists. The packaged role policy defines the allowed roles and their owners. Role policy

Owner Allowed roles
obs none
var fasta_accessions, gene_assignment, protein_assignment
layer abundance

A var role identifies one logical column. gene_assignment names a level's gene group, such as DIA-NN's Genes, so an ion or protein can link to its gene. APB2 writes protein lists for protein_assignment and fasta_accessions with semicolons. Both A, B and A,B become A;B. A column with "separator": ":", as in PEAKS, also splits on colons. Several layers can share the abundance role, including raw, normalized, MS1, MS2, LFQ, iBAQ and peak-area measurements.

measurements.primary_layer makes its source required and selects the layer that AnnData stores as X. Other measurement layers keep their own structural and semantic roles.

A numeric layer inherits its type from the table's defaults unless it declares one. Use "type": "integer" for whole counts. Fractional and infinite values raise an error. Null and NaN are valid missing cells, so AnnData can store an integer layer in a Float64 matrix. Factor layers declare their encoding_mode.

"measurements": {
  "primary_layer": "Intensity",
  "repeated_cells": {"mode": "error"},
  "layers": [
    {"name": "Intensity", "source": "Intensity", "roles": ["abundance"], "missing_values": ["<=0"]},
    {"name": "LFQ_intensity", "source": "LFQ intensity", "roles": ["abundance"], "missing_values": ["<=0"]}
  ]
}

missing_values lists exact numbers such as 0 and at most one <= threshold. The example "<=0" treats all values at or below zero as missing. APB2 applies both forms before duplicate resolution and in the final layer. Every packaged abundance layer uses "<=0" for linear abundances that downstream tools may log-transform, and a test enforces it. Preserve zero and negative values where they carry meaning, such as scores, mass errors and retention-time deltas.

missing_tokens lists vendor spellings for missing numeric values, such as PEAKS' - or WOMBAT-P's NA. After trimming whitespace, APB2 treats a match as missing for both duplicate resolution and numeric diagnostics. Other unreadable values still appear in the conversion summary.

A result records each level's roles under apb.roles: columns maps each role to one var-column name, layers maps each role to the ordered retained layer names. Optional layers absent from the bound source carry no role.

MeasurementLayerRole and AuxiliaryLayerRole control occupancy checks. Rule roles describe scientific meaning. Semantic rule roles

Authoring and verification

Put shared declarations in base and level settings in levels.<level>. For a single-level table, put defaults and any sample_pattern in base and the rest on the level. Share layer declarations in base only when one file can report either of two levels. Sage's lfq.tsv reports ions or peptidoforms according to combine_charge_states. In WOMBAT-P, the charge header determines the level. When one prepared table carries several levels side by side, as in MaxQuant, each level declares its own layers and primary_layer.

APB2 composes and validates one effective rule per level against that table's input. A search-parameter override can select another measurements.primary_layer from the same declared layers.

Run make check after changing rules. The conversion corpus exercises real vendor files and can catch binding or conversion failures that schema validation misses.

To ship a rule as a packaged, detected format, follow Add a vendor format.

See the Python API for programmatic conversion and Read and write parsed results for persisted formats and the compact JSON representation.