apb-export 0.2.2__py3-none-any.whl

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 (39) hide show
  1. apb_export/__init__.py +1 -0
  2. apb_export/api.py +98 -0
  3. apb_export/cli.py +562 -0
  4. apb_export/computed.py +135 -0
  5. apb_export/engine.py +717 -0
  6. apb_export/export_rules/__init__.py +0 -0
  7. apb_export/export_rules/documents/_schema/document.schema.json +1280 -0
  8. apb_export/export_rules/documents/_schema/rule.schema.json +1454 -0
  9. apb_export/export_rules/documents/alphapepttools/v0_4/rules.json +98 -0
  10. apb_export/export_rules/documents/explorede/v1_0/rules.json +197 -0
  11. apb_export/export_rules/documents/msmu/v0_4/rules.json +127 -0
  12. apb_export/export_rules/documents/msstats/v4_20/rules.json +66 -0
  13. apb_export/export_rules/documents/perseus/v2/rules.json +59 -0
  14. apb_export/export_rules/documents/prolfqua/v2_11/rules.json +223 -0
  15. apb_export/export_rules/documents/proteopy/v0_1/rules.json +53 -0
  16. apb_export/export_rules/documents/proteopy_ion/v0_1/rules.json +62 -0
  17. apb_export/export_rules/documents/qfeatures/v1_22/rules.json +98 -0
  18. apb_export/export_rules/documents/qpx/v1_1/rules.json +110 -0
  19. apb_export/export_rules/layout.py +60 -0
  20. apb_export/export_rules/loader.py +208 -0
  21. apb_export/export_rules/schema.py +502 -0
  22. apb_export/export_rules/schema_artifact.py +40 -0
  23. apb_export/long_table.py +75 -0
  24. apb_export/outputs.py +90 -0
  25. apb_export/perseus_table.py +100 -0
  26. apb_export/py.typed +1 -0
  27. apb_export/qpx/LICENSE.qpx +81 -0
  28. apb_export/qpx/__init__.py +0 -0
  29. apb_export/qpx/output.py +215 -0
  30. apb_export/qpx/schema.json +662 -0
  31. apb_export/qpx/schema.py +32 -0
  32. apb_export/rows.py +72 -0
  33. apb_export/sources.py +415 -0
  34. apb_export-0.2.2.dist-info/METADATA +159 -0
  35. apb_export-0.2.2.dist-info/RECORD +39 -0
  36. apb_export-0.2.2.dist-info/WHEEL +4 -0
  37. apb_export-0.2.2.dist-info/entry_points.txt +3 -0
  38. apb_export-0.2.2.dist-info/licenses/LICENSE +21 -0
  39. apb_export-0.2.2.dist-info/licenses/src/apb_export/qpx/LICENSE.qpx +81 -0
apb_export/__init__.py ADDED
@@ -0,0 +1 @@
1
+
apb_export/api.py ADDED
@@ -0,0 +1,98 @@
1
+ """Exports of APB2 results in the formats downstream tools read.
2
+
3
+ APB2 owns conversion and persistence: ``ParseRuleCompiler`` reads vendor files into
4
+ ``ParsedLevels``, ``read_parsed_levels`` loads a stored result, ``write_parsed_levels`` writes
5
+ one. Each target's packaged export rule declares what that tool reads; ``Exporter`` applies one
6
+ and writes the target's format: HDF5 through APB2, one ``.h5ad`` per level in a ``.h5ads``
7
+ directory, a ``.csv`` long table, a ``.txt`` Perseus table, or a QPX Parquet directory. The
8
+ command composes conversion, annotation and export.
9
+
10
+ A plugin package adds a target through the `apb_export.targets` entry-point group.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ from pathlib import Path
16
+
17
+ from apb2.api import ParsedLevels, QuantificationLevel
18
+
19
+ from apb_export.engine import CompiledExport
20
+ from apb_export.export_rules.loader import packaged_documents, packaged_rules
21
+
22
+
23
+ class Exporter:
24
+ """Bind one packaged target's export rule and the layer that becomes X."""
25
+
26
+ __slots__ = ("_abundance", "_compiled")
27
+
28
+ def __init__(self, target: str, abundance: str | None = None) -> None:
29
+ """Choose the target and, for a one-level target, the layer that becomes X.
30
+
31
+ Args:
32
+ target: One of :meth:`targets`.
33
+ abundance: A layer of the target's level; APB2's primary layer when ``None``.
34
+
35
+ Raises:
36
+ ValueError: The target is neither packaged nor installed by a plugin, or ``abundance``
37
+ is given for a target that writes several levels.
38
+ """
39
+ if target not in self.targets():
40
+ raise ValueError(f"unknown export target {target!r}; packaged: {list(self.targets())}")
41
+ self._compiled = CompiledExport(packaged_rules(target))
42
+ if abundance is not None and not self._compiled.writes_one_level:
43
+ raise ValueError(
44
+ f"{target} writes {list(self._compiled.written)}; "
45
+ "abundance applies only to targets that write one level"
46
+ )
47
+ self._abundance = abundance
48
+
49
+ @staticmethod
50
+ def targets() -> tuple[str, ...]:
51
+ """The packaged targets and those of installed plugins, by name."""
52
+ return tuple(dict.fromkeys(name.split("/", 1)[0] for name in packaged_documents()))
53
+
54
+ @property
55
+ def levels(self) -> tuple[QuantificationLevel, ...]:
56
+ """The APB2 levels the target reads; the command asks APB2 for exactly these."""
57
+ return self._compiled.levels
58
+
59
+ @property
60
+ def extension(self) -> str:
61
+ """The target's file suffix: ``.h5ad``, ``.h5mu``, ``.csv`` or ``.txt``, or the directory
62
+ suffix ``.qpx`` or ``.h5ads``."""
63
+ return self._compiled.extension
64
+
65
+ def export(self, parsed: ParsedLevels) -> ParsedLevels:
66
+ """Build the target's export from an APB2 result.
67
+
68
+ Args:
69
+ parsed: An APB2 result holding the levels the target requires.
70
+
71
+ Returns:
72
+ A ``ParsedLevels`` for APB2's writer, one level per level the target reads, with a
73
+ directed feature relation for each of the target's feature links.
74
+
75
+ Raises:
76
+ ValueError: The result lacks a level or field the target requires.
77
+ UnresolvedField: apb-catalog finds an answer ambiguous or the vendor rule unreviewed.
78
+ """
79
+ written = self._compiled.written
80
+ chosen = None if self._abundance is None else dict.fromkeys(written, self._abundance)
81
+ return self._compiled.export(parsed, abundance=chosen)
82
+
83
+ def write(self, exported: ParsedLevels, output: Path) -> None:
84
+ """Write an export in its target's format.
85
+
86
+ HDF5 exports use APB2's writer with unprefixed variable names and its sidecar.
87
+ QPX exports contain Parquet tables and an export manifest in a new directory.
88
+ ``.csv`` exports are the long table and ``.txt`` exports the Perseus table, both
89
+ without a sidecar.
90
+
91
+ Args:
92
+ exported: What :meth:`export` returned.
93
+ output: The new ``.h5ad``/``.h5mu``/``.csv``/``.txt`` file or ``.qpx`` directory.
94
+ """
95
+ self._compiled.write(exported, output)
96
+
97
+
98
+ __all__ = ["Exporter"]
apb_export/cli.py ADDED
@@ -0,0 +1,562 @@
1
+ """``apb-export``: vendor output in, the file or directory a downstream tool opens.
2
+
3
+ One subcommand per target, each reading the APB2 levels its export rule names: APB2 converts
4
+ the vendor files, apb2's sample annotation attaches ``--annotation`` or ``--sdrf``, apb-fasta
5
+ checks the peptides and protein groups against ``--fasta``, and
6
+ :class:`~apb_export.api.Exporter` builds the file. Existing files are never overwritten. A target
7
+ an installed plugin adds gets a generated subcommand.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import sys
13
+ from collections.abc import Mapping
14
+ from functools import partial
15
+ from pathlib import Path
16
+ from typing import Annotated, Any, cast
17
+
18
+ from apb2.api import (
19
+ AnnotationCompiler,
20
+ ParsedLevel,
21
+ ParsedLevels,
22
+ ParseRuleCompiler,
23
+ QuantificationLevel,
24
+ SdrfSource,
25
+ )
26
+ from apb_catalog.api import UnresolvedField
27
+ from apb_fasta.api import FastaAnnotator
28
+ from cyclopts import App, Parameter
29
+ from loguru import logger
30
+
31
+ from apb_export.api import Exporter
32
+
33
+ app = App(
34
+ name="apb-export",
35
+ help="Export vendor output as downstream AnnData, MuData, CSV, Perseus tables or QPX Parquet.",
36
+ )
37
+
38
+ Data = Annotated[Path, Parameter(help="Vendor table or vendor-result directory")]
39
+ Params = Annotated[
40
+ tuple[Path, ...],
41
+ Parameter(
42
+ help="Vendor parameter file; repeat for a tool that writes two (MetaMorpheus, quantms)"
43
+ ),
44
+ ]
45
+ Software = Annotated[
46
+ str | None, Parameter(help="Restrict recognition to one vendor, as in apb2 convert")
47
+ ]
48
+ Abundance = Annotated[
49
+ str | None,
50
+ Parameter(help="Layer of the target's level to become X; the export rule's choice by default"),
51
+ ]
52
+ SampleAnnotation = Annotated[
53
+ Path | None,
54
+ Parameter(help="SDRF or prolfquapp-style CSV/TSV sample annotation, as apb2 annotate reads"),
55
+ ]
56
+ Sdrf = Annotated[
57
+ Path | None,
58
+ Parameter(
59
+ help="SDRF-Proteomics sample table: every run must match one of its rows, whose columns "
60
+ "fill the sample metadata"
61
+ ),
62
+ ]
63
+ Strict = Annotated[
64
+ bool, Parameter(negative=False, help="Make an effectively empty layer an error, not left out")
65
+ ]
66
+ Fasta = Annotated[
67
+ tuple[Path, ...],
68
+ Parameter(
69
+ negative=False,
70
+ help="Optional FASTA files, or their protein-fasta database: check the peptides and "
71
+ "annotate the protein groups first, and log how many the FASTA holds; msmu also flags "
72
+ "the FASTA's contaminants",
73
+ ),
74
+ ]
75
+
76
+
77
+ def _parse(
78
+ data: Path,
79
+ params: tuple[Path, ...],
80
+ levels: tuple[QuantificationLevel, ...],
81
+ *,
82
+ software: str | None,
83
+ strict: bool,
84
+ ) -> ParsedLevels:
85
+ """Read the vendor files into the levels the target reads, those the vendor has.
86
+
87
+ Without a parameter file the software's columns alone choose the rule, as ``apb2
88
+ convert --software`` does.
89
+ """
90
+ checks = "strict" if strict else "standard"
91
+ compiler = (
92
+ ParseRuleCompiler.from_software(data, software, levels, checks)
93
+ if not params and software is not None
94
+ else ParseRuleCompiler.detect(data, params or None, levels, checks, software)
95
+ )
96
+ return compiler.compile().parse()
97
+
98
+
99
+ def _exported(
100
+ target: str,
101
+ data: Path,
102
+ output: Path,
103
+ *,
104
+ params: tuple[Path, ...],
105
+ software: str | None,
106
+ abundance: str | None,
107
+ annotation: Path | None,
108
+ strict: bool,
109
+ fasta: tuple[Path, ...] = (),
110
+ sdrf: Path | None = None,
111
+ ) -> ParsedLevels | None:
112
+ """Convert, annotate, FASTA-check and export; ``None`` after logging why not."""
113
+ exporter = Exporter(target, abundance)
114
+ if output.suffix != exporter.extension:
115
+ logger.error(f"{target} opens {exporter.extension} files, not {output}")
116
+ return None
117
+ if output.exists():
118
+ logger.error(f"refusing to overwrite {output}")
119
+ return None
120
+ try:
121
+ parsed = _parse(data, params, exporter.levels, software=software, strict=strict)
122
+ if annotation is not None:
123
+ parsed = AnnotationCompiler().compile(annotation).parse(parsed).annotate().parsed
124
+ if sdrf is not None:
125
+ SdrfSource.read(sdrf) # refuses a table that is no SDRF before matching its rows
126
+ compiled = AnnotationCompiler(unmatched="error").compile(sdrf)
127
+ parsed = compiled.parse(parsed).annotate().parsed
128
+ if fasta:
129
+ parsed = _fasta_checked(parsed, fasta)
130
+ return exporter.export(parsed)
131
+ except (OSError, ValueError) as error:
132
+ logger.error(str(error))
133
+ except UnresolvedField as error:
134
+ # Unknown is not missing: a step that writes the field has not run, and the error names
135
+ # it, or the catalogue has not reviewed this exact vendor rule. Guessing would export a
136
+ # silent gap.
137
+ logger.error(
138
+ f"apb-catalog cannot answer for this vendor rule ({error}); unless it names a step "
139
+ "to run, re-review the catalogues against this APB2 revision"
140
+ )
141
+ return None
142
+
143
+
144
+ def _fasta_checked(parsed: ParsedLevels, fasta: tuple[Path, ...]) -> ParsedLevels:
145
+ """Verify the peptides and annotate the protein lists the result's levels hold against the
146
+ FASTA, and log the coverage; a level's protein list is apb2's ``fasta_accessions`` role."""
147
+ annotator = FastaAnnotator.read(fasta)
148
+ if set(parsed.levels) - {"protein"}:
149
+ verified = annotator.verify_peptides(parsed)
150
+ for level, coverage in verified.reports.peptide_levels.items():
151
+ logger.info(
152
+ f"fasta level={level} peptides_in_fasta={coverage.matched_feature_count}/"
153
+ f"{coverage.feature_count - coverage.decoy_feature_count} "
154
+ f"unmatched={coverage.unmatched_feature_count} "
155
+ f"decoys={coverage.decoy_feature_count}"
156
+ )
157
+ parsed = verified.parsed
158
+ if any("fasta_accessions" in level.var.roles for level in parsed.levels.values()):
159
+ annotated = annotator.merge_annotations(parsed)
160
+ for level, groups in annotated.reports.protein_groups.items():
161
+ logger.info(
162
+ f"fasta level={level} members_in_fasta={groups.matched_member_count}/"
163
+ f"{groups.member_count} unmatched={groups.unmatched_member_count} "
164
+ f"ambiguous={groups.ambiguous_member_count}"
165
+ )
166
+ parsed = annotated.parsed
167
+ return parsed
168
+
169
+
170
+ def _shape(n_obs: int, n_vars: int, export: Mapping[str, Any]) -> str:
171
+ """A level's shape and, from the export's record, the APB layer behind each matrix."""
172
+ sources = export["provenance"]["sources"]
173
+ layers = [
174
+ f"{key.split('.', 1)[1]}={value.get('name', value.get('location'))}"
175
+ for key, value in sources.items()
176
+ if key.startswith("layers.")
177
+ ]
178
+ return f"{n_obs} x {n_vars} ({', '.join(layers)})"
179
+
180
+
181
+ def _record(level: ParsedLevel) -> dict[str, Any]:
182
+ """The export's own record of one level of a ``ParsedLevels`` export."""
183
+ return cast(dict[str, Any], level.metadata["export"])
184
+
185
+
186
+ def _write(target: str, result: ParsedLevels | None, output: Path) -> int:
187
+ if result is None:
188
+ return 1
189
+ output.parent.mkdir(parents=True, exist_ok=True)
190
+ try:
191
+ Exporter(target).write(result, output)
192
+ except (OSError, ValueError) as error:
193
+ logger.error(str(error))
194
+ return 1
195
+ shapes = "; ".join(
196
+ f"{name} {_shape(level.obs.frame.height, level.var.frame.height, _record(level))}"
197
+ for name, level in result.levels.items()
198
+ )
199
+ logger.info(f"wrote {output}: {shapes}")
200
+ return 0
201
+
202
+
203
+ @app.command
204
+ def msmu(
205
+ data: Data,
206
+ output: Annotated[Path, Parameter(help="New .h5mu file for msmu.read_h5mu")],
207
+ /,
208
+ *,
209
+ params: Params = (),
210
+ software: Software = None,
211
+ abundance: Abundance = None,
212
+ strict: Strict = False,
213
+ fasta: Fasta = (),
214
+ ) -> int:
215
+ """APB2's peptidoform_ion level as msmu's psm modality, precursors by runs; experimental."""
216
+ result = _exported(
217
+ "msmu",
218
+ data,
219
+ output,
220
+ params=params,
221
+ software=software,
222
+ abundance=abundance,
223
+ annotation=None,
224
+ strict=strict,
225
+ fasta=fasta,
226
+ )
227
+ if result is not None:
228
+ # The PSM table names the identification file its rows came from, by base name.
229
+ result.levels["psm"].export_uns["identification_file"] = data.name
230
+ return _write("msmu", result, output)
231
+
232
+
233
+ @app.command
234
+ def prolfqua(
235
+ data: Data,
236
+ output: Annotated[Path, Parameter(help="New .h5ad file for LFQData_from_anndata")],
237
+ /,
238
+ *,
239
+ params: Params = (),
240
+ software: Software = None,
241
+ abundance: Abundance = None,
242
+ annotation: SampleAnnotation = None,
243
+ strict: Strict = False,
244
+ fasta: Fasta = (),
245
+ ) -> int:
246
+ """APB2's peptidoform_ion level for prolfquapp; the annotation's columns become its factors."""
247
+ return _write(
248
+ "prolfqua",
249
+ _exported(
250
+ "prolfqua",
251
+ data,
252
+ output,
253
+ params=params,
254
+ software=software,
255
+ abundance=abundance,
256
+ annotation=annotation,
257
+ strict=strict,
258
+ fasta=fasta,
259
+ ),
260
+ output,
261
+ )
262
+
263
+
264
+ @app.command
265
+ def msstats(
266
+ data: Data,
267
+ output: Annotated[Path, Parameter(help="New .csv file for MSstats::dataProcess")],
268
+ /,
269
+ *,
270
+ params: Params = (),
271
+ software: Software = None,
272
+ abundance: Abundance = None,
273
+ annotation: SampleAnnotation = None,
274
+ strict: Strict = False,
275
+ fasta: Fasta = (),
276
+ ) -> int:
277
+ """APB2's peptidoform_ion level as MSstats' long table; the annotation gives Condition and
278
+ BioReplicate."""
279
+ return _write(
280
+ "msstats",
281
+ _exported(
282
+ "msstats",
283
+ data,
284
+ output,
285
+ params=params,
286
+ software=software,
287
+ abundance=abundance,
288
+ annotation=annotation,
289
+ strict=strict,
290
+ fasta=fasta,
291
+ ),
292
+ output,
293
+ )
294
+
295
+
296
+ @app.command
297
+ def perseus(
298
+ data: Data,
299
+ output: Annotated[Path, Parameter(help="New .txt file for Perseus")],
300
+ /,
301
+ *,
302
+ params: Params = (),
303
+ software: Software = None,
304
+ abundance: Abundance = None,
305
+ annotation: SampleAnnotation = None,
306
+ strict: Strict = False,
307
+ fasta: Fasta = (),
308
+ ) -> int:
309
+ """APB2's protein level as Perseus loads MaxQuant's proteinGroups.txt; each annotation
310
+ column becomes a categorical row."""
311
+ return _write(
312
+ "perseus",
313
+ _exported(
314
+ "perseus",
315
+ data,
316
+ output,
317
+ params=params,
318
+ software=software,
319
+ abundance=abundance,
320
+ annotation=annotation,
321
+ strict=strict,
322
+ fasta=fasta,
323
+ ),
324
+ output,
325
+ )
326
+
327
+
328
+ @app.command
329
+ def proteopy(
330
+ data: Data,
331
+ output: Annotated[Path, Parameter(help="New .h5ad file for ProteoPy")],
332
+ /,
333
+ *,
334
+ params: Params = (),
335
+ software: Software = None,
336
+ abundance: Abundance = None,
337
+ annotation: SampleAnnotation = None,
338
+ strict: Strict = False,
339
+ fasta: Fasta = (),
340
+ ) -> int:
341
+ """APB2's protein level for ProteoPy, with sample_id and protein_id."""
342
+ return _write(
343
+ "proteopy",
344
+ _exported(
345
+ "proteopy",
346
+ data,
347
+ output,
348
+ params=params,
349
+ software=software,
350
+ abundance=abundance,
351
+ annotation=annotation,
352
+ strict=strict,
353
+ fasta=fasta,
354
+ ),
355
+ output,
356
+ )
357
+
358
+
359
+ @app.command(name="proteopy_ion") # a command is named as its target, which the web app runs
360
+ def proteopy_ion(
361
+ data: Data,
362
+ output: Annotated[Path, Parameter(help="New .h5ad file for ProteoPy")],
363
+ /,
364
+ *,
365
+ params: Params = (),
366
+ software: Software = None,
367
+ abundance: Abundance = None,
368
+ annotation: SampleAnnotation = None,
369
+ strict: Strict = False,
370
+ fasta: Fasta = (),
371
+ ) -> int:
372
+ """APB2's peptidoform_ion level for ProteoPy, one ion per peptide_id, with sample_id and
373
+ protein_id; ions naming several proteins are left out, as ProteoPy's DIA-NN reader does, and
374
+ ProteoPy rolls the ions up itself."""
375
+ return _write(
376
+ "proteopy_ion",
377
+ _exported(
378
+ "proteopy_ion",
379
+ data,
380
+ output,
381
+ params=params,
382
+ software=software,
383
+ abundance=abundance,
384
+ annotation=annotation,
385
+ strict=strict,
386
+ fasta=fasta,
387
+ ),
388
+ output,
389
+ )
390
+
391
+
392
+ @app.command
393
+ def explorede(
394
+ data: Data,
395
+ output: Annotated[Path, Parameter(help="New .h5ads directory for exploreDE")],
396
+ /,
397
+ *,
398
+ params: Params = (),
399
+ software: Software = None,
400
+ annotation: SampleAnnotation = None,
401
+ strict: Strict = False,
402
+ fasta: Fasta = (),
403
+ ) -> int:
404
+ """APB2's protein, peptide and peptidoform_ion levels, those the result holds, as
405
+ exploreDE/1.0 files without differential expression, one .h5ad each; SDRF factor values
406
+ and prolfquapp grouping columns become their factors."""
407
+ return _write(
408
+ "explorede",
409
+ _exported(
410
+ "explorede",
411
+ data,
412
+ output,
413
+ params=params,
414
+ software=software,
415
+ abundance=None,
416
+ annotation=annotation,
417
+ strict=strict,
418
+ fasta=fasta,
419
+ ),
420
+ output,
421
+ )
422
+
423
+
424
+ @app.command
425
+ def qpx(
426
+ data: Data,
427
+ output: Annotated[Path, Parameter(help="New .qpx directory containing QPX Parquet tables")],
428
+ /,
429
+ *,
430
+ params: Params = (),
431
+ software: Software = None,
432
+ annotation: SampleAnnotation = None,
433
+ strict: Strict = False,
434
+ fasta: Fasta = (),
435
+ ) -> int:
436
+ """Existing precursor and protein quantities as QPX 1.1; either level suffices."""
437
+ return _write(
438
+ "qpx",
439
+ _exported(
440
+ "qpx",
441
+ data,
442
+ output,
443
+ params=params,
444
+ software=software,
445
+ abundance=None,
446
+ annotation=annotation,
447
+ strict=strict,
448
+ fasta=fasta,
449
+ ),
450
+ output,
451
+ )
452
+
453
+
454
+ @app.command
455
+ def alphapepttools(
456
+ data: Data,
457
+ output: Annotated[Path, Parameter(help="New .h5mu file for mulink_from_anndatas")],
458
+ /,
459
+ *,
460
+ params: Params = (),
461
+ software: Software = None,
462
+ annotation: SampleAnnotation = None,
463
+ strict: Strict = False,
464
+ fasta: Fasta = (),
465
+ ) -> int:
466
+ """APB2's peptidoform_ion, peptide and protein levels as AlphaPeptTools modalities, each primary layer."""
467
+ return _write(
468
+ "alphapepttools",
469
+ _exported(
470
+ "alphapepttools",
471
+ data,
472
+ output,
473
+ params=params,
474
+ software=software,
475
+ abundance=None,
476
+ annotation=annotation,
477
+ strict=strict,
478
+ fasta=fasta,
479
+ ),
480
+ output,
481
+ )
482
+
483
+
484
+ @app.command
485
+ def qfeatures(
486
+ data: Data,
487
+ output: Annotated[Path, Parameter(help="New .h5mu file for MuData::readH5MU and QFeatures")],
488
+ /,
489
+ *,
490
+ params: Params = (),
491
+ software: Software = None,
492
+ annotation: SampleAnnotation = None,
493
+ strict: Strict = False,
494
+ fasta: Fasta = (),
495
+ ) -> int:
496
+ """APB2's peptidoform_ion, peptide and protein levels as QFeatures assays, linked by id columns."""
497
+ return _write(
498
+ "qfeatures",
499
+ _exported(
500
+ "qfeatures",
501
+ data,
502
+ output,
503
+ params=params,
504
+ software=software,
505
+ abundance=None,
506
+ annotation=annotation,
507
+ strict=strict,
508
+ fasta=fasta,
509
+ ),
510
+ output,
511
+ )
512
+
513
+
514
+ def _plugin_command(
515
+ target: str,
516
+ data: Data,
517
+ output: Annotated[Path, Parameter(help="New file in the plugin target's layout")],
518
+ /,
519
+ *,
520
+ params: Params = (),
521
+ software: Software = None,
522
+ fasta: Fasta = (),
523
+ sdrf: Sdrf = None,
524
+ strict: Strict = False,
525
+ ) -> int:
526
+ """APB2's levels as an installed plugin target's export rule declares them."""
527
+ return _write(
528
+ target,
529
+ _exported(
530
+ target,
531
+ data,
532
+ output,
533
+ params=params,
534
+ software=software,
535
+ abundance=None,
536
+ annotation=None,
537
+ strict=strict,
538
+ fasta=fasta,
539
+ sdrf=sdrf,
540
+ ),
541
+ output,
542
+ )
543
+
544
+
545
+ def add_plugin_commands() -> None:
546
+ """Give each installed plugin target without a command of its own a generated one."""
547
+ for target in Exporter.targets():
548
+ if target not in app:
549
+ app.command(
550
+ partial(_plugin_command, target),
551
+ name=target,
552
+ help=f"APB2's levels as the installed plugin target {target} declares them; each "
553
+ "level's primary layer becomes X.",
554
+ )
555
+
556
+
557
+ add_plugin_commands()
558
+
559
+
560
+ def main() -> None:
561
+ """Run the command line and exit with its status."""
562
+ sys.exit(app(sys.argv[1:]))