samplesheet-parser 0.3.4__tar.gz → 1.0.0__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 (70) hide show
  1. samplesheet_parser-1.0.0/.pre-commit-config.yaml +29 -0
  2. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/CHANGELOG.md +45 -0
  3. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/PKG-INFO +3 -3
  4. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/README.md +1 -1
  5. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/pyproject.toml +5 -2
  6. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/samplesheet_parser/__init__.py +4 -2
  7. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/samplesheet_parser/cli.py +87 -79
  8. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/samplesheet_parser/factory.py +6 -4
  9. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/samplesheet_parser/index_utils.py +3 -2
  10. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/samplesheet_parser/merger.py +85 -62
  11. samplesheet_parser-1.0.0/tests/test_validators/__init__.py +0 -0
  12. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/.github/workflows/ci.yml +0 -0
  13. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/.github/workflows/copilot-instructions.md +0 -0
  14. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/.gitignore +0 -0
  15. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/.zenodo.json +0 -0
  16. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/CITATION.cff +0 -0
  17. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/CONTRIBUTING.md +0 -0
  18. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/LICENSE +0 -0
  19. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/examples/demo_merger.py +0 -0
  20. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/examples/parse_examples.py +0 -0
  21. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/examples/sample_sheets/ProjectAlpha_SampleSheet.csv +0 -0
  22. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/examples/sample_sheets/ProjectBeta_SampleSheet.csv +0 -0
  23. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/examples/sample_sheets/ProjectDelta_SampleSheet_collision.csv +0 -0
  24. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/examples/sample_sheets/ProjectGamma_SampleSheet.csv +0 -0
  25. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/examples/sample_sheets/README.md +0 -0
  26. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/examples/sample_sheets/combined_clean.csv +0 -0
  27. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/examples/sample_sheets/combined_collision_forced.csv +0 -0
  28. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/examples/sample_sheets/combined_mixed_formats.csv +0 -0
  29. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/examples/sample_sheets/v1_dual_index.csv +0 -0
  30. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/examples/sample_sheets/v1_multi_lane.csv +0 -0
  31. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/examples/sample_sheets/v1_single_index.csv +0 -0
  32. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/examples/sample_sheets/v1_with_lab_qc_settings.csv +0 -0
  33. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/examples/sample_sheets/v1_with_manifests.csv +0 -0
  34. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/examples/sample_sheets/v2_nextseq_single_index.csv +0 -0
  35. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/examples/sample_sheets/v2_novaseq_x_dual_index.csv +0 -0
  36. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/examples/sample_sheets/v2_with_cloud_settings.csv +0 -0
  37. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/examples/sample_sheets/v2_with_index_umi.csv +0 -0
  38. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/examples/sample_sheets/v2_with_pipeline_settings.csv +0 -0
  39. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/examples/sample_sheets/v2_with_read_umi.csv +0 -0
  40. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/images/samplesheet_parser_arch_v03.png +0 -0
  41. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/images/samplesheet_parser_overview.png +0 -0
  42. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/samplesheet_parser/converter.py +0 -0
  43. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/samplesheet_parser/diff.py +0 -0
  44. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/samplesheet_parser/enums.py +0 -0
  45. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/samplesheet_parser/parsers/__init__.py +0 -0
  46. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/samplesheet_parser/parsers/v1.py +0 -0
  47. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/samplesheet_parser/parsers/v2.py +0 -0
  48. /samplesheet_parser-0.3.4/tests/__init__.py → /samplesheet_parser-1.0.0/samplesheet_parser/py.typed +0 -0
  49. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/samplesheet_parser/validators.py +0 -0
  50. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/samplesheet_parser/writer.py +0 -0
  51. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/scripts/demo_converter.py +0 -0
  52. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/scripts/demo_diff.py +0 -0
  53. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/scripts/demo_writer.py +0 -0
  54. {samplesheet_parser-0.3.4/tests/test_parsers → samplesheet_parser-1.0.0/tests}/__init__.py +0 -0
  55. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/tests/conftest.py +0 -0
  56. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/tests/fixtures/SampleSheet_v1_dual_index.csv +0 -0
  57. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/tests/fixtures/SampleSheet_v2_dual_index.csv +0 -0
  58. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/tests/fixtures/SampleSheet_v2_modified.csv +0 -0
  59. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/tests/test_cli.py +0 -0
  60. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/tests/test_converter.py +0 -0
  61. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/tests/test_diff.py +0 -0
  62. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/tests/test_factory.py +0 -0
  63. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/tests/test_index_utils.py +0 -0
  64. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/tests/test_merger.py +0 -0
  65. {samplesheet_parser-0.3.4/tests/test_validators → samplesheet_parser-1.0.0/tests/test_parsers}/__init__.py +0 -0
  66. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/tests/test_parsers/test_v1.py +0 -0
  67. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/tests/test_parsers/test_v2.py +0 -0
  68. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/tests/test_validators/test_hamming.py +0 -0
  69. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/tests/test_validators/test_validators.py +0 -0
  70. {samplesheet_parser-0.3.4 → samplesheet_parser-1.0.0}/tests/test_writer.py +0 -0
