rawtrace-qc 0.1.0__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 (61) hide show
  1. rawtrace_qc/__init__.py +12 -0
  2. rawtrace_qc/cli/__init__.py +33 -0
  3. rawtrace_qc/cli/errors.py +70 -0
  4. rawtrace_qc/cli/extract.py +144 -0
  5. rawtrace_qc/cli/main.py +32 -0
  6. rawtrace_qc/cli/thermo.py +140 -0
  7. rawtrace_qc/discovery/__init__.py +53 -0
  8. rawtrace_qc/discovery/discover.py +584 -0
  9. rawtrace_qc/discovery/models.py +116 -0
  10. rawtrace_qc/discovery/policies.py +193 -0
  11. rawtrace_qc/discovery/registry.py +51 -0
  12. rawtrace_qc/environment.py +63 -0
  13. rawtrace_qc/errors.py +114 -0
  14. rawtrace_qc/extractors/__init__.py +9 -0
  15. rawtrace_qc/extractors/bruker.py +413 -0
  16. rawtrace_qc/extractors/common.py +114 -0
  17. rawtrace_qc/extractors/protocol.py +26 -0
  18. rawtrace_qc/extractors/thermo.py +276 -0
  19. rawtrace_qc/gui/__init__.py +13 -0
  20. rawtrace_qc/gui/app.py +2125 -0
  21. rawtrace_qc/gui/cache.py +200 -0
  22. rawtrace_qc/gui/config.py +190 -0
  23. rawtrace_qc/gui/patterns.py +123 -0
  24. rawtrace_qc/gui/reporting.py +324 -0
  25. rawtrace_qc/gui/resources/chevron-down-dark.svg +1 -0
  26. rawtrace_qc/gui/resources/chevron-down-light.svg +1 -0
  27. rawtrace_qc/gui/resources/perutz-ms-facility_logo-inverted.svg +61 -0
  28. rawtrace_qc/gui/resources/settings-icon.svg +5 -0
  29. rawtrace_qc/gui/resources/tool-icon.svg +4 -0
  30. rawtrace_qc/gui/resources/trash-icon.svg +7 -0
  31. rawtrace_qc/gui/resources/upload-icon.svg +6 -0
  32. rawtrace_qc/gui/theme.py +928 -0
  33. rawtrace_qc/gui/thermo_tool.py +614 -0
  34. rawtrace_qc/gui/workflow.py +304 -0
  35. rawtrace_qc/models.py +18 -0
  36. rawtrace_qc/processing/__init__.py +20 -0
  37. rawtrace_qc/processing/models.py +97 -0
  38. rawtrace_qc/processing/process.py +219 -0
  39. rawtrace_qc/py.typed +0 -0
  40. rawtrace_qc/report/__init__.py +32 -0
  41. rawtrace_qc/report/channels.py +48 -0
  42. rawtrace_qc/report/html.py +1674 -0
  43. rawtrace_qc/report/models.py +214 -0
  44. rawtrace_qc/report/prepare.py +287 -0
  45. rawtrace_qc/thermo/__init__.py +69 -0
  46. rawtrace_qc/thermo/installation.py +619 -0
  47. rawtrace_qc/thermo/license.py +191 -0
  48. rawtrace_qc/thermo/locator.py +520 -0
  49. rawtrace_qc/thermo/runner.py +224 -0
  50. rawtrace_qc/thermo/runtime.py +27 -0
  51. rawtrace_qc/thermo/specification.py +170 -0
  52. rawtrace_qc/traces/__init__.py +41 -0
  53. rawtrace_qc/traces/artifact.py +325 -0
  54. rawtrace_qc/traces/schema.py +139 -0
  55. rawtrace_qc/workflows/__init__.py +19 -0
  56. rawtrace_qc/workflows/extraction.py +225 -0
  57. rawtrace_qc-0.1.0.dist-info/METADATA +186 -0
  58. rawtrace_qc-0.1.0.dist-info/RECORD +61 -0
  59. rawtrace_qc-0.1.0.dist-info/WHEEL +4 -0
  60. rawtrace_qc-0.1.0.dist-info/entry_points.txt +4 -0
  61. rawtrace_qc-0.1.0.dist-info/licenses/LICENSE +202 -0
