Skip to content

Code restructuring#151

Open
matthdsm wants to merge 16 commits intomasterfrom
refactor/restructure
Open

Code restructuring#151
matthdsm wants to merge 16 commits intomasterfrom
refactor/restructure

Conversation

@matthdsm
Copy link
Copy Markdown

@matthdsm matthdsm commented Mar 30, 2026

  • Fix chromosome parsing in _generate_regions_bed - use elif/else chain so X/Y assignments are not overwritten by the int(re.sub(...)) conversion
  • Fix --gender Sex enum comparison - extract .value when assigning args.gender so downstream string comparisons (== "M", == "F") work correctly

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR restructures the WisecondorX codebase by consolidating stage logic into fewer modules, adds a refqc CLI subcommand for reference QC, and updates the project to require Python 3.12+.

Changes:

  • Consolidated convert/newref/predict logic into src/wisecondorx/{convert,newref,predict}.py, removing older *_tools.py / *_control.py modules.
  • Added refqc CLI subcommand and expanded QC-related tests.
  • Added/updated unit tests for convert, newref, predict, and CLI version behavior; bumped Python requirement to >= 3.12.

Reviewed changes

Copilot reviewed 25 out of 26 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/test_ref_qc.py Updates imports and adds unit tests for new refqc internals.
tests/test_predict_contract.py Updates contract tests to import from consolidated predict.py.
tests/test_predict.py Adds new functional tests covering consolidated predict utilities.
tests/test_newref_contract.py Updates contract tests to import from consolidated newref.py.
tests/test_newref.py Adds new functional tests covering consolidated newref utilities and tools.
tests/test_main.py Adds CLI test for --version/-v.
tests/test_convert.py Adds functional tests for consolidated convert implementation using pysam.
src/wisecondorx/utils.py Moves shared helpers here and renames gender_correct to sex_correct; modernizes some strings/docstrings.
src/wisecondorx/refqc.py Adds Typer CLI wrapper function (wcx_refqc) and refactors/optimizes parts of QC computations.
src/wisecondorx/predict_tools.py Deleted (logic moved into predict.py).
src/wisecondorx/predict_output.py Deleted (logic moved into predict.py).
src/wisecondorx/predict_control.py Deleted (logic moved into predict.py).
src/wisecondorx/predict.py New consolidated predict module including CLI commands and supporting functions.
src/wisecondorx/newref_tools.py Deleted (logic moved into newref.py).
src/wisecondorx/newref_control.py Deleted (logic moved into newref.py).
src/wisecondorx/newref.py New consolidated newref module including CLI command and supporting functions; calls refqc after building.
src/wisecondorx/main.py Simplifies CLI wiring to consolidated modules; adds refqc command and version flag.
src/wisecondorx/convert_tools.py Deleted (logic moved into convert.py).
src/wisecondorx/convert.py New consolidated convert module.
pyproject.toml Bumps requires-python and Ruff target version to 3.12.
pixi.lock Updates locked metadata for Python requirement.
docs/include/pipeline/predict.sh Deleted legacy pipeline helper script.
docs/include/pipeline/newref.sh Deleted legacy pipeline helper script.
docs/include/pipeline/convert.sh Deleted legacy pipeline helper script.
README.md Removes references to deleted pipeline scripts.
AGENTS.md Updates project architecture and stack description to reflect restructuring and Typer CLI.
Comments suppressed due to low confidence (1)

src/wisecondorx/refqc.py:257

  • As a Typer subcommand, the integer returned by wcx_refqc won’t propagate to the process exit code, so wisecondorx refqc ... will exit 0 even when QC fails. If QC status is meant for automation/pipelines, raise typer.Exit(code=worst) (after writing JSON/logging) instead of only returning the integer.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +212 to +217
gender = predict_sex(sample, ref_file["trained_cutoff"])
if not ref_file["is_nipt"]:
if args.gender:
gender = args.gender
sample = sex_correct(sample, gender)
ref_gender = gender
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--gender is declared as Sex (an Enum), but later gender is compared to string literals (e.g. gender == "M") and passed into sex_correct, which currently checks sex == "M". If the user provides --gender, gender becomes a Sex instance and these checks will fail (and gonosome normalization may select the wrong branch). Convert the enum to its .value when assigning/using it (or update sex_correct / comparisons to handle Sex).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9a5cde1. Added .value when assigning args.gender to gender (gender = args.gender.value) in both the NIPT and non-NIPT branches, so gender is always a plain string ("M" or "F") consistent with what predict_sex returns and what the downstream comparisons and sex_correct expect.

Comment on lines +72 to +79
mode = "rb" if infile.suffix == ".bam" else "rc"
ref_filename = str(reference) if reference else None

if mode == "rc" and not ref_filename:
logging.error(
"Cram inputs need a reference fasta provided through the '--reference' flag."
)
sys.exit(1)
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Input format detection treats any non-.bam file as CRAM (mode = "rb" if ... else "rc"). This misclassifies unsupported extensions and produces a misleading “Cram inputs need a reference” error. Add an explicit suffix check for .bam/.cram and error out for anything else.

Copilot uses AI. Check for mistakes.
nvnieuwk
nvnieuwk previously approved these changes Mar 30, 2026
Copy link
Copy Markdown

@nvnieuwk nvnieuwk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't checked the new files but I trust you didn't change anything there, the rest looks good!

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants