Skip to content

Commit 70d90d4

Browse files
Move MatchJob dataclass from grouping.py to config.py
MatchJob is a plain data container that belongs with the other config/data types, not in the grouping module.
1 parent 99cb890 commit 70d90d4

8 files changed

Lines changed: 43 additions & 41 deletions

File tree

tests/test_grouping.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import numpy as np
3030
import pytest
3131

32-
from tsinfer import grouping
32+
from tsinfer import config, grouping
3333

3434

3535
@dataclasses.dataclass
@@ -558,7 +558,7 @@ class TestAssignGroups:
558558
"""Test that assign_groups takes ungrouped MatchJobs and assigns groups."""
559559

560560
def _make_job(self, haplotype_index, time, start=0, end=100):
561-
return grouping.MatchJob(
561+
return config.MatchJob(
562562
haplotype_index=haplotype_index,
563563
source="test",
564564
sample_id=f"s{haplotype_index}",
@@ -617,7 +617,7 @@ def test_sorted_by_group_then_haplotype_index(self):
617617
)
618618

619619
def test_preserves_job_fields(self):
620-
job = grouping.MatchJob(
620+
job = config.MatchJob(
621621
haplotype_index=0,
622622
source="my_source",
623623
sample_id="my_sample",

tests/test_matcher_fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import pytest
3131

3232
from tsinfer import config, matching, vcz
33-
from tsinfer.grouping import MatchJob
33+
from tsinfer.config import MatchJob
3434

3535
# ---------------------------------------------------------------------------
3636
# Helpers

tests/test_matching.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import numpy as np
2626
import tskit
2727

28-
from tsinfer import config, grouping, matching, vcz
28+
from tsinfer import config, matching, vcz
2929

3030
# ---------------------------------------------------------------------------
3131
# Helpers
@@ -110,7 +110,7 @@ def _make_job(
110110
population_id=None,
111111
):
112112
"""Create a MatchJob with sensible defaults for testing."""
113-
return grouping.MatchJob(
113+
return config.MatchJob(
114114
haplotype_index=haplotype_index,
115115
source=source,
116116
sample_id=sample_id,

tests/test_vcz.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import pytest
3131
import zarr
3232

33-
from tsinfer import config, grouping, vcz
33+
from tsinfer import config, vcz
3434

3535
# ---------------------------------------------------------------------------
3636
# Fixtures
@@ -346,7 +346,7 @@ def test_ancestor_haplotype(self):
346346
schedule=schedule,
347347
)
348348
# a0 has genotype [0, 1, 0]
349-
job = grouping.MatchJob(
349+
job = config.MatchJob(
350350
haplotype_index=1,
351351
source="ancestors",
352352
sample_id="a0",
@@ -371,7 +371,7 @@ def test_ancestor_haplotype_second(self):
371371
schedule=schedule,
372372
)
373373
# a1 has genotype [1, 0, 1]
374-
job = grouping.MatchJob(
374+
job = config.MatchJob(
375375
haplotype_index=2,
376376
source="ancestors",
377377
sample_id="a1",
@@ -396,7 +396,7 @@ def test_sample_haplotype_encoding(self):
396396
schedule=schedule,
397397
)
398398
# sample_0: gt [0, 1, 1] → encoded [0=anc, 1=derived, 1=derived]
399-
job = grouping.MatchJob(
399+
job = config.MatchJob(
400400
haplotype_index=3,
401401
source="test",
402402
sample_id="sample_0",
@@ -421,7 +421,7 @@ def test_sample_haplotype_second(self):
421421
schedule=schedule,
422422
)
423423
# sample_1: gt [1, 0, 0] → encoded [1=derived, 0=anc, 0=anc]
424-
job = grouping.MatchJob(
424+
job = config.MatchJob(
425425
haplotype_index=4,
426426
source="test",
427427
sample_id="sample_1",
@@ -467,7 +467,7 @@ def test_missing_genotype_encoded_as_minus_one(self):
467467
anc_alleles,
468468
schedule=schedule,
469469
)
470-
job = grouping.MatchJob(
470+
job = config.MatchJob(
471471
haplotype_index=2,
472472
source="test",
473473
sample_id="sample_0",
@@ -519,7 +519,7 @@ def test_multiple_sources(self):
519519
schedule = [("src_a", "sample_0", 0), ("src_b", "sample_0", 0)]
520520
reader = vcz.HaplotypeReader(sources, positions, anc_alleles, schedule=schedule)
521521

522-
job_a = grouping.MatchJob(
522+
job_a = config.MatchJob(
523523
haplotype_index=2,
524524
source="src_a",
525525
sample_id="sample_0",
@@ -529,7 +529,7 @@ def test_multiple_sources(self):
529529
end_position=200,
530530
group=2,
531531
)
532-
job_b = grouping.MatchJob(
532+
job_b = config.MatchJob(
533533
haplotype_index=3,
534534
source="src_b",
535535
sample_id="sample_0",
@@ -1475,7 +1475,7 @@ def test_facade_returns_alleles_after_reads(self):
14751475
reader = vcz.HaplotypeReader(sources, positions, anc_alleles, schedule=schedule)
14761476

14771477
# Read from both sources to trigger allele discovery
1478-
job_a = grouping.MatchJob(
1478+
job_a = config.MatchJob(
14791479
haplotype_index=0,
14801480
source="src_a",
14811481
sample_id="sample_0",
@@ -1485,7 +1485,7 @@ def test_facade_returns_alleles_after_reads(self):
14851485
end_position=200,
14861486
group=0,
14871487
)
1488-
job_b = grouping.MatchJob(
1488+
job_b = config.MatchJob(
14891489
haplotype_index=1,
14901490
source="src_b",
14911491
sample_id="sample_0",

tsinfer/config.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,24 @@ class MatchSourceConfig:
161161
mismatch: float | None = None
162162

163163

164+
@dataclasses.dataclass
165+
class MatchJob:
166+
"""One row of the compute-groups output — one per haplotype."""
167+
168+
haplotype_index: int
169+
source: str
170+
sample_id: str
171+
ploidy_index: int
172+
time: float
173+
start_position: int
174+
end_position: int
175+
group: int
176+
node_flags: int = 1
177+
individual_id: int | None = None
178+
population_id: int | None = None
179+
sample_chunk: int = 0
180+
181+
164182
@dataclasses.dataclass
165183
class MatchConfig:
166184
"""Configuration for the match step."""

tsinfer/grouping.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,13 @@
3030
import numba
3131
import numpy as np
3232

33+
from . import config
34+
3335
logging.getLogger("numba").setLevel(logging.WARNING)
3436
logger = logging.getLogger(__name__)
3537

3638

37-
@dataclasses.dataclass
38-
class MatchJob:
39-
"""One row of the compute-groups output — one per haplotype."""
40-
41-
haplotype_index: int
42-
source: str
43-
sample_id: str
44-
ploidy_index: int
45-
time: float
46-
start_position: int
47-
end_position: int
48-
group: int
49-
node_flags: int = 1
50-
individual_id: int | None = None
51-
population_id: int | None = None
52-
sample_chunk: int = 0
53-
54-
55-
def assign_groups(jobs: list[MatchJob]) -> list[MatchJob]:
39+
def assign_groups(jobs: list[config.MatchJob]) -> list[config.MatchJob]:
5640
"""Assign group indices to MatchJobs, return sorted by (group, haplotype_index)."""
5741
if len(jobs) == 0:
5842
return jobs

tsinfer/matching.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
import _tsinfer
3535

36-
from . import arg_ops, config, grouping, vcz
36+
from . import arg_ops, config, vcz
3737

3838
logger = logging.getLogger(__name__)
3939

@@ -286,7 +286,7 @@ def match(
286286
def extend_ts(
287287
ts: tskit.TreeSequence,
288288
*,
289-
paired_results: list[tuple[grouping.MatchJob, MatchResult]],
289+
paired_results: list[tuple[config.MatchJob, MatchResult]],
290290
allele_mapper: vcz.AlleleMapper,
291291
provenance_record: str | None = None,
292292
) -> tskit.TreeSequence:

tsinfer/pipeline.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def _build_jobs_with_metadata(cfg):
6464

6565
# Build MatchJobs directly from VCZ stores, assigning individual IDs
6666
# in the same pass.
67-
jobs: list[grouping.MatchJob] = []
67+
jobs: list[config.MatchJob] = []
6868
ind_key_to_id: dict[tuple[str, str], int] = {}
6969
hap_idx = 0
7070

@@ -159,7 +159,7 @@ def _build_jobs_with_metadata(cfg):
159159

160160
for p in range(ploidy):
161161
jobs.append(
162-
grouping.MatchJob(
162+
config.MatchJob(
163163
haplotype_index=hap_idx,
164164
source=source.name,
165165
sample_id=sid,
@@ -292,10 +292,10 @@ def compute_groups_json(cfg: config.Config) -> str:
292292
return json_str
293293

294294

295-
def _load_match_jobs(path) -> list[grouping.MatchJob]:
295+
def _load_match_jobs(path) -> list[config.MatchJob]:
296296
"""Read a match-jobs JSON file and return a list of MatchJob objects."""
297297
records = json.loads(pathlib.Path(path).read_text())
298-
return [grouping.MatchJob(**rec) for rec in records]
298+
return [config.MatchJob(**rec) for rec in records]
299299

300300

301301
def _setup_workdir(workdir, cfg):

0 commit comments

Comments
 (0)