@@ -0,0 +1,12 @@
1
+ """Public package metadata for rawtrace-qc."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from importlib.metadata import PackageNotFoundError, version
6
+
7
+ try:
8
+ __version__ = version("rawtrace-qc")
9
+ except PackageNotFoundError:
10
+ __version__ = "0.1.0"
11
+
12
+ __all__ = ["__version__"]
@@ -0,0 +1,33 @@
1
+ """Command-line interface for rawtrace-qc."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import sys
6
+ from collections.abc import Sequence
7
+
8
+
9
+ def main(argv: Sequence[str] | None = None) -> int:
10
+ """Run the command-line application or report missing optional dependencies.
11
+
12
+ Args:
13
+ argv: Optional command arguments. Defaults to the process arguments.
14
+
15
+ Returns:
16
+ The selected command's process exit code, or `2` when the optional
17
+ Cyclopts dependency is missing.
18
+ """
19
+ try:
20
+ from rawtrace_qc.cli.main import run
21
+ except ModuleNotFoundError as error:
22
+ if error.name != "cyclopts":
23
+ raise
24
+ print(
25
+ "The rawtrace-qc CLI requires the optional 'cli' extra. Install it "
26
+ "with `uv sync --extra cli` or `pip install 'rawtrace-qc[cli]'`.",
27
+ file=sys.stderr,
28
+ )
29
+ return 2
30
+ return run(argv)
31
+
32
+
33
+ __all__ = ["main"]
@@ -0,0 +1,70 @@
1
+ """CLI error reporting and user guidance helpers."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import sys
6
+
7
+ from rawtrace_qc.errors import (
8
+ ThermoHelperError,
9
+ ThermoHelperInstallConflictError,
10
+ ThermoHelperLicenseError,
11
+ ThermoHelperNotFoundError,
12
+ ThermoHelperVersionError,
13
+ UnsupportedPlatformError,
14
+ )
15
+
16
+ CHECK_THERMO_SETUP = "Check setup with `rawtrace-qc thermo status`."
17
+
18
+
19
+ def print_cli_error(error: Exception, *, thermo: bool = False) -> None:
20
+ """Print a standardized CLI error message and actionable guidance to stderr.
21
+
22
+ Args:
23
+ error: The exception to format and display.
24
+ thermo: If True, include the fallback hint for Thermo-related operations
25
+ when the error is a `ThermoHelperError`. Defaults to False.
26
+ """
27
+ print(f"Error: {error}", file=sys.stderr)
28
+ hint = thermo_setup_hint(error)
29
+ if hint is None and thermo and isinstance(error, ThermoHelperError):
30
+ hint = CHECK_THERMO_SETUP
31
+ if hint is not None:
32
+ print(hint, file=sys.stderr)
33
+
34
+
35
+ def thermo_setup_hint(error: Exception) -> str | None:
36
+ """Return the setup step that resolves a Thermo helper error.
37
+
38
+ Args:
39
+ error: The exception to look up.
40
+
41
+ Returns:
42
+ The setup guidance, or None if `error` has no specific setup step.
43
+ """
44
+ if isinstance(error, ThermoHelperNotFoundError):
45
+ return (
46
+ "Install the helper with `rawtrace-qc thermo install` (or "
47
+ "`rawtrace-qc thermo install --from-zip PATH` offline), then review "
48
+ "and accept its terms with `rawtrace-qc thermo accept-license`."
49
+ )
50
+ if isinstance(error, ThermoHelperLicenseError):
51
+ return (
52
+ "Review and accept the displayed terms with "
53
+ "`rawtrace-qc thermo accept-license`."
54
+ )
55
+ if isinstance(error, ThermoHelperVersionError):
56
+ return (
57
+ "Replace it with the pinned helper version using "
58
+ "`rawtrace-qc thermo install --overwrite`."
59
+ )
60
+ if isinstance(error, ThermoHelperInstallConflictError):
61
+ return (
62
+ "Replace the existing installation with "
63
+ "`rawtrace-qc thermo install --overwrite`."
64
+ )
65
+ if isinstance(error, UnsupportedPlatformError):
66
+ return (
67
+ "Thermo .raw extraction is not supported on this system; see the "
68
+ "supported runtimes above."
69
+ )
70
+ return None
@@ -0,0 +1,144 @@
1
+ """Batch raw-acquisition extraction command."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+ from typing import Annotated, Literal
7
+
8
+ from cyclopts import Parameter, validators
9
+
10
+ from rawtrace_qc.cli.errors import (
11
+ CHECK_THERMO_SETUP,
12
+ print_cli_error,
13
+ thermo_setup_hint,
14
+ )
15
+ from rawtrace_qc.discovery import DiscoveryOptions
16
+ from rawtrace_qc.errors import RawtraceError, ThermoHelperError
17
+ from rawtrace_qc.workflows import (
18
+ BatchExtractionOutcome,
19
+ BatchExtractionResult,
20
+ ExtractionOutcomeStatus,
21
+ extract_batch,
22
+ )
23
+
24
+ _BYTES_PER_MB = 1024 * 1024
25
+
26
+
27
+ def extract(
28
+ paths: Annotated[list[Path], Parameter(name="PATH")],
29
+ /,
30
+ *,
31
+ recursive: Annotated[bool, Parameter(negative_bool=(), show_default=False)] = False,
32
+ output_dir: Path | None = None,
33
+ precision: Literal["low", "high"] = "low",
34
+ ms1: Annotated[bool, Parameter(negative_bool=(), show_default=False)] = False,
35
+ msn: Annotated[bool, Parameter(negative_bool=(), show_default=False)] = False,
36
+ min_age_minutes: Annotated[
37
+ float, Parameter(validator=validators.Number(gte=0))
38
+ ] = 0,
39
+ min_size_mb: Annotated[float, Parameter(validator=validators.Number(gte=0))] = 0,
40
+ ) -> int:
41
+ """Extract scan traces from acquisition paths or directories.
42
+
43
+ With neither MS-level flag, both levels are selected. Setting both flags
44
+ also selects both levels.
45
+
46
+ Args:
47
+ paths: Acquisition files, folders, or quoted glob patterns.
48
+ recursive: Also scan subfolders.
49
+ output_dir: Write all traces to this folder. By default, traces are
50
+ written beside each acquisition.
51
+ precision: Trace precision: `low` (float32) or `high` (float64).
52
+ ms1: Extract only MS1 traces. By default, both MS1 and MSn are extracted.
53
+ msn: Extract only MSn traces. By default, both MS1 and MSn are extracted.
54
+ min_age_minutes: Skip acquisitions modified less than this many minutes
55
+ ago. `0` turns the check off.
56
+ min_size_mb: Skip acquisitions smaller than this many MB. `0` turns the
57
+ check off.
58
+
59
+ Returns:
60
+ Exit code zero only when all candidates succeed and there are no
61
+ discovery issues. Acquisitions skipped by discovery are reported without
62
+ affecting the exit code, unless they leave an input with no candidates.
63
+ """
64
+ select_both_levels = not ms1 and not msn
65
+ try:
66
+ result = extract_batch(
67
+ paths,
68
+ recursive=recursive,
69
+ output_directory=output_dir,
70
+ precision_mode=precision,
71
+ select_ms1=ms1 or select_both_levels,
72
+ select_msn=msn or select_both_levels,
73
+ discovery_options=DiscoveryOptions(
74
+ min_size_bytes=int(min_size_mb * _BYTES_PER_MB),
75
+ min_age_seconds=min_age_minutes * 60,
76
+ ),
77
+ )
78
+ except RawtraceError as error:
79
+ print_cli_error(error)
80
+ return 1
81
+
82
+ _print_batch_result(result)
83
+ return result.exit_code
84
+
85
+
86
+ def _print_batch_result(result: BatchExtractionResult) -> None:
87
+ rows = [(skip.path, "skipped", [skip.message]) for skip in result.discovery_skips]
88
+ helper_errors: dict[type[Exception], Exception] = {}
89
+ for outcome in result.outcomes:
90
+ rows.append(
91
+ (outcome.candidate.path, outcome.status.value, _outcome_details(outcome))
92
+ )
93
+ if outcome.error is not None and _is_helper_problem(outcome):
94
+ helper_errors.setdefault(type(outcome.error), outcome.error)
95
+
96
+ for path, status, details in sorted(rows, key=lambda row: row[0]):
97
+ print(f"{status}: {path}")
98
+ for detail in details:
99
+ print(f" {detail}")
100
+
101
+ if helper_errors:
102
+ print("Thermo setup:")
103
+ for error in helper_errors.values():
104
+ print(f" {error}")
105
+ print(f" {thermo_setup_hint(error) or CHECK_THERMO_SETUP}")
106
+
107
+ for issue in result.discovery_issues:
108
+ print(f"{issue.path}: {issue.message}")
109
+
110
+ succeeded = sum(
111
+ outcome.status is ExtractionOutcomeStatus.SUCCEEDED
112
+ for outcome in result.outcomes
113
+ )
114
+ skipped = len(result.discovery_skips) + sum(
115
+ outcome.status is ExtractionOutcomeStatus.SKIPPED for outcome in result.outcomes
116
+ )
117
+ failed = sum(
118
+ outcome.status is ExtractionOutcomeStatus.FAILED for outcome in result.outcomes
119
+ )
120
+ print(
121
+ f"Summary: {succeeded} succeeded, {skipped} skipped, {failed} failed, "
122
+ f"{len(result.discovery_issues)} discovery issue(s)."
123
+ )
124
+
125
+
126
+ def _outcome_details(outcome: BatchExtractionOutcome) -> list[str]:
127
+ if _is_helper_problem(outcome):
128
+ return ["Thermo helper is not ready."]
129
+ if outcome.error is not None:
130
+ return [str(outcome.error)]
131
+ if outcome.result is None:
132
+ return []
133
+ details = []
134
+ if outcome.result.ms1_path is not None:
135
+ details.append(f"MS1: {outcome.result.ms1_path}")
136
+ if outcome.result.msn_path is not None:
137
+ details.append(f"MSn: {outcome.result.msn_path}")
138
+ return details
139
+
140
+
141
+ def _is_helper_problem(outcome: BatchExtractionOutcome) -> bool:
142
+ return outcome.status is ExtractionOutcomeStatus.SKIPPED or isinstance(
143
+ outcome.error, ThermoHelperError
144
+ )
@@ -0,0 +1,32 @@
1
+ """Main command-line application definition."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Sequence
6
+
7
+ from cyclopts import App
8
+
9
+ app = App(name="rawtrace-qc", help="Command-line interface for rawtrace-qc.")
10
+ app.command(
11
+ "rawtrace_qc.cli.thermo:thermo_app",
12
+ name="thermo",
13
+ help="Manage ThermoScanHeaderExtractor setup.",
14
+ )
15
+ app.command(
16
+ "rawtrace_qc.cli.extract:extract",
17
+ name="extract",
18
+ help="Extract traces from Thermo and Bruker acquisitions.",
19
+ )
20
+
21
+
22
+ def run(argv: Sequence[str] | None = None) -> int:
23
+ """Run the command-line application.
24
+
25
+ Args:
26
+ argv: Optional command arguments. Defaults to the process arguments.
27
+
28
+ Returns:
29
+ The selected command's process exit code.
30
+ """
31
+ result = app(argv, result_action="return_value")
32
+ return result if isinstance(result, int) else 0
@@ -0,0 +1,140 @@
1
+ """ThermoScanHeaderExtractor CLI commands."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+
7
+ from cyclopts import App
8
+
9
+ from rawtrace_qc.cli.errors import print_cli_error
10
+ from rawtrace_qc.errors import ThermoHelperError
11
+ from rawtrace_qc.thermo import (
12
+ ThermoHelperState,
13
+ accept_thermo_license,
14
+ get_thermo_helper_status,
15
+ get_thermo_license_text,
16
+ install_thermo_helper,
17
+ )
18
+
19
+ thermo_app = App(name="thermo", help="Manage ThermoScanHeaderExtractor setup.")
20
+
21
+
22
+ @thermo_app.command
23
+ def status(
24
+ *,
25
+ helper_path: Path | None = None,
26
+ data_directory: Path | None = None,
27
+ ) -> int:
28
+ """Show Thermo helper installation, version, and license status.
29
+
30
+ Args:
31
+ helper_path: Use this helper executable, or the helper in this folder.
32
+ data_directory: Use this application data folder instead of the default.
33
+
34
+ Returns:
35
+ Exit code `0` when the helper is ready, otherwise `1`.
36
+ """
37
+ helper_status = get_thermo_helper_status(
38
+ explicit_path=helper_path,
39
+ data_directory=data_directory,
40
+ )
41
+ print(f"Thermo helper status: {helper_status.state.value}")
42
+ print(helper_status.message)
43
+ if helper_status.is_ready:
44
+ return 0
45
+ print(_status_action(helper_status.state))
46
+ return 1
47
+
48
+
49
+ @thermo_app.command
50
+ def install(
51
+ *,
52
+ from_zip: Path | None = None,
53
+ data_directory: Path | None = None,
54
+ overwrite: bool = False,
55
+ ) -> int:
56
+ """Install the pinned helper from its release or a local ZIP archive.
57
+
58
+ Args:
59
+ from_zip: Install from this local ZIP instead of downloading it.
60
+ data_directory: Install into this application data folder instead of
61
+ the default.
62
+ overwrite: Replace whatever is already at the install location.
63
+
64
+ Returns:
65
+ Exit code `0` when installation succeeds, otherwise `1`.
66
+ """
67
+ try:
68
+ executable = install_thermo_helper(
69
+ archive_path=from_zip,
70
+ data_directory=data_directory,
71
+ overwrite=overwrite,
72
+ )
73
+ except ThermoHelperError as error:
74
+ print_cli_error(error, thermo=True)
75
+ return 1
76
+
77
+ print(f"Installed ThermoScanHeaderExtractor at {executable}")
78
+ print(
79
+ "Review the terms, then run `rawtrace-qc thermo accept-license` to accept them."
80
+ )
81
+ return 0
82
+
83
+
84
+ @thermo_app.command(name="accept-license")
85
+ def accept_license(
86
+ *,
87
+ helper_path: Path | None = None,
88
+ data_directory: Path | None = None,
89
+ ) -> int:
90
+ """Display the Thermo terms and explicitly record license acceptance.
91
+
92
+ Running this command is the user's explicit acceptance action. The helper
93
+ prints its terms before the library records acceptance.
94
+
95
+ Args:
96
+ helper_path: Use this helper executable, or the helper in this folder.
97
+ data_directory: Use this application data folder instead of the default.
98
+
99
+ Returns:
100
+ Exit code `0` when acceptance is recorded, otherwise `1`.
101
+ """
102
+ try:
103
+ terms = get_thermo_license_text(
104
+ explicit_path=helper_path,
105
+ data_directory=data_directory,
106
+ )
107
+ print("The following Thermo license terms will be accepted by this command:")
108
+ print(terms, end="" if terms.endswith("\n") else "\n")
109
+ accept_thermo_license(
110
+ explicit_path=helper_path,
111
+ data_directory=data_directory,
112
+ )
113
+ except ThermoHelperError as error:
114
+ print_cli_error(error, thermo=True)
115
+ return 1
116
+
117
+ print("Thermo license acceptance is recorded for the current user.")
118
+ return 0
119
+
120
+
121
+ def _status_action(state: ThermoHelperState) -> str:
122
+ actions = {
123
+ ThermoHelperState.NOT_INSTALLED: (
124
+ "Install it with `rawtrace-qc thermo install`; use `--from-zip PATH` "
125
+ "for an offline archive."
126
+ ),
127
+ ThermoHelperState.UNLICENSED: (
128
+ "Review and accept the terms with `rawtrace-qc thermo accept-license`."
129
+ ),
130
+ ThermoHelperState.INVALID_VERSION: (
131
+ "Replace it with the pinned helper version using "
132
+ "`rawtrace-qc thermo install --overwrite`."
133
+ ),
134
+ ThermoHelperState.UNSUPPORTED_PLATFORM: (
135
+ "Thermo .raw extraction and helper setup are not supported on this "
136
+ "system; see the supported runtimes above."
137
+ ),
138
+ ThermoHelperState.READY: "",
139
+ }
140
+ return actions[state]
@@ -0,0 +1,53 @@
1
+ """Discover and validate vendor-specific raw mass-spectrometry acquisitions."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from rawtrace_qc.discovery.discover import (
6
+ discover,
7
+ discover_inputs,
8
+ inspect_path,
9
+ resolve_input_path_pattern,
10
+ validate_path,
11
+ )
12
+ from rawtrace_qc.discovery.models import (
13
+ DiscoveryCandidate,
14
+ DiscoveryIssue,
15
+ DiscoveryOptions,
16
+ DiscoveryResult,
17
+ DiscoveryScope,
18
+ SkippedAcquisition,
19
+ SkipReason,
20
+ TraversalIssue,
21
+ TraversalTree,
22
+ ValidationResult,
23
+ )
24
+ from rawtrace_qc.discovery.policies import (
25
+ FileFormat,
26
+ Vendor,
27
+ validate_bruker,
28
+ validate_thermo,
29
+ )
30
+ from rawtrace_qc.discovery.registry import DiscoveryRegistry
31
+
32
+ __all__ = [
33
+ "DiscoveryCandidate",
34
+ "DiscoveryIssue",
35
+ "DiscoveryOptions",
36
+ "DiscoveryRegistry",
37
+ "DiscoveryResult",
38
+ "DiscoveryScope",
39
+ "FileFormat",
40
+ "SkipReason",
41
+ "SkippedAcquisition",
42
+ "TraversalIssue",
43
+ "TraversalTree",
44
+ "ValidationResult",
45
+ "Vendor",
46
+ "discover",
47
+ "discover_inputs",
48
+ "inspect_path",
49
+ "resolve_input_path_pattern",
50
+ "validate_bruker",
51
+ "validate_path",
52
+ "validate_thermo",
53
+ ]