Skip to content

fix(mpa): skip blank/commented lines and warn on rarefaction-excluded samples - #28

Merged
ilypopv merged 5 commits into
mainfrom
dev
Sep 14, 2026
Merged

ilypopv merged 5 commits into
mainfrom
dev

Conversation

@ilypopv

@ilypopv ilypopv commented Sep 14, 2026

Copy link
Copy Markdown
Member

📝 Summary

Hardens the Kraken/Bracken report parser to gracefully skip blank and #-commented lines, fixing a latent crash where such lines fell through to a ValueError on tuple unpacking. Additionally, calc_beta_div now emits a UserWarning naming every sample excluded for falling below the rarefaction depth instead of silently dropping them.

🛠 Type of Change

  • Bug fix
  • New feature

🔍 Key Changes

  • transform2mpa._parse_line: strip the line and return [] immediately for blank or #-commented input, preventing downstream unpacking errors.
  • transform2mpa.kreport_to_mpa: replace the is None check with not report_vals so the empty-list return from _parse_line is correctly treated as a skip.
  • krakenparser.py: add import warnings and override warnings.formatwarning to suppress source file/line noise, showing only the message text; broaden the main_callback error handler to also catch ValueError.
  • stats/diversity.calc_beta_div: track excluded samples with their total read counts and emit a UserWarning (plus a log warning) listing them when any are dropped below rarefaction_depth; added a Warns: docstring section.
  • Tests: added unit tests for blank/commented line handling in _parse_line, an integration test verifying noisy reports produce identical output to clean ones, and a test asserting the exclusion warning names the affected sample.

🧪 How Has This Been Tested?

  • Unit tests (test_units.py) verify _parse_line returns [] for blank ("\n", " \n") and commented ("# some comment\n") lines.
  • Integration test (test_integration.py) confirms a report with leading blank/comment lines yields byte-identical output to the clean report.
  • Integration test asserts calc_beta_div raises UserWarning matching the excluded sample id (S3) when a sample is below the rarefaction depth.

@codecov

codecov Bot commented Sep 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@ilypopv
ilypopv marked this pull request as ready for review September 14, 2026 09:02
@ilypopv
ilypopv merged commit 9894229 into main Sep 14, 2026
11 checks passed
@ilypopv
ilypopv deleted the dev branch September 14, 2026 09:02
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.

1 participant