@@ -0,0 +1,29 @@
1
+ repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v5.0.0
4
+ hooks:
5
+ - id: trailing-whitespace
6
+ - id: end-of-file-fixer
7
+ - id: check-yaml
8
+ - id: check-toml
9
+ - id: check-merge-conflict
10
+ - id: check-added-large-files
11
+
12
+ - repo: https://github.com/psf/black
13
+ rev: 24.10.0
14
+ hooks:
15
+ - id: black
16
+ language_version: python3.12
17
+
18
+ - repo: https://github.com/astral-sh/ruff-pre-commit
19
+ rev: v0.9.0
20
+ hooks:
21
+ - id: ruff
22
+ args: [--fix]
23
+
24
+ - repo: https://github.com/pre-commit/mirrors-mypy
25
+ rev: v1.13.0
26
+ hooks:
27
+ - id: mypy
28
+ additional_dependencies: [loguru, typer]
29
+ args: [--ignore-missing-imports]
@@ -6,6 +6,51 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
6
6
 
7
7
  ---
8
8
 
9
+ ## [1.0.0] - 2026-04-05
10
+
11
+ ### Added
12
+
13
+ - **`py.typed` marker** — package now ships inline type information per
14
+ PEP 561, enabling mypy and pyright to type-check downstream code without
15
+ extra configuration.
16
+
17
+ - **`InstrumentPlatform` and `UMILocation` enums exported** — both were
18
+ already defined in `enums.py` but not part of the public API. They are now
19
+ importable directly from the top-level package and listed in `__all__`.
20
+
21
+ - **`.pre-commit-config.yaml`** — pre-commit hook configuration included in
22
+ the repository (black, ruff with `--fix`, mypy, and standard file hygiene
23
+ hooks) so contributors get the same checks locally that CI enforces.
24
+
25
+ ### Fixed
26
+
27
+ - `SampleSheetFactory.create_parser()` now returns a typed local variable
28
+ instead of `self.parser`, resolving a mypy `return-value` error caused by
29
+ the instance attribute being typed as `SampleSheetV1 | SampleSheetV2 | None`.
30
+
31
+ - `SampleSheetMerger._parse_all()` guards against `factory.version` being
32
+ `None` before accessing `.value`, fixing a potential `AttributeError` on
33
+ unexpected parse paths.
34
+
35
+ - Removed redundant `type: ignore[assignment]` suppressions in
36
+ `index_utils.py` that were no longer needed under strict mypy.
37
+
38
+ ### Changed
39
+
40
+ - Development status classifier updated from `3 - Alpha` to
41
+ `5 - Production/Stable`.
42
+
43
+ - Ruff config adds `[tool.ruff.lint.per-file-ignores]` to suppress E402 for
44
+ `samplesheet_parser/__init__.py`, where the version-detection block
45
+ intentionally precedes the package re-exports.
46
+
47
+ - **Stability guarantee** — `1.0.0` marks the first stable release.
48
+ The public API (all names in `__init__.__all__`) is now subject to
49
+ semantic versioning: breaking changes will not be made without a major
50
+ version bump.
51
+
52
+ ---
53
+
9
54
  ## [0.3.4] - 2026-04-04
10
55
 
11
56
  ### Added
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: samplesheet-parser
3
- Version: 0.3.4
3
+ Version: 1.0.0
4
4
  Summary: Format-agnostic parser for Illumina SampleSheet.csv files — supports IEM V1 and BCLConvert V2
5
5
  Project-URL: Homepage, https://github.com/chaitanyakasaraneni/samplesheet-parser
6
6
  Project-URL: Documentation, https://illumina-samplesheet.readthedocs.io
@@ -28,7 +28,7 @@ License: Apache License
28
28
  limitations under the License.
29
29
  License-File: LICENSE
30
30
  Keywords: bcl2fastq,bclconvert,bioinformatics,demultiplexing,genomics,illumina,ngs,samplesheet,sequencing
31
- Classifier: Development Status :: 3 - Alpha
31
+ Classifier: Development Status :: 5 - Production/Stable
32
32
  Classifier: Intended Audience :: Developers
33
33
  Classifier: Intended Audience :: Science/Research
34
34
  Classifier: License :: OSI Approved :: Apache Software License
@@ -659,7 +659,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for the full local testing guide and PR c
659
659
  title = {samplesheet-parser: Format-agnostic parser for Illumina SampleSheet.csv},
660
660
  year = {2026},
661
661
  url = {https://github.com/chaitanyakasaraneni/samplesheet-parser},
662
- version = {0.3.4}
662
+ version = {1.0.0}
663
663
  }
664
664
  ```
665
665
 
@@ -608,7 +608,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for the full local testing guide and PR c
608
608
  title = {samplesheet-parser: Format-agnostic parser for Illumina SampleSheet.csv},
609
609
  year = {2026},
610
610
  url = {https://github.com/chaitanyakasaraneni/samplesheet-parser},
611
- version = {0.3.4}
611
+ version = {1.0.0}
612
612
  }
613
613
  ```
614
614
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "samplesheet-parser"
7
- version = "0.3.4"
7
+ version = "1.0.0"
8
8
  description = "Format-agnostic parser for Illumina SampleSheet.csv files — supports IEM V1 and BCLConvert V2"
9
9
  readme = "README.md"
10
10
  license = { file = "LICENSE" }
@@ -14,7 +14,7 @@ keywords = [
14
14
  "genomics", "bioinformatics", "demultiplexing", "sequencing",
15
15
  ]
16
16
  classifiers = [
17
- "Development Status :: 3 - Alpha",
17
+ "Development Status :: 5 - Production/Stable",
18
18
  "Intended Audience :: Science/Research",
19
19
  "Intended Audience :: Developers",
20
20
  "License :: OSI Approved :: Apache Software License",
@@ -62,6 +62,9 @@ target-version = "py312"
62
62
  [tool.ruff.lint]
63
63
  select = ["E", "F", "I", "W", "UP", "B"]
64
64
 
65
+ [tool.ruff.lint.per-file-ignores]
66
+ "samplesheet_parser/__init__.py" = ["E402"]
67
+
65
68
  [tool.mypy]
66
69
  python_version = "3.12"
67
70
  strict = true
@@ -29,12 +29,12 @@ except PackageNotFoundError:
29
29
  __version__ = "0.1.0-dev"
30
30
 
31
31
  __author__ = "Chaitanya Kasaraneni"
32
- __email__ = "kc.kasaraneni@gmail.com"
32
+ __email__ = "kc.kasaraneni@gmail.com"
33
33
  __license__ = "Apache 2.0"
34
34
 
35
35
  from samplesheet_parser.converter import SampleSheetConverter
36
36
  from samplesheet_parser.diff import DiffResult, SampleSheetDiff
37
- from samplesheet_parser.enums import IndexType, SampleSheetVersion
37
+ from samplesheet_parser.enums import IndexType, InstrumentPlatform, SampleSheetVersion, UMILocation
38
38
  from samplesheet_parser.factory import SampleSheetFactory
39
39
  from samplesheet_parser.index_utils import normalize_index_lengths
40
40
  from samplesheet_parser.merger import MergeResult, SampleSheetMerger
@@ -49,6 +49,8 @@ __all__ = [
49
49
  "SampleSheetFactory",
50
50
  "SampleSheetVersion",
51
51
  "IndexType",
52
+ "InstrumentPlatform",
53
+ "UMILocation",
52
54
  "SampleSheetValidator",
53
55
  "ValidationResult",
54
56
  "SampleSheetConverter",
@@ -50,6 +50,7 @@ from typing import Annotated
50
50
 
51
51
  try:
52
52
  import typer
53
+
53
54
  _TYPER_AVAILABLE = True
54
55
  except ImportError: # pragma: no cover
55
56
  _TYPER_AVAILABLE = False
@@ -167,24 +168,24 @@ if _TYPER_AVAILABLE:
167
168
  else:
168
169
  reads_dict = sheet.reads or {}
169
170
  read_lengths = [
170
- str(reads_dict[k])
171
- for k in ("Read1Cycles", "Read2Cycles")
172
- if k in reads_dict
171
+ str(reads_dict[k]) for k in ("Read1Cycles", "Read2Cycles") if k in reads_dict
173
172
  ]
174
173
  instrument = sheet.instrument_platform
175
174
 
176
175
  if fmt == "json":
177
- _print_json({
178
- "file": str(path),
179
- "format": factory.version.value,
180
- "sample_count": len(samples),
181
- "lanes": lanes,
182
- "index_type": index_type,
183
- "read_lengths": read_lengths,
184
- "adapters": adapters,
185
- "experiment_name": experiment_name,
186
- "instrument": instrument,
187
- })
176
+ _print_json(
177
+ {
178
+ "file": str(path),
179
+ "format": factory.version.value,
180
+ "sample_count": len(samples),
181
+ "lanes": lanes,
182
+ "index_type": index_type,
183
+ "read_lengths": read_lengths,
184
+ "adapters": adapters,
185
+ "experiment_name": experiment_name,
186
+ "instrument": instrument,
187
+ }
188
+ )
188
189
  else:
189
190
  typer.echo(f"File: {path}")
190
191
  typer.echo(f"Format: {factory.version.value}")
@@ -233,9 +234,7 @@ if _TYPER_AVAILABLE:
233
234
 
234
235
  _validate_fmt(fmt)
235
236
  if min_hamming < 1:
236
- typer.echo(
237
- f"Error: --min-hamming must be >= 1, got {min_hamming}.", err=True
238
- )
237
+ typer.echo(f"Error: --min-hamming must be >= 1, got {min_hamming}.", err=True)
239
238
  raise typer.Exit(code=2)
240
239
  if not path.exists():
241
240
  typer.echo(f"Error: file not found: {path}", err=True)
@@ -255,21 +254,23 @@ if _TYPER_AVAILABLE:
255
254
  result = SampleSheetValidator().validate(sheet, min_hamming_distance=min_hamming)
256
255
 
257
256
  if fmt == "json":
258
- _print_json({
259
- "file": str(path),
260
- "version": version.value,
261
- "is_valid": result.is_valid,
262
- "min_hamming_distance": min_hamming,
263
- "errors": [
264
- {"code": e.code, "message": e.message, "context": e.context}
265
- for e in result.errors
266
- ],
267
- "warnings": [
268
- {"code": w.code, "message": w.message, "context": w.context}
269
- for w in result.warnings
270
- ],
271
- "summary": result.summary(),
272
- })
257
+ _print_json(
258
+ {
259
+ "file": str(path),
260
+ "version": version.value,
261
+ "is_valid": result.is_valid,
262
+ "min_hamming_distance": min_hamming,
263
+ "errors": [
264
+ {"code": e.code, "message": e.message, "context": e.context}
265
+ for e in result.errors
266
+ ],
267
+ "warnings": [
268
+ {"code": w.code, "message": w.message, "context": w.context}
269
+ for w in result.warnings
270
+ ],
271
+ "summary": result.summary(),
272
+ }
273
+ )
273
274
  else:
274
275
  typer.echo(f"File: {path}")
275
276
  typer.echo(f"Format: {version.value}")
@@ -325,8 +326,7 @@ if _TYPER_AVAILABLE:
325
326
  if converter.source_version is None: # pragma: no cover
326
327
  raise RuntimeError("SampleSheetConverter.source_version must be set after conversion")
327
328
  typer.echo(
328
- f"Converted {path.name} ({converter.source_version.value})"
329
- f" → {out} ({target.value})"
329
+ f"Converted {path.name} ({converter.source_version.value})" f" → {out} ({target.value})"
330
330
  )
331
331
 
332
332
  # ---------------------------------------------------------------------------
@@ -360,29 +360,30 @@ if _TYPER_AVAILABLE:
360
360
  raise typer.Exit(code=2) from exc
361
361
 
362
362
  if fmt == "json":
363
- _print_json({
364
- "has_changes": result.has_changes,
365
- "source_version": result.source_version.value,
366
- "target_version": result.target_version.value,
367
- "summary": result.summary(),
368
- "header_changes": [
369
- {"field": c.field, "old": c.old_value, "new": c.new_value}
370
- for c in result.header_changes
371
- ],
372
- "samples_added": result.samples_added,
373
- "samples_removed": result.samples_removed,
374
- "sample_changes": [
375
- {
376
- "sample_id": sc.sample_id,
377
- "lane": sc.lane,
378
- "changes": {
379
- f: {"old": o, "new": n}
380
- for f, (o, n) in sc.changes.items()
381
- },
382
- }
383
- for sc in result.sample_changes
384
- ],
385
- })
363
+ _print_json(
364
+ {
365
+ "has_changes": result.has_changes,
366
+ "source_version": result.source_version.value,
367
+ "target_version": result.target_version.value,
368
+ "summary": result.summary(),
369
+ "header_changes": [
370
+ {"field": c.field, "old": c.old_value, "new": c.new_value}
371
+ for c in result.header_changes
372
+ ],
373
+ "samples_added": result.samples_added,
374
+ "samples_removed": result.samples_removed,
375
+ "sample_changes": [
376
+ {
377
+ "sample_id": sc.sample_id,
378
+ "lane": sc.lane,
379
+ "changes": {
380
+ f: {"old": o, "new": n} for f, (o, n) in sc.changes.items()
381
+ },
382
+ }
383
+ for sc in result.sample_changes
384
+ ],
385
+ }
386
+ )
386
387
  else:
387
388
  typer.echo(result.summary())
388
389
 
@@ -426,10 +427,13 @@ if _TYPER_AVAILABLE:
426
427
  output: _OutputOption = Path("SampleSheet_combined.csv"),
427
428
  to: _VersionOption = "v2",
428
429
  fmt: _FormatOption = "text",
429
- force: Annotated[bool, typer.Option(
430
- "--force",
431
- help="Write output even if conflicts are found.",
432
- )] = False,
430
+ force: Annotated[
431
+ bool,
432
+ typer.Option(
433
+ "--force",
434
+ help="Write output even if conflicts are found.",
435
+ ),
436
+ ] = False,
433
437
  ) -> None:
434
438
  """Merge multiple per-project sample sheets into one combined sheet.
435
439
 
@@ -469,21 +473,23 @@ if _TYPER_AVAILABLE:
469
473
  raise typer.Exit(code=2) from exc
470
474
 
471
475
  if fmt == "json":
472
- _print_json({
473
- "has_conflicts": result.has_conflicts,
474
- "sample_count": result.sample_count,
475
- "output_path": str(result.output_path) if result.output_path else None,
476
- "source_versions": result.source_versions,
477
- "summary": result.summary(),
478
- "conflicts": [
479
- {"code": c.code, "message": c.message, "context": c.context}
480
- for c in result.conflicts
481
- ],
482
- "warnings": [
483
- {"code": w.code, "message": w.message, "context": w.context}
484
- for w in result.warnings
485
- ],
486
- })
476
+ _print_json(
477
+ {
478
+ "has_conflicts": result.has_conflicts,
479
+ "sample_count": result.sample_count,
480
+ "output_path": str(result.output_path) if result.output_path else None,
481
+ "source_versions": result.source_versions,
482
+ "summary": result.summary(),
483
+ "conflicts": [
484
+ {"code": c.code, "message": c.message, "context": c.context}
485
+ for c in result.conflicts
486
+ ],
487
+ "warnings": [
488
+ {"code": w.code, "message": w.message, "context": w.context}
489
+ for w in result.warnings
490
+ ],
491
+ }
492
+ )
487
493
  else:
488
494
  typer.echo(result.summary())
489
495
 
@@ -506,19 +512,21 @@ if _TYPER_AVAILABLE:
506
512
  else: # pragma: no cover
507
513
  # Fallbacks when Typer is not installed: keep simple type aliases so that
508
514
  # the module can be imported and type annotations remain usable.
509
- _FormatOption = str # type: ignore[assignment,misc]
510
- _OutputOption = Path # type: ignore[assignment,misc]
511
- _VersionOption = str # type: ignore[assignment,misc]
515
+ _FormatOption = str # type: ignore[misc]
516
+ _OutputOption = Path # type: ignore[misc]
517
+ _VersionOption = str # type: ignore[misc]
512
518
 
513
519
 
514
520
  # ---------------------------------------------------------------------------
515
521
  # Entry point
516
522
  # ---------------------------------------------------------------------------
517
523
 
524
+
518
525
  def main() -> None: # pragma: no cover
519
526
  """Entry point for the ``samplesheet`` CLI command."""
520
527
  if not _TYPER_AVAILABLE:
521
528
  import sys
529
+
522
530
  sys.stderr.write(
523
531
  "Error: the samplesheet-parser CLI requires 'typer'.\n"
524
532
  "Install it with: pip install 'samplesheet-parser[cli]'\n"
@@ -68,7 +68,7 @@ class SampleSheetFactory:
68
68
 
69
69
  def __init__(self) -> None:
70
70
  self.version: SampleSheetVersion | None = None
71
- self.parser: SampleSheetV1 | SampleSheetV2 | None = None
71
+ self.parser: SampleSheetV1 | SampleSheetV2 | None = None
72
72
 
73
73
  # ------------------------------------------------------------------
74
74
  # Public API
@@ -124,14 +124,16 @@ class SampleSheetFactory:
124
124
  self.version = detected
125
125
  kwargs: dict[str, Any] = dict(clean=clean, experiment_id=experiment_id, parse=parse)
126
126
 
127
+ parser: SampleSheetV1 | SampleSheetV2
127
128
  if detected == SampleSheetVersion.V2:
128
129
  logger.info("Detected BCLConvert V2 format — using SampleSheetV2")
129
- self.parser = SampleSheetV2(path, **kwargs)
130
+ parser = SampleSheetV2(path, **kwargs)
130
131
  else:
131
132
  logger.info("Detected IEM V1 format — using SampleSheetV1")
132
- self.parser = SampleSheetV1(path, **kwargs)
133
+ parser = SampleSheetV1(path, **kwargs)
133
134
 
134
- return self.parser
135
+ self.parser = parser
136
+ return parser
135
137
 
136
138
  def get_umi_length(self) -> int:
137
139
  """Return the UMI length for the currently selected parser.
@@ -140,12 +140,12 @@ def normalize_index_lengths(
140
140
  out = dict(sample)
141
141
 
142
142
  if index1_key and target_i1:
143
- v1: str | None = out.get(index1_key) # type: ignore[assignment]
143
+ v1: str | None = out.get(index1_key)
144
144
  if v1:
145
145
  out[index1_key] = _apply(v1, target_i1, strategy)
146
146
 
147
147
  if index2_key and target_i2:
148
- v2: str | None = out.get(index2_key) # type: ignore[assignment]
148
+ v2: str | None = out.get(index2_key)
149
149
  if v2:
150
150
  out[index2_key] = _apply(v2, target_i2, strategy)
151
151
 
@@ -158,6 +158,7 @@ def normalize_index_lengths(
158
158
  # Helpers
159
159
  # ---------------------------------------------------------------------------
160
160
 
161
+
161
162
  def _detect_key(samples: list[dict[str, Any]], candidates: tuple[str, ...]) -> str:
162
163
  """Return the first candidate key that has at least one non-empty value.
163
164
 
@@ -51,6 +51,7 @@ from samplesheet_parser.validators import (
51
51
  # Result types
52
52
  # ---------------------------------------------------------------------------
53
53
 
54
+
54
55
  @dataclass
55
56
  class MergeConflict:
56
57
  """A single error or warning produced during a merge.
@@ -66,8 +67,9 @@ class MergeConflict:
66
67
  context:
67
68
  Optional dict with extra detail.
68
69
  """
69
- level: str
70
- code: str
70
+
71
+ level: str
72
+ code: str
71
73
  message: str
72
74
  context: dict[str, Any] = field(default_factory=dict)
73
75
 
@@ -96,11 +98,12 @@ class MergeResult:
96
98
  source_versions:
97
99
  Format version detected for each input file, keyed by file path.
98
100
  """
99
- has_conflicts: bool = False
100
- conflicts: list[MergeConflict] = field(default_factory=list)
101
- warnings: list[MergeConflict] = field(default_factory=list)
102
- output_path: Path | None = None
103
- sample_count: int = 0
101
+
102
+ has_conflicts: bool = False
103
+ conflicts: list[MergeConflict] = field(default_factory=list)
104
+ warnings: list[MergeConflict] = field(default_factory=list)
105
+ output_path: Path | None = None
106
+ sample_count: int = 0
104
107
  source_versions: dict[str, str] = field(default_factory=dict)
105
108
 
106
109
  def add_conflict(self, code: str, message: str, **context: Any) -> None:
@@ -130,20 +133,25 @@ class MergeResult:
130
133
 
131
134
  # Validator codes that are fully covered by a pre-merge cross-sheet check
132
135
  # and must be suppressed in _validate_merged() to avoid duplicate reporting.
133
- _PRE_MERGE_CONFLICT_CODES: frozenset[str] = frozenset({
134
- "INDEX_COLLISION", # covered by _check_index_collisions
135
- "DUPLICATE_INDEX", # same root cause — validator sees result of collision
136
- })
136
+ _PRE_MERGE_CONFLICT_CODES: frozenset[str] = frozenset(
137
+ {
138
+ "INDEX_COLLISION", # covered by _check_index_collisions
139
+ "DUPLICATE_INDEX", # same root cause — validator sees result of collision
140
+ }
141
+ )
137
142
 
138
- _PRE_MERGE_WARNING_CODES: frozenset[str] = frozenset({
139
- "INDEX_DISTANCE_TOO_LOW", # covered by _check_index_distances
140
- })
143
+ _PRE_MERGE_WARNING_CODES: frozenset[str] = frozenset(
144
+ {
145
+ "INDEX_DISTANCE_TOO_LOW", # covered by _check_index_distances
146
+ }
147
+ )
141
148
 
142
149
 
143
150
  # ---------------------------------------------------------------------------
144
151
  # Merger
145
152
  # ---------------------------------------------------------------------------
146
153
 
154
+
147
155
  class SampleSheetMerger:
148
156
  """Combine multiple per-project SampleSheet.csv files for one flow cell.
149
157
 
@@ -298,10 +306,7 @@ class SampleSheetMerger:
298
306
  # ── 6. Write ─────────────────────────────────────────────────────
299
307
  out = writer.write(output_path, validate=False) # already validated above
300
308
  result.output_path = out
301
- logger.info(
302
- f"Merged {len(parsed)} sheet(s) → {out} "
303
- f"({result.sample_count} samples)"
304
- )
309
+ logger.info(f"Merged {len(parsed)} sheet(s) → {out} " f"({result.sample_count} samples)")
305
310
  return result
306
311
 
307
312
  # ------------------------------------------------------------------
@@ -323,9 +328,10 @@ class SampleSheetMerger:
323
328
  # cleaning could modify input sheets or create .backup files.
324
329
  sheet = factory.create_parser(str(p), parse=True, clean=False)
325
330
  parsed.append((p, sheet))
326
- versions_seen.add(factory.version)
327
- result.source_versions[str(p)] = factory.version.value
328
- logger.debug(f"Parsed {p} as {factory.version.value}")
331
+ if factory.version is not None:
332
+ versions_seen.add(factory.version)
333
+ result.source_versions[str(p)] = factory.version.value
334
+ logger.debug(f"Parsed {p} as {factory.version.value}")
329
335
  except Exception as exc:
330
336
  result.add_conflict(
331
337
  "PARSE_ERROR",
@@ -367,7 +373,7 @@ class SampleSheetMerger:
367
373
  # Use a fixed key order so [Read1Cycles=151, Read2Cycles=101]
368
374
  # and [Read2Cycles=101, Read1Cycles=151] produce the same key
369
375
  # and don't spuriously trigger READ_LENGTH_CONFLICT.
370
- lengths: list[int] = []
376
+ lengths = []
371
377
  for read_key in ("Read1Cycles", "Read2Cycles"):
372
378
  v = r.get(read_key)
373
379
  if v:
@@ -383,8 +389,7 @@ class SampleSheetMerger:
383
389
 
384
390
  if len(length_map) > 1:
385
391
  detail = "; ".join(
386
- f"{p.name}: {lens if lens else '(none)'}"
387
- for lens, p in length_map.values()
392
+ f"{p.name}: {lens if lens else '(none)'}" for lens, p in length_map.values()
388
393
  )
389
394
  result.add_conflict(
390
395
  "READ_LENGTH_CONFLICT",
@@ -413,9 +418,7 @@ class SampleSheetMerger:
413
418
  )
414
419
 
415
420
  for p, sheet in parsed[1:]:
416
- adapters = frozenset(
417
- a.upper() for a in (getattr(sheet, "adapters", []) or []) if a
418
- )
421
+ adapters = frozenset(a.upper() for a in (getattr(sheet, "adapters", []) or []) if a)
419
422
  # Only warn when both sheets have adapters and they differ; if
420
423
  # either sheet has no adapters, there is nothing to conflict.
421
424
  if adapters and primary_adapters and adapters != primary_adapters:
@@ -448,12 +451,12 @@ class SampleSheetMerger:
448
451
  # Prefer per-row records; fall back to samples() if unavailable.
449
452
  records = getattr(sheet, "records", None) or sheet.samples()
450
453
  for record in records:
451
- lane = record.get("lane") or record.get("Lane")
452
- idx1 = (record.get("index") or record.get("Index") or "").upper()
453
- idx2 = (record.get("index2") or record.get("Index2") or "").upper()
454
+ lane = record.get("lane") or record.get("Lane")
455
+ idx1 = (record.get("index") or record.get("Index") or "").upper()
456
+ idx2 = (record.get("index2") or record.get("Index2") or "").upper()
454
457
  raw_sid = record.get("sample_id") or record.get("Sample_ID")
455
- sid = raw_sid or "?"
456
- key = f"{idx1}+{idx2}" if idx2 else idx1
458
+ sid = raw_sid or "?"
459
+ key = f"{idx1}+{idx2}" if idx2 else idx1
457
460
 
458
461
  # Silently skip incomplete rows — _build_writer will emit
459
462
  # INCOMPLETE_SAMPLE_RECORD for them; no collision warning here.
@@ -498,9 +501,9 @@ class SampleSheetMerger:
498
501
  for p, sheet in parsed:
499
502
  records = getattr(sheet, "records", None) or sheet.samples()
500
503
  for record in records:
501
- lane = record.get("lane") or record.get("Lane")
502
- idx1 = (record.get("index") or record.get("Index") or "").upper()
503
- idx2 = (record.get("index2") or record.get("Index2") or "").upper()
504
+ lane = record.get("lane") or record.get("Lane")
505
+ idx1 = (record.get("index") or record.get("Index") or "").upper()
506
+ idx2 = (record.get("index2") or record.get("Index2") or "").upper()
504
507
  sid_raw = record.get("sample_id") or record.get("Sample_ID")
505
508
  # Skip records lacking a primary index or Sample_ID, to align
506
509
  # with _build_writer(), which does not include such rows.
@@ -588,22 +591,43 @@ class SampleSheetMerger:
588
591
  # Keys that belong in [Header]/[BCLConvert_Settings] or are handled
589
592
  # explicitly below — must not leak into [Data]/[BCLConvert_Data] as
590
593
  # extra per-sample columns.
591
- _STANDARD_SAMPLE_KEYS: frozenset[str] = frozenset({
592
- # core sample fields (lowercase — V1/V2 shared interface)
593
- "sample_id", "sample_name", "lane", "index", "index2",
594
- "sample_project", "description", "sample_plate", "sample_well",
595
- "i7_index_id", "i5_index_id",
596
- # capitalised variants returned by some parser versions
597
- "Index", "Index2", "Sample_Project",
598
- "I7_Index_ID", "I5_Index_ID",
599
- # raw CSV column-name variants in sheet.records (Title-case / V1 headers)
600
- "Lane", "Sample_ID", "Sample_Name", "Description",
601
- "Sample_Plate", "Sample_Well",
602
- # run-level metadata that sheet.samples() may include for V2
603
- "flowcell_id", "experiment_name",
604
- "run_name", "instrument_platform", "instrument_type",
605
- "run_description", "file_format_version",
606
- })
594
+ _STANDARD_SAMPLE_KEYS: frozenset[str] = frozenset(
595
+ {
596
+ # core sample fields (lowercase — V1/V2 shared interface)
597
+ "sample_id",
598
+ "sample_name",
599
+ "lane",
600
+ "index",
601
+ "index2",
602
+ "sample_project",
603
+ "description",
604
+ "sample_plate",
605
+ "sample_well",
606
+ "i7_index_id",
607
+ "i5_index_id",
608
+ # capitalised variants returned by some parser versions
609
+ "Index",
610
+ "Index2",
611
+ "Sample_Project",
612
+ "I7_Index_ID",
613
+ "I5_Index_ID",
614
+ # raw CSV column-name variants in sheet.records (Title-case / V1 headers)
615
+ "Lane",
616
+ "Sample_ID",
617
+ "Sample_Name",
618
+ "Description",
619
+ "Sample_Plate",
620
+ "Sample_Well",
621
+ # run-level metadata that sheet.samples() may include for V2
622
+ "flowcell_id",
623
+ "experiment_name",
624
+ "run_name",
625
+ "instrument_platform",
626
+ "instrument_type",
627
+ "run_description",
628
+ "file_format_version",
629
+ }
630
+ )
607
631
 
608
632
  # Add samples from all other sheets.
609
633
  # Use per-row records (not samples()) so multi-lane sheets — where the
@@ -613,14 +637,14 @@ class SampleSheetMerger:
613
637
  logger.debug(f"Adding samples from {p.name}")
614
638
  sheet_records = getattr(sheet, "records", None) or sheet.samples()
615
639
  for sample in sheet_records:
616
- sid = sample.get("sample_id") or sample.get("Sample_ID") or ""
617
- idx = sample.get("index") or sample.get("Index") or ""
640
+ sid = sample.get("sample_id") or sample.get("Sample_ID") or ""
641
+ idx = sample.get("index") or sample.get("Index") or ""
618
642
  idx2 = sample.get("index2") or sample.get("Index2") or ""
619
643
  lane = sample.get("lane") or sample.get("Lane") or "1"
620
644
  # Fix: fall back to capitalised key for V2 sheets
621
645
  proj = sample.get("sample_project") or sample.get("Sample_Project") or ""
622
- i7 = sample.get("i7_index_id") or sample.get("I7_Index_ID") or ""
623
- i5 = sample.get("i5_index_id") or sample.get("I5_Index_ID") or ""
646
+ i7 = sample.get("i7_index_id") or sample.get("I7_Index_ID") or ""
647
+ i5 = sample.get("i5_index_id") or sample.get("I5_Index_ID") or ""
624
648
 
625
649
  if not sid or not idx:
626
650
  missing = []
@@ -641,16 +665,17 @@ class SampleSheetMerger:
641
665
 
642
666
  # Only pass through genuine per-sample extra columns
643
667
  extra = {
644
- k: v for k, v in sample.items()
668
+ k: v
669
+ for k, v in sample.items()
645
670
  if k not in _STANDARD_SAMPLE_KEYS and v is not None
646
671
  }
647
672
 
648
673
  # Preserve per-sample metadata across all inputs by mapping
649
674
  # both normalised and raw (capitalised) keys from sheet.records.
650
- sample_name = sample.get("sample_name") or sample.get("Sample_Name") or ""
651
- description = sample.get("description") or sample.get("Description") or ""
675
+ sample_name = sample.get("sample_name") or sample.get("Sample_Name") or ""
676
+ description = sample.get("description") or sample.get("Description") or ""
652
677
  sample_plate = sample.get("sample_plate") or sample.get("Sample_Plate") or ""
653
- sample_well = sample.get("sample_well") or sample.get("Sample_Well") or ""
678
+ sample_well = sample.get("sample_well") or sample.get("Sample_Well") or ""
654
679
 
655
680
  writer.add_sample(
656
681
  sid,
@@ -693,9 +718,7 @@ class SampleSheetMerger:
693
718
  tmp_path = tmp.name
694
719
 
695
720
  try:
696
- sheet = SampleSheetFactory().create_parser(
697
- tmp_path, parse=True, clean=False
698
- )
721
+ sheet = SampleSheetFactory().create_parser(tmp_path, parse=True, clean=False)
699
722
  vresult = SampleSheetValidator().validate(
700
723
  sheet, min_hamming_distance=self.min_hamming_distance
701
724
  )