Skip to content

Replace intersect()'s eight mutually-exclusive booleans with a single mode parameter #238

Open

Description

@conradbzura

intersect() in tests/integration/bedtools/utils/bedtools_wrapper.py takes eight mutually-exclusive booleans (loj, inverse, write_both, count, write_overlap, write_all_overlap, clip, reciprocal) and resolves them through two parallel if/elif chains — one picking the bedtools flags, a second picking the bed_format passed to bedtool_to_tuples:

if loj:
    kwargs["loj"] = True
elif inverse:
    kwargs["v"] = True
elif write_both:
    ...
elif not clip:
    kwargs["u"] = True
...
if loj:
    return bedtool_to_tuples(result, bed_format="loj")
if write_both:
    return bedtool_to_tuples(result, bed_format="loj")
...

Three problems follow from the shape rather than from any single branch. The exclusivity is encoded only in the elif ordering, so intersect(a, b, clip=True, reciprocal=True) silently honours one and drops the other — no caller does that today, which is exactly why it would go unnoticed. The two chains must stay in agreement by hand, and they already disagree in structure (write_both sets two flags but shares loj's output format). And each new bedtools mode costs a branch in both chains plus a parameter in the signature.

Suggested shape. One mode parameter over the named bedtools output modes, resolved through a single mapping from mode to (flags, bed_format). That collapses both chains, makes the exclusivity structural instead of positional, and reduces adding a mode to adding a row.

Raised as A7 in the round-1 review of #235 (.sdlc/reviews/issue-#109/review-1.md), where all five python reviewers flagged the chain. #235 took the in-scope half — it removed an empty elif clip: pass branch and the reciprocal shadowing it introduced, and corrected the clip docstring — and Style Guide §1 requires a refactor of this size be surfaced as a proposal rather than folded into an unrelated change, hence this issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions