Skip to content

fix: Enhance logging and add allele consistency checks#22

Merged
gp201 merged 9 commits intoandersen-lab:mainfrom
gp201:fix/ensure_binary_matrix
Mar 18, 2026
Merged

fix: Enhance logging and add allele consistency checks#22
gp201 merged 9 commits intoandersen-lab:mainfrom
gp201:fix/ensure_binary_matrix

Conversation

@gp201
Copy link
Copy Markdown
Collaborator

@gp201 gp201 commented Mar 18, 2026

This pull request refactors the codebase to standardize and simplify console output handling by replacing direct usage of the rich.console.Console and manual style formatting with new utility functions (print_error, print_warning, print_success, print_info, print_debug). It also enhances barcode consistency checks by introducing a new allele consistency validation and improves error handling throughout the CLI and barcode generation modules.

Console output refactoring:

  • Replaced all direct console.print calls and manual style formatting with utility functions (print_error, print_warning, print_success, print_info, print_debug) across barcodeforge/cli.py, barcodeforge/generate_barcodes.py, and barcodeforge/auspice_tree_to_table.py for more consistent and maintainable messaging. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18]

Barcode consistency and error handling improvements:

  • Introduced a new check_allele_consistency function to ensure that each position in the barcode matrix has only one reference allele and that no lineage has multiple alternative alleles at the same position, raising errors if inconsistencies are found. [1] [2] [3]
  • Updated the flip pair check (check_no_flip_pairs) to use print_success and print_error, and to raise click.Abort instead of a generic exception for improved CLI error handling. [1] [2]

CLI interface and function signature changes:

  • Removed the console argument from CLI and processing functions, simplifying function signatures and reducing coupling to the console implementation. [1] [2] [3] [4] [5] [6]
  • Improved error handling in CLI commands by using print_error and click.Abort for unsupported formats and operational failures.

General code cleanup:

  • Removed unused imports and redundant code related to console handling and style management. [1] [2] [3]

These changes collectively make console output more uniform, improve error reporting, and add robust checks for barcode data integrity.

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 standardizes CLI/library console output by centralizing Rich printing in barcodeforge.utils helper functions, and strengthens barcode validation by adding an allele consistency check that aborts on inconsistent mutation encodings.

Changes:

  • Added print_error/print_warning/print_success/print_info/print_debug helpers and refactored callers to use them (removing Console parameters/instances).
  • Introduced check_allele_consistency and integrated it into barcode generation/validation.
  • Updated tests to patch the shared barcodeforge.utils.console and to expect click.Abort for CLI-style failures.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
barcodeforge/utils.py Adds shared console and printing helpers; updates subprocess + tree-format utilities to use them.
barcodeforge/cli.py Refactors CLI output and error handling to standardized print helpers; removes Console usage.
barcodeforge/generate_barcodes.py Adds allele consistency validation; standardizes flip-pair failure to click.Abort; refactors logging.
barcodeforge/ref_muts.py Refactors messages to standardized printing helpers.
barcodeforge/plot_barcode.py Updates debug/info output to standardized printing helpers.
barcodeforge/auspice_tree_to_table.py Removes console parameter; standardizes errors/warnings via print helpers and click.Abort.
tests/test_utils.py Updates tests for new utility signatures/output formatting and console patching approach.
tests/test_cli.py Updates CLI tests for new signatures and console patching via barcodeforge.utils.console.
tests/test_generate_barcodes.py Adds coverage for allele consistency; updates abort expectations for flip-pair check.
tests/test_ref_muts.py Updates console patch target to barcodeforge.utils.console and adjusts expected messages.
tests/test_auspice_tree_to_table.py Updates tests for console removal and abort behavior; captures output via shared console.

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

You can also share your feedback on Copilot code review. Take the survey.

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 standardizes console output across the BarcodeForge CLI/tooling by centralizing printing in barcodeforge.utils helper functions, and adds an allele-consistency validation step to improve barcode integrity checks during generation.

Changes:

  • Introduces print_error/print_warning/print_success/print_info/print_debug helpers and removes per-module Console usage / console parameters.
  • Adds check_allele_consistency() and invokes it during barcode mutation-chain validation.
  • Updates CLI + module error handling to raise click.Abort, and adjusts tests accordingly.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
barcodeforge/utils.py Adds global console + new print helper functions; updates subprocess + format resolution logging.
barcodeforge/cli.py Refactors CLI messaging to use print helpers; removes console plumbing and improves abort behavior.
barcodeforge/generate_barcodes.py Uses print helpers; changes flip-pair handling to click.Abort; adds allele consistency validation and calls it from mutation-chain checks.
barcodeforge/auspice_tree_to_table.py Removes console parameter and switches messaging/error handling to print helpers + click.Abort.
barcodeforge/ref_muts.py Replaces direct console printing with print helpers.
barcodeforge/plot_barcode.py Switches debug/info output to print helpers.
tests/test_utils.py Updates unit tests for new utils signatures and centralized console patching.
tests/test_cli.py Updates CLI tests to patch barcodeforge.utils.console and reflect new function signatures.
tests/test_generate_barcodes.py Adds tests for check_allele_consistency; updates expected exceptions for flip-pair checks.
tests/test_ref_muts.py Updates console patching target to barcodeforge.utils.console and expected message format.
tests/test_auspice_tree_to_table.py Updates tests for removed console parameter and centralized console patching.

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

You can also share your feedback on Copilot code review. Take the survey.

@gp201 gp201 merged commit 19071cd into andersen-lab:main Mar 18, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants