apb-export 0.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. apb_export-0.2.2/LICENSE +21 -0
  2. apb_export-0.2.2/PKG-INFO +159 -0
  3. apb_export-0.2.2/README.md +138 -0
  4. apb_export-0.2.2/pyproject.toml +139 -0
  5. apb_export-0.2.2/pyproject.toml.orig +121 -0
  6. apb_export-0.2.2/src/apb_export/__init__.py +1 -0
  7. apb_export-0.2.2/src/apb_export/api.py +98 -0
  8. apb_export-0.2.2/src/apb_export/cli.py +562 -0
  9. apb_export-0.2.2/src/apb_export/computed.py +135 -0
  10. apb_export-0.2.2/src/apb_export/engine.py +717 -0
  11. apb_export-0.2.2/src/apb_export/export_rules/__init__.py +0 -0
  12. apb_export-0.2.2/src/apb_export/export_rules/documents/_schema/document.schema.json +1280 -0
  13. apb_export-0.2.2/src/apb_export/export_rules/documents/_schema/rule.schema.json +1454 -0
  14. apb_export-0.2.2/src/apb_export/export_rules/documents/alphapepttools/v0_4/rules.json +98 -0
  15. apb_export-0.2.2/src/apb_export/export_rules/documents/explorede/v1_0/rules.json +197 -0
  16. apb_export-0.2.2/src/apb_export/export_rules/documents/msmu/v0_4/rules.json +127 -0
  17. apb_export-0.2.2/src/apb_export/export_rules/documents/msstats/v4_20/rules.json +66 -0
  18. apb_export-0.2.2/src/apb_export/export_rules/documents/perseus/v2/rules.json +59 -0
  19. apb_export-0.2.2/src/apb_export/export_rules/documents/prolfqua/v2_11/rules.json +223 -0
  20. apb_export-0.2.2/src/apb_export/export_rules/documents/proteopy/v0_1/rules.json +53 -0
  21. apb_export-0.2.2/src/apb_export/export_rules/documents/proteopy_ion/v0_1/rules.json +62 -0
  22. apb_export-0.2.2/src/apb_export/export_rules/documents/qfeatures/v1_22/rules.json +98 -0
  23. apb_export-0.2.2/src/apb_export/export_rules/documents/qpx/v1_1/rules.json +110 -0
  24. apb_export-0.2.2/src/apb_export/export_rules/layout.py +60 -0
  25. apb_export-0.2.2/src/apb_export/export_rules/loader.py +208 -0
  26. apb_export-0.2.2/src/apb_export/export_rules/schema.py +502 -0
  27. apb_export-0.2.2/src/apb_export/export_rules/schema_artifact.py +40 -0
  28. apb_export-0.2.2/src/apb_export/long_table.py +75 -0
  29. apb_export-0.2.2/src/apb_export/outputs.py +90 -0
  30. apb_export-0.2.2/src/apb_export/perseus_table.py +100 -0
  31. apb_export-0.2.2/src/apb_export/py.typed +1 -0
  32. apb_export-0.2.2/src/apb_export/qpx/LICENSE.qpx +81 -0
  33. apb_export-0.2.2/src/apb_export/qpx/__init__.py +0 -0
  34. apb_export-0.2.2/src/apb_export/qpx/output.py +215 -0
  35. apb_export-0.2.2/src/apb_export/qpx/schema.json +662 -0
  36. apb_export-0.2.2/src/apb_export/qpx/schema.py +32 -0
  37. apb_export-0.2.2/src/apb_export/rows.py +72 -0
  38. apb_export-0.2.2/src/apb_export/sources.py +415 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Witold Wolski
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,159 @@
1
+ Metadata-Version: 2.4
2
+ Name: apb-export
3
+ Version: 0.2.2
4
+ Summary: APB2 results exported for nine downstream targets: msmu, MSstats, Perseus, prolfqua, ProteoPy, exploreDE, AlphaPeptTools, QFeatures and QPX
5
+ Author: Witold Wolski
6
+ Author-email: Witold Wolski <wew@fgcz.ethz.ch>
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ License-File: src/apb_export/qpx/LICENSE.qpx
10
+ Requires-Dist: apb2>=0.1.3,<0.2
11
+ Requires-Dist: apb-catalog>=0.1.5,<0.2
12
+ Requires-Dist: apb-fasta>=0.1.2,<0.2
13
+ Requires-Dist: cyclopts>=4,<5
14
+ Requires-Dist: loguru>=0.7,<1
15
+ Requires-Dist: numpy>=2,<3
16
+ Requires-Dist: polars>=1.43,<2
17
+ Requires-Dist: pyarrow>=21,<24
18
+ Requires-Dist: pydantic>=2.10,<3
19
+ Requires-Python: >=3.13
20
+ Description-Content-Type: text/markdown
21
+
22
+ # APB Export
23
+
24
+ **[Online documentation](https://anndata-omics-bridge.github.io/apb-export/)** or its [source index](docs/index.md).
25
+
26
+ Try it online:
27
+
28
+ - [Rules viewer](https://fgcz-ms.uzh.ch/public/apb-rules/): every vendor table's parse rules, as apb2 packages them
29
+ - [Catalog viewer](https://fgcz-ms.uzh.ch/public/apb-catalog/): every catalog set with its entries and coverage
30
+ - [APB Studio](https://fgcz-ms.uzh.ch/public/apb-studio/): APB's corpus runs over the test vendor files
31
+ - [APB Export](https://apps-dev.bfabric.org/apb-export/): convert a vendor table for a downstream tool in the browser
32
+
33
+ APB2 results exported as downstream AnnData, MuData, CSV long tables, Perseus tables and QPX Parquet: one export rule per target, one subcommand per target. HDF5 files get APB2's `<file>.apb.json` sidecar, which APB Studio's viewer reads; exploreDE's `.h5ad` files, one per level, live in a new `.h5ads` directory. QPX tables and their export manifest live in a new `.qpx` directory; the `.csv` and `.txt` tables have no sidecar. Each target fixes the APB2 levels it reads; `--abundance` picks which layer of a single-level target becomes X, and `--annotation` attaches an SDRF or prolfquapp-style sample table, as `apb2 annotate` does.
34
+
35
+ ```bash
36
+ apb-export msmu report.tsv result.h5mu --params report.log.txt
37
+ apb-export msmu report.tsv result.h5mu --params report.log.txt --fasta proteins.fasta
38
+ apb-export prolfqua report.tsv result.h5ad --params report.log.txt --annotation dataset.csv
39
+ apb-export msstats report.tsv msstats.csv --params report.log.txt --annotation design.tsv
40
+ apb-export perseus report.tsv perseus.txt --params report.log.txt --annotation samples.tsv
41
+ apb-export proteopy report.tsv proteins.h5ad --params report.log.txt
42
+ apb-export alphapepttools report.tsv linked.h5mu --params report.log.txt
43
+ apb-export qfeatures report.tsv qfeatures.h5mu --params report.log.txt
44
+ apb-export qpx report.tsv result.qpx --params report.log.txt
45
+ ```
46
+
47
+ The msmu file is the MuData [msmu](https://github.com/bertis-informatics/msmu) builds itself: apb-catalog names the confidence fields, and msmu takes the result with `msmu.read_h5mu` and runs unchanged.
48
+
49
+ ```python
50
+ import msmu as mm
51
+
52
+ mdata = mm.read_h5mu("result.h5mu")
53
+ mdata = mm.pp.add_filter(mdata, modality="psm", column="q_value", keep="lt", value=0.01)
54
+ mdata = mm.pp.apply_filter(mdata, modality="psm", on="var")
55
+ mdata = mm.pp.to_peptide(mdata, calculate_q=False)
56
+ ```
57
+
58
+ From Python, APB2 converts and `Exporter` exports, the shape of the other APB tools:
59
+
60
+ ```python
61
+ from pathlib import Path
62
+
63
+ from apb2.api import ParseRuleCompiler
64
+ from apb_export.api import Exporter
65
+
66
+ exporter = Exporter("msmu")
67
+ parsed = ParseRuleCompiler.detect(
68
+ Path("report.tsv"), Path("report.log.txt"), requested_levels=exporter.levels
69
+ ).compile().parse()
70
+ exporter.write(exporter.export(parsed), Path("result.h5mu"))
71
+ ```
72
+
73
+ `write` uses APB2's `write_parsed_levels` for HDF5, `.h5ads` included, and target-specific serializers for QPX, the `.csv` long table and the `.txt` Perseus table. An APB2 result already on disk works the same way through `apb2.api.read_parsed_levels`. `Exporter.targets()` lists the packaged targets; `extension` names the file suffix or `.qpx` or `.h5ads` directory.
74
+
75
+ QPX exports existing precursor and/or protein quantities, with no aggregation or required grouping, FASTA or SDRF. RT is resolved through APB Catalog's `chromatography` set and converted from its reviewed unit to seconds. [QPX layout and pMultiQC](docs/targets.md#qpx) describes the tables, missing metadata and report compatibility.
76
+
77
+ ## Install
78
+
79
+ ```bash
80
+ uv tool install --python 3.13 apb-export
81
+ ```
82
+
83
+ This puts `apb-export` on the PATH in an environment of its own; `--with-executables-from apb2,apb-fasta` adds the `apb2` and `apb-fasta` commands. Python 3.13 is the tested interpreter.
84
+
85
+ ## What it writes
86
+
87
+ msmu's `psm` modality, written wide. Experimental: msmu's own readers write one feature per run and precursor, and msmu's tools may expect that.
88
+
89
+ - one `psm` modality; runs are observations, precursors are features, id `<ProForma precursor>`; the keys `filename` and `precursor` stay columns and name the indices, as APB2 writes them
90
+ - `X`: dense float32, the chosen abundance layer (`--abundance`, APB2's primary layer by default); a precursor absent from a run is NaN
91
+ - `layers`: `q_value`, the library or experiment-wide q-value repeated in every run where the vendor reports one, else each run's; each run's `PEP`, where the vendor reports it
92
+ - `var`: `proteins`, `peptide`, `stripped_peptide`, `charge`, `peptide_length`, `decoy`, `contaminant`, and `PEP` and `q_value` where reported, each the precursor's lowest value across runs
93
+ - `uns`: `apb_export_status: "experimental"`, msmu's reader settings, plus APB metadata as in an APB2 result: the MuData's `uns["apb"]` holds the result's root records and the `export` record (rule, target, versions); each modality's `uns["apb"]` holds that level's apb2 records unchanged and the `export` record with each field's APB source and a summary
94
+
95
+ `peptide` is ProForma for every vendor (`AC[UNIMOD:4]K`), not each vendor's own notation. msmu's modification parser reads it, and `to_ptm` takes the tag as written, for example `"[UNIMOD:21]"`.
96
+
97
+ ## Export rules
98
+
99
+ The layout above is declared in [msmu's export rule](src/apb_export/export_rules/documents/msmu/v0_4/rules.json), not coded. Rules follow APB2's rule schema read in reverse: an entry's `name` is the target's field, its `source` an APB field every vendor shares: the run key, the primary layer, or a meaning catalogued by apb-catalog, APB's own columns included (`{"catalog": "apb_alpha", "var": "peptidoform_ion"}` is `ProForma_ion`). Where the result may lack the source, `fallback` lists what to read instead, in order, and the export logs which one it read. A table's `base` holds what every level shares; a level adds its own entries, and one with a base entry's name replaces it. A catalogued source with `"from_level": "protein"` reads the protein level through each variable's protein group, named whole or by the protein that leads it: a cell takes its group's value in its run; a var column's value, the group's, repeats in every run. A level block may name the `software` it is for; an `.h5ad` rule lists its levels in order and writes the first one the result's software and levels allow. One engine checks every source before it builds anything; the published [JSON Schemas](src/apb_export/export_rules/documents/_schema) describe the documents. An installed package can add a target through the `apb_export.targets` entry-point group; see [plugin targets](docs/targets.md#plugin-targets).
100
+
101
+ | Target | File | APB2 levels | Layout |
102
+ | --- | --- | --- | --- |
103
+ | [msmu](src/apb_export/export_rules/documents/msmu/v0_4/rules.json) | `.h5mu` | peptidoform_ion | `psm` modality, precursors by runs, experimental; a feature without a protein is left out and counted in the export record |
104
+ | [MSstats](src/apb_export/export_rules/documents/msstats/v4_20/rules.json) | `.csv` | peptidoform_ion | long table, one row per precursor and run, MSstats' column names |
105
+ | [Perseus](src/apb_export/export_rules/documents/perseus/v2/rules.json) | `.txt` | protein | wide, proteinGroups.txt's names, `#!{Type}` and `#!{C:…}` header rows |
106
+ | [prolfquapp](src/apb_export/export_rules/documents/prolfqua/v2_11/rules.json) | `.h5ad` | peptidoform_ion, or peptide for MaxQuant; reading protein | wide; `uns["prolfquapp"]` for `LFQData_from_anndata`, factors from `apb2 annotate` columns; confidence layers `qValue` (precursor, per run), `pg_qValue` (protein group, per run), `pg_qValue_experiment` (protein group, library or experiment-wide, the same in every run) and `pep`, each where the vendor reports it; a feature without a protein is left out and counted in the export record; with `--fasta`, the leading protein's `fasta.id`, `description`, `IDcolumn` (accession), `gene_name`, `protein_length` and `nr_tryptic_peptides`, as prolfquapp's own FASTA annotation writes them; without one, `fasta.id`, `description` and `IDcolumn` repeat `protein_Id` |
107
+ | [ProteoPy, ions](src/apb_export/export_rules/documents/proteopy_ion/v0_1/rules.json) | `.h5ad` | peptidoform_ion | wide; `sample_id`, `peptide_id` (the ion's ProForma) and `protein_id`; an ion naming several proteins is left out, as ProteoPy's own DIA-NN reader does; ProteoPy rolls the ions up itself |
108
+ | [ProteoPy](src/apb_export/export_rules/documents/proteopy/v0_1/rules.json) | `.h5ad` | protein | wide; `sample_id` and `protein_id` beside their indexes; with `--fasta`, apb-fasta annotates the protein groups and adds `in_fasta`, `gene_id`, `description` and `fasta_organisms`, which ProteoPy does not read |
109
+ | [exploreDE](src/apb_export/export_rules/documents/explorede/v1_0/rules.json) | `.h5ads` directory | protein, peptide, peptidoform_ion, those present | `exploreDE/1.0` without differential expression, one file per level the result holds: `protein.h5ad`, `peptide.h5ad`, `precursor.h5ad`; log2 `intensities` with vendor zeros missing, linear `intensities_raw`, X a copy of `intensities`; SDRF `factor value[…]` and prolfquapp `group`/`bait` columns become `factor_<name>` with sorted categories, other annotation columns pass unprefixed; `feature_id` is the protein group, or `<protein>_<peptide>` and `<protein>_<ProForma ion>`; `label_gene_symbol` is the leading protein's FASTA gene name, else its entry name or accession, with the peptide or precursor appended; `uns` holds exploreDE's identity keys and empty `de`, `enrichment` and `enrichment_support` |
110
+ | [AlphaPeptTools](src/apb_export/export_rules/documents/alphapepttools/v0_4/rules.json) | `.h5mu` | peptidoform_ion, peptide, protein | one wide modality per level, linked by id columns for `mulink_from_anndatas`; peptidoform_ion and peptide modalities carry `contaminant` and, with `--fasta`, `in_fasta`, `fasta_proteins` and `fasta_organisms`, which AlphaPeptTools does not read |
111
+ | [QFeatures](src/apb_export/export_rules/documents/qfeatures/v1_22/rules.json) | `.h5mu` | peptidoform_ion, peptide, protein | AlphaPeptTools' layout; assays linked by `addAssayLink` on id columns |
112
+ | [QPX](src/apb_export/export_rules/documents/qpx/v1_1/rules.json) | `.qpx` directory | peptidoform_ion and/or protein | QPX 1.1 feature/protein Parquet, optional annotations and export manifest; existing primary quantities, catalogued RT in seconds |
113
+
114
+ ## Confidence, by meaning
115
+
116
+ - `q_value`: the library q-value (a var column) when it holds a nonzero value, else the experiment-wide q-value (var), else the per-run q-value; the first two repeat in every run; the order msmu's DIA-NN reader uses
117
+ - `PEP`: the vendor's posterior error probability
118
+ - Lookup: apb-catalog's `confidence` and `proteobench_entrapment` catalogues, never vendor column names
119
+ - Not reported: no `q_value` column, so msmu's filter cannot act on an invented value; `PEP` is NaN, because msmu's `to_peptide` requires the column
120
+ - Unreviewed rule: apb-catalog answers "unknown" and the command stops; unknown is not missing
121
+
122
+ ## Protein groups
123
+
124
+ Written as msmu's readers write them: members split on `;`, the accession taken from a UniProt `db|ACC|NAME` entry, and members spelled `contam_`, `Cont_` or `CON__` respelled `Cont_ACC`. `contaminant` flags a row that apb2 marked `apb_Contaminant`, a contaminant the software flags or adds itself, or that apb-fasta matched to a FASTA contaminant. `apb-export msmu --fasta` runs that FASTA check after conversion; without a FASTA only the vendor's own flags are known.
125
+
126
+ ## Web application
127
+
128
+ The upload page, server and deployment now belong to [APB Export UI](https://github.com/anndata-omics-bridge/apb-export-ui). It installs a locked APB stack and provides `apb-export-web`; this library provides `apb-export` only.
129
+
130
+ ## Limits
131
+
132
+ - A result without the level a target reads is refused: msmu needs an `peptidoform_ion` level (Sage's `lfq.tsv` is peptide-level), ProteoPy a `protein` level, ProteoPy ions a `peptidoform_ion` level
133
+ - Label-free only: a result keyed by more than one observation column, as multiplexed designs are, is refused
134
+ - `decoy` is apb2's `apb_Decoy`; most exports carry no decoys, and msmu's target-decoy q-values need them, so use `calculate_q=False` unless the vendor kept them
135
+ - Group separators other than `;` pass through unchanged; no APB2 rule declares its separator
136
+ - QPX maps retention time through the chromatography catalogue; an unknown original unit is refused instead of assumed
137
+ - msmu's file has no per-run `filename` column: msmu tools that group features by file see precursors, not identifications
138
+
139
+ ## Development
140
+
141
+ The development release expects APB2, apb-catalog and apb-fasta, with apb-fasta's protein_fasta and Prozor, checked out beside this repository, on `main`, as CI checks them out:
142
+
143
+ ```text
144
+ anndata_bridge/
145
+ ├── apb2/
146
+ ├── apb-catalog/
147
+ ├── apb-fasta/
148
+ ├── protein_fasta/
149
+ ├── prozor/
150
+ └── apb-export/
151
+ ```
152
+
153
+ ```bash
154
+ uv sync --group dev
155
+ make check
156
+ make check-full
157
+ ```
158
+
159
+ Tests use synthetic vendor files only and install none of the target tools. Whether the tools read the files is checked in [consumers/](consumers): the [Consumers workflow](.github/workflows/consumers.yml) exports the synthetic examples, validates the QPX ones with qpx and the released pMultiQC, builds one image with msmu, ProteoPy, AlphaPeptTools and perseuspy and one R image with QFeatures and MSstats, and runs each tool's check, msmu's comparison with its own `read_diann` and ProteoPy's ion file against its own DIA-NN reader among them. prolfquapp's check runs in prolfquapp's own image and compares its APB reader with its own `preprocess_DIANN` on peptide and protein values.
@@ -0,0 +1,138 @@
1
+ # APB Export
2
+
3
+ **[Online documentation](https://anndata-omics-bridge.github.io/apb-export/)** or its [source index](docs/index.md).
4
+
5
+ Try it online:
6
+
7
+ - [Rules viewer](https://fgcz-ms.uzh.ch/public/apb-rules/): every vendor table's parse rules, as apb2 packages them
8
+ - [Catalog viewer](https://fgcz-ms.uzh.ch/public/apb-catalog/): every catalog set with its entries and coverage
9
+ - [APB Studio](https://fgcz-ms.uzh.ch/public/apb-studio/): APB's corpus runs over the test vendor files
10
+ - [APB Export](https://apps-dev.bfabric.org/apb-export/): convert a vendor table for a downstream tool in the browser
11
+
12
+ APB2 results exported as downstream AnnData, MuData, CSV long tables, Perseus tables and QPX Parquet: one export rule per target, one subcommand per target. HDF5 files get APB2's `<file>.apb.json` sidecar, which APB Studio's viewer reads; exploreDE's `.h5ad` files, one per level, live in a new `.h5ads` directory. QPX tables and their export manifest live in a new `.qpx` directory; the `.csv` and `.txt` tables have no sidecar. Each target fixes the APB2 levels it reads; `--abundance` picks which layer of a single-level target becomes X, and `--annotation` attaches an SDRF or prolfquapp-style sample table, as `apb2 annotate` does.
13
+
14
+ ```bash
15
+ apb-export msmu report.tsv result.h5mu --params report.log.txt
16
+ apb-export msmu report.tsv result.h5mu --params report.log.txt --fasta proteins.fasta
17
+ apb-export prolfqua report.tsv result.h5ad --params report.log.txt --annotation dataset.csv
18
+ apb-export msstats report.tsv msstats.csv --params report.log.txt --annotation design.tsv
19
+ apb-export perseus report.tsv perseus.txt --params report.log.txt --annotation samples.tsv
20
+ apb-export proteopy report.tsv proteins.h5ad --params report.log.txt
21
+ apb-export alphapepttools report.tsv linked.h5mu --params report.log.txt
22
+ apb-export qfeatures report.tsv qfeatures.h5mu --params report.log.txt
23
+ apb-export qpx report.tsv result.qpx --params report.log.txt
24
+ ```
25
+
26
+ The msmu file is the MuData [msmu](https://github.com/bertis-informatics/msmu) builds itself: apb-catalog names the confidence fields, and msmu takes the result with `msmu.read_h5mu` and runs unchanged.
27
+
28
+ ```python
29
+ import msmu as mm
30
+
31
+ mdata = mm.read_h5mu("result.h5mu")
32
+ mdata = mm.pp.add_filter(mdata, modality="psm", column="q_value", keep="lt", value=0.01)
33
+ mdata = mm.pp.apply_filter(mdata, modality="psm", on="var")
34
+ mdata = mm.pp.to_peptide(mdata, calculate_q=False)
35
+ ```
36
+
37
+ From Python, APB2 converts and `Exporter` exports, the shape of the other APB tools:
38
+
39
+ ```python
40
+ from pathlib import Path
41
+
42
+ from apb2.api import ParseRuleCompiler
43
+ from apb_export.api import Exporter
44
+
45
+ exporter = Exporter("msmu")
46
+ parsed = ParseRuleCompiler.detect(
47
+ Path("report.tsv"), Path("report.log.txt"), requested_levels=exporter.levels
48
+ ).compile().parse()
49
+ exporter.write(exporter.export(parsed), Path("result.h5mu"))
50
+ ```
51
+
52
+ `write` uses APB2's `write_parsed_levels` for HDF5, `.h5ads` included, and target-specific serializers for QPX, the `.csv` long table and the `.txt` Perseus table. An APB2 result already on disk works the same way through `apb2.api.read_parsed_levels`. `Exporter.targets()` lists the packaged targets; `extension` names the file suffix or `.qpx` or `.h5ads` directory.
53
+
54
+ QPX exports existing precursor and/or protein quantities, with no aggregation or required grouping, FASTA or SDRF. RT is resolved through APB Catalog's `chromatography` set and converted from its reviewed unit to seconds. [QPX layout and pMultiQC](docs/targets.md#qpx) describes the tables, missing metadata and report compatibility.
55
+
56
+ ## Install
57
+
58
+ ```bash
59
+ uv tool install --python 3.13 apb-export
60
+ ```
61
+
62
+ This puts `apb-export` on the PATH in an environment of its own; `--with-executables-from apb2,apb-fasta` adds the `apb2` and `apb-fasta` commands. Python 3.13 is the tested interpreter.
63
+
64
+ ## What it writes
65
+
66
+ msmu's `psm` modality, written wide. Experimental: msmu's own readers write one feature per run and precursor, and msmu's tools may expect that.
67
+
68
+ - one `psm` modality; runs are observations, precursors are features, id `<ProForma precursor>`; the keys `filename` and `precursor` stay columns and name the indices, as APB2 writes them
69
+ - `X`: dense float32, the chosen abundance layer (`--abundance`, APB2's primary layer by default); a precursor absent from a run is NaN
70
+ - `layers`: `q_value`, the library or experiment-wide q-value repeated in every run where the vendor reports one, else each run's; each run's `PEP`, where the vendor reports it
71
+ - `var`: `proteins`, `peptide`, `stripped_peptide`, `charge`, `peptide_length`, `decoy`, `contaminant`, and `PEP` and `q_value` where reported, each the precursor's lowest value across runs
72
+ - `uns`: `apb_export_status: "experimental"`, msmu's reader settings, plus APB metadata as in an APB2 result: the MuData's `uns["apb"]` holds the result's root records and the `export` record (rule, target, versions); each modality's `uns["apb"]` holds that level's apb2 records unchanged and the `export` record with each field's APB source and a summary
73
+
74
+ `peptide` is ProForma for every vendor (`AC[UNIMOD:4]K`), not each vendor's own notation. msmu's modification parser reads it, and `to_ptm` takes the tag as written, for example `"[UNIMOD:21]"`.
75
+
76
+ ## Export rules
77
+
78
+ The layout above is declared in [msmu's export rule](src/apb_export/export_rules/documents/msmu/v0_4/rules.json), not coded. Rules follow APB2's rule schema read in reverse: an entry's `name` is the target's field, its `source` an APB field every vendor shares: the run key, the primary layer, or a meaning catalogued by apb-catalog, APB's own columns included (`{"catalog": "apb_alpha", "var": "peptidoform_ion"}` is `ProForma_ion`). Where the result may lack the source, `fallback` lists what to read instead, in order, and the export logs which one it read. A table's `base` holds what every level shares; a level adds its own entries, and one with a base entry's name replaces it. A catalogued source with `"from_level": "protein"` reads the protein level through each variable's protein group, named whole or by the protein that leads it: a cell takes its group's value in its run; a var column's value, the group's, repeats in every run. A level block may name the `software` it is for; an `.h5ad` rule lists its levels in order and writes the first one the result's software and levels allow. One engine checks every source before it builds anything; the published [JSON Schemas](src/apb_export/export_rules/documents/_schema) describe the documents. An installed package can add a target through the `apb_export.targets` entry-point group; see [plugin targets](docs/targets.md#plugin-targets).
79
+
80
+ | Target | File | APB2 levels | Layout |
81
+ | --- | --- | --- | --- |
82
+ | [msmu](src/apb_export/export_rules/documents/msmu/v0_4/rules.json) | `.h5mu` | peptidoform_ion | `psm` modality, precursors by runs, experimental; a feature without a protein is left out and counted in the export record |
83
+ | [MSstats](src/apb_export/export_rules/documents/msstats/v4_20/rules.json) | `.csv` | peptidoform_ion | long table, one row per precursor and run, MSstats' column names |
84
+ | [Perseus](src/apb_export/export_rules/documents/perseus/v2/rules.json) | `.txt` | protein | wide, proteinGroups.txt's names, `#!{Type}` and `#!{C:…}` header rows |
85
+ | [prolfquapp](src/apb_export/export_rules/documents/prolfqua/v2_11/rules.json) | `.h5ad` | peptidoform_ion, or peptide for MaxQuant; reading protein | wide; `uns["prolfquapp"]` for `LFQData_from_anndata`, factors from `apb2 annotate` columns; confidence layers `qValue` (precursor, per run), `pg_qValue` (protein group, per run), `pg_qValue_experiment` (protein group, library or experiment-wide, the same in every run) and `pep`, each where the vendor reports it; a feature without a protein is left out and counted in the export record; with `--fasta`, the leading protein's `fasta.id`, `description`, `IDcolumn` (accession), `gene_name`, `protein_length` and `nr_tryptic_peptides`, as prolfquapp's own FASTA annotation writes them; without one, `fasta.id`, `description` and `IDcolumn` repeat `protein_Id` |
86
+ | [ProteoPy, ions](src/apb_export/export_rules/documents/proteopy_ion/v0_1/rules.json) | `.h5ad` | peptidoform_ion | wide; `sample_id`, `peptide_id` (the ion's ProForma) and `protein_id`; an ion naming several proteins is left out, as ProteoPy's own DIA-NN reader does; ProteoPy rolls the ions up itself |
87
+ | [ProteoPy](src/apb_export/export_rules/documents/proteopy/v0_1/rules.json) | `.h5ad` | protein | wide; `sample_id` and `protein_id` beside their indexes; with `--fasta`, apb-fasta annotates the protein groups and adds `in_fasta`, `gene_id`, `description` and `fasta_organisms`, which ProteoPy does not read |
88
+ | [exploreDE](src/apb_export/export_rules/documents/explorede/v1_0/rules.json) | `.h5ads` directory | protein, peptide, peptidoform_ion, those present | `exploreDE/1.0` without differential expression, one file per level the result holds: `protein.h5ad`, `peptide.h5ad`, `precursor.h5ad`; log2 `intensities` with vendor zeros missing, linear `intensities_raw`, X a copy of `intensities`; SDRF `factor value[…]` and prolfquapp `group`/`bait` columns become `factor_<name>` with sorted categories, other annotation columns pass unprefixed; `feature_id` is the protein group, or `<protein>_<peptide>` and `<protein>_<ProForma ion>`; `label_gene_symbol` is the leading protein's FASTA gene name, else its entry name or accession, with the peptide or precursor appended; `uns` holds exploreDE's identity keys and empty `de`, `enrichment` and `enrichment_support` |
89
+ | [AlphaPeptTools](src/apb_export/export_rules/documents/alphapepttools/v0_4/rules.json) | `.h5mu` | peptidoform_ion, peptide, protein | one wide modality per level, linked by id columns for `mulink_from_anndatas`; peptidoform_ion and peptide modalities carry `contaminant` and, with `--fasta`, `in_fasta`, `fasta_proteins` and `fasta_organisms`, which AlphaPeptTools does not read |
90
+ | [QFeatures](src/apb_export/export_rules/documents/qfeatures/v1_22/rules.json) | `.h5mu` | peptidoform_ion, peptide, protein | AlphaPeptTools' layout; assays linked by `addAssayLink` on id columns |
91
+ | [QPX](src/apb_export/export_rules/documents/qpx/v1_1/rules.json) | `.qpx` directory | peptidoform_ion and/or protein | QPX 1.1 feature/protein Parquet, optional annotations and export manifest; existing primary quantities, catalogued RT in seconds |
92
+
93
+ ## Confidence, by meaning
94
+
95
+ - `q_value`: the library q-value (a var column) when it holds a nonzero value, else the experiment-wide q-value (var), else the per-run q-value; the first two repeat in every run; the order msmu's DIA-NN reader uses
96
+ - `PEP`: the vendor's posterior error probability
97
+ - Lookup: apb-catalog's `confidence` and `proteobench_entrapment` catalogues, never vendor column names
98
+ - Not reported: no `q_value` column, so msmu's filter cannot act on an invented value; `PEP` is NaN, because msmu's `to_peptide` requires the column
99
+ - Unreviewed rule: apb-catalog answers "unknown" and the command stops; unknown is not missing
100
+
101
+ ## Protein groups
102
+
103
+ Written as msmu's readers write them: members split on `;`, the accession taken from a UniProt `db|ACC|NAME` entry, and members spelled `contam_`, `Cont_` or `CON__` respelled `Cont_ACC`. `contaminant` flags a row that apb2 marked `apb_Contaminant`, a contaminant the software flags or adds itself, or that apb-fasta matched to a FASTA contaminant. `apb-export msmu --fasta` runs that FASTA check after conversion; without a FASTA only the vendor's own flags are known.
104
+
105
+ ## Web application
106
+
107
+ The upload page, server and deployment now belong to [APB Export UI](https://github.com/anndata-omics-bridge/apb-export-ui). It installs a locked APB stack and provides `apb-export-web`; this library provides `apb-export` only.
108
+
109
+ ## Limits
110
+
111
+ - A result without the level a target reads is refused: msmu needs an `peptidoform_ion` level (Sage's `lfq.tsv` is peptide-level), ProteoPy a `protein` level, ProteoPy ions a `peptidoform_ion` level
112
+ - Label-free only: a result keyed by more than one observation column, as multiplexed designs are, is refused
113
+ - `decoy` is apb2's `apb_Decoy`; most exports carry no decoys, and msmu's target-decoy q-values need them, so use `calculate_q=False` unless the vendor kept them
114
+ - Group separators other than `;` pass through unchanged; no APB2 rule declares its separator
115
+ - QPX maps retention time through the chromatography catalogue; an unknown original unit is refused instead of assumed
116
+ - msmu's file has no per-run `filename` column: msmu tools that group features by file see precursors, not identifications
117
+
118
+ ## Development
119
+
120
+ The development release expects APB2, apb-catalog and apb-fasta, with apb-fasta's protein_fasta and Prozor, checked out beside this repository, on `main`, as CI checks them out:
121
+
122
+ ```text
123
+ anndata_bridge/
124
+ ├── apb2/
125
+ ├── apb-catalog/
126
+ ├── apb-fasta/
127
+ ├── protein_fasta/
128
+ ├── prozor/
129
+ └── apb-export/
130
+ ```
131
+
132
+ ```bash
133
+ uv sync --group dev
134
+ make check
135
+ make check-full
136
+ ```
137
+
138
+ Tests use synthetic vendor files only and install none of the target tools. Whether the tools read the files is checked in [consumers/](consumers): the [Consumers workflow](.github/workflows/consumers.yml) exports the synthetic examples, validates the QPX ones with qpx and the released pMultiQC, builds one image with msmu, ProteoPy, AlphaPeptTools and perseuspy and one R image with QFeatures and MSstats, and runs each tool's check, msmu's comparison with its own `read_diann` and ProteoPy's ion file against its own DIA-NN reader among them. prolfquapp's check runs in prolfquapp's own image and compares its APB reader with its own `preprocess_DIANN` on peptide and protein values.
@@ -0,0 +1,139 @@
1
+ [build-system]
2
+ requires = ["uv_build>=0.9.26,<0.10.0"]
3
+ build-backend = "uv_build"
4
+
5
+ [project]
6
+ name = "apb-export"
7
+ version = "0.2.2"
8
+ description = "APB2 results exported for nine downstream targets: msmu, MSstats, Perseus, prolfqua, ProteoPy, exploreDE, AlphaPeptTools, QFeatures and QPX"
9
+ readme = "README.md"
10
+ requires-python = ">=3.13"
11
+ license = "MIT"
12
+ license-files = [
13
+ "LICENSE",
14
+ "src/apb_export/qpx/LICENSE.qpx",
15
+ ]
16
+ dependencies = [
17
+ "apb2>=0.1.3,<0.2",
18
+ "apb-catalog>=0.1.5,<0.2",
19
+ "apb-fasta>=0.1.2,<0.2",
20
+ "cyclopts>=4,<5",
21
+ "loguru>=0.7,<1",
22
+ "numpy>=2,<3",
23
+ "polars>=1.43,<2",
24
+ "pyarrow>=21,<24",
25
+ "pydantic>=2.10,<3",
26
+ ]
27
+
28
+ [[project.authors]]
29
+ name = "Witold Wolski"
30
+ email = "wew@fgcz.ethz.ch"
31
+
32
+ [project.scripts]
33
+ apb-export = "apb_export.cli:main"
34
+
35
+ [dependency-groups]
36
+ dev = [
37
+ "mudata>=0.4.1,<0.5",
38
+ "anndata>=0.11",
39
+ "build>=1.3,<2",
40
+ "deptry>=0.24,<1",
41
+ "pandas>=2.2,<4",
42
+ "pre-commit>=4,<5",
43
+ "pyright==1.1.414",
44
+ "pytest>=9,<10",
45
+ "pytest-cov>=7,<8",
46
+ "ruff==0.16.10",
47
+ "twine>=6,<7",
48
+ ]
49
+ docs = [
50
+ "mkdocstrings[python]>=1.0,<2",
51
+ "pymdown-extensions>=11,<12",
52
+ "zensical==0.0.43",
53
+ ]
54
+
55
+ [tool.ruff]
56
+ line-length = 100
57
+ target-version = "py313"
58
+ src = [
59
+ "src",
60
+ "tests",
61
+ ]
62
+
63
+ [tool.ruff.lint]
64
+ select = [
65
+ "ANN",
66
+ "B",
67
+ "C4",
68
+ "C90",
69
+ "E4",
70
+ "E7",
71
+ "E9",
72
+ "F",
73
+ "I",
74
+ "PGH",
75
+ "PIE",
76
+ "RUF",
77
+ "SIM",
78
+ "UP",
79
+ ]
80
+
81
+ [tool.ruff.lint.mccabe]
82
+ max-complexity = 10
83
+
84
+ [tool.ruff.format]
85
+ docstring-code-format = true
86
+
87
+ [tool.pyright]
88
+ include = [
89
+ "src",
90
+ "tests",
91
+ ]
92
+ venvPath = "."
93
+ venv = ".venv"
94
+ pythonVersion = "3.13"
95
+ typeCheckingMode = "strict"
96
+ reportImportCycles = "error"
97
+ reportUnnecessaryTypeIgnoreComment = "error"
98
+ reportImplicitOverride = "error"
99
+ enableTypeIgnoreComments = false
100
+ reportMissingTypeStubs = "none"
101
+ reportUnknownMemberType = "none"
102
+ reportUnknownVariableType = "none"
103
+ reportUnknownArgumentType = "none"
104
+ reportUnknownParameterType = "none"
105
+ reportUnknownLambdaType = "none"
106
+
107
+ [tool.pytest.ini_options]
108
+ addopts = [
109
+ "--strict-config",
110
+ "--strict-markers",
111
+ "-ra",
112
+ ]
113
+ testpaths = ["tests"]
114
+ xfail_strict = true
115
+
116
+ [tool.coverage.run]
117
+ branch = true
118
+ source = ["apb_export"]
119
+
120
+ [tool.coverage.report]
121
+ fail_under = 80
122
+ show_missing = true
123
+ skip_covered = true
124
+
125
+ [tool.deptry]
126
+ known_first_party = ["apb_export"]
127
+ extend_exclude = ["consumers"]
128
+
129
+ [tool.uv.sources.apb2]
130
+ path = "../apb2"
131
+ editable = true
132
+
133
+ [tool.uv.sources.apb-catalog]
134
+ path = "../apb-catalog"
135
+ editable = true
136
+
137
+ [tool.uv.sources.apb-fasta]
138
+ path = "../apb-fasta"
139
+ editable = true
@@ -0,0 +1,121 @@
1
+ [build-system]
2
+ requires = ["uv_build>=0.9.26,<0.10.0"]
3
+ build-backend = "uv_build"
4
+
5
+ [project]
6
+ name = "apb-export"
7
+ version = "0.2.2"
8
+ description = "APB2 results exported for nine downstream targets: msmu, MSstats, Perseus, prolfqua, ProteoPy, exploreDE, AlphaPeptTools, QFeatures and QPX"
9
+ readme = "README.md"
10
+ requires-python = ">=3.13"
11
+ license = "MIT"
12
+ license-files = ["LICENSE", "src/apb_export/qpx/LICENSE.qpx"]
13
+ authors = [
14
+ { name = "Witold Wolski", email = "wew@fgcz.ethz.ch" },
15
+ ]
16
+ dependencies = [
17
+ "apb2>=0.1.3,<0.2",
18
+ "apb-catalog>=0.1.5,<0.2",
19
+ "apb-fasta>=0.1.2,<0.2",
20
+ "cyclopts>=4,<5",
21
+ "loguru>=0.7,<1",
22
+ "numpy>=2,<3",
23
+ "polars>=1.43,<2",
24
+ "pyarrow>=21,<24",
25
+ "pydantic>=2.10,<3",
26
+ ]
27
+
28
+ [project.scripts]
29
+ apb-export = "apb_export.cli:main"
30
+
31
+ [dependency-groups]
32
+ dev = [
33
+ "mudata>=0.4.1,<0.5",
34
+ "anndata>=0.11",
35
+ "build>=1.3,<2",
36
+ "deptry>=0.24,<1",
37
+ "pandas>=2.2,<4",
38
+ "pre-commit>=4,<5",
39
+ "pyright==1.1.414",
40
+ "pytest>=9,<10",
41
+ "pytest-cov>=7,<8",
42
+ "ruff==0.16.10",
43
+ "twine>=6,<7",
44
+ ]
45
+ docs = [
46
+ "mkdocstrings[python]>=1.0,<2",
47
+ "pymdown-extensions>=11,<12",
48
+ "zensical==0.0.43",
49
+ ]
50
+
51
+ [tool.ruff]
52
+ line-length = 100
53
+ target-version = "py313"
54
+ src = ["src", "tests"]
55
+
56
+ [tool.ruff.lint]
57
+ select = [
58
+ "ANN",
59
+ "B",
60
+ "C4",
61
+ "C90",
62
+ "E4",
63
+ "E7",
64
+ "E9",
65
+ "F",
66
+ "I",
67
+ "PGH",
68
+ "PIE",
69
+ "RUF",
70
+ "SIM",
71
+ "UP",
72
+ ]
73
+
74
+ [tool.ruff.lint.mccabe]
75
+ max-complexity = 10
76
+
77
+ [tool.ruff.format]
78
+ docstring-code-format = true
79
+
80
+ [tool.pyright]
81
+ include = ["src", "tests"]
82
+ venvPath = "."
83
+ venv = ".venv"
84
+ pythonVersion = "3.13"
85
+ typeCheckingMode = "strict"
86
+ reportImportCycles = "error"
87
+ reportUnnecessaryTypeIgnoreComment = "error"
88
+ reportImplicitOverride = "error"
89
+ enableTypeIgnoreComments = false
90
+ # SciPy, pandas and AnnData still propagate Unknown through supported public operations.
91
+ # Keep strict first-party checking while suppressing diagnostics with only that signal.
92
+ reportMissingTypeStubs = "none"
93
+ reportUnknownMemberType = "none"
94
+ reportUnknownVariableType = "none"
95
+ reportUnknownArgumentType = "none"
96
+ reportUnknownParameterType = "none"
97
+ reportUnknownLambdaType = "none"
98
+
99
+ [tool.pytest.ini_options]
100
+ addopts = ["--strict-config", "--strict-markers", "-ra"]
101
+ testpaths = ["tests"]
102
+ xfail_strict = true
103
+
104
+ [tool.coverage.run]
105
+ branch = true
106
+ source = ["apb_export"]
107
+
108
+ [tool.coverage.report]
109
+ fail_under = 80
110
+ show_missing = true
111
+ skip_covered = true
112
+
113
+ [tool.deptry]
114
+ known_first_party = ["apb_export"]
115
+ # consumers/ runs in the consumer image, where the tools it imports are installed.
116
+ extend_exclude = ["consumers"]
117
+
118
+ [tool.uv.sources]
119
+ apb2 = { path = "../apb2", editable = true }
120
+ apb-catalog = { path = "../apb-catalog", editable = true }
121
+ apb-fasta = { path = "../apb-fasta", editable = true }