Repository navigation
Multi letter rows and cli errors - #8
Merged
Merged
Conversation
Rows are labelled A-Z and then continue into multiple letters, matching
1536-well plates where row 27 is AA. This required replacing the inline
chr(ord("A") + r) at eight sites with two bijective base-26 helpers,
letters_to_row_index and row_index_to_letters, which now own the
conversion. Plate output is unchanged for 96- and 384-well plates, which
never exceed 26 rows.
Rows past Z previously produced punctuation instead of letters, so trace
labelled a 32-row plate with wells like '[12', and out-of-bounds errors
named a maximum well of '^'. Both now report real wells. Shuffle output
was never affected, since it writes a plain grid of sample IDs.
Row labels are restricted to ASCII A-Z. str.isalpha() accepts any Unicode
letter, and Unicode case-mapping can turn non-ASCII input into a real row
label, so a sample file naming well 'i1' would place a sample at I1 with no
error raised.
shuffle now surfaces input-validation ValueErrors as click usage errors
instead of letting tracebacks escape. load_sample_ids is inside that block
too, so a duplicated well in a sample file is reported cleanly rather than
crashing the shell.
A well can be written several ways -- 1, A1, A01 and a1 all name the same well -- and each spelling was kept as its own dictionary key. Two maps therefore disagreed about which sample occupied a well depending only on how it happened to be spelled: - A sample file placing a control at "1" alongside --fixed-map A1:control-1 was reported as a conflict, though both named the same well. - Placing a different sample at "1" alongside --fixed-map A1:control-1 raised nothing. Plate 1 got the control in A1 and the sample appeared on no plate at all, silently dropping it. Both well maps are now rewritten to a canonical form via well_to_index once the plate size is known, before the conflict check and the plate merge, and two entries resolving to one well are rejected rather than overwriting each other. Case folding is limited to ASCII input, since Unicode upper() folds some non-ASCII letters onto A-Z and would let such a well validate as a real one. Output is unchanged for plates that do not use initial positions or a fixed control map.
open() without an encoding argument uses the platform locale, so a UTF-8 file read on Windows decoded as cp1252. Four tests that write a non-ASCII well into a fixture failed there with UnicodeEncodeError while passing on Linux and macOS. The same default applied to production code, where the failure is quieter: a sample file written on one platform and read on another decoded to mojibake rather than raising, silently corrupting sample IDs. All six open() calls in cli.py and utilities.py now pass encoding="utf-8". numpy.savetxt is untouched, since it already writes UTF-8 regardless of locale. Console output is not covered by this change. click.echo of a non-ASCII sample ID still depends on the console encoding, which on Windows means setting PYTHONUTF8=1 or chcp 65001.
Contributor
Author
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds support for plates with more than 26 rows, and makes
shufflereportinvalid input as a usage error rather than a traceback.
What changed
Znow continue asAA,AB, ...,matching 1536-well plates (32 rows =
A-Z,AA-AF). Two conversions,letters_to_row_indexandrow_index_to_letters, now own the row-labellogic, replacing inline arithmetic at eight sites.
labels like
[12; out-of-bounds errors reported a maximum well of^. Bothnow name real wells.
str.isalpha()accepts any Unicode letter, andUnicode case-mapping folds some non-ASCII input onto
A-Z, soi1with adotless i silently resolved to
I1. Now rejected.clickusage errors(exit 2) instead of tracebacks. This includes
load_sample_ids, so aduplicated well in a sample file is reported rather than crashing the shell.
before being compared or merged. Two spellings of one well no longer produce
a false conflict, nor silently drop a sample.
.gitignore. Ignores scratch output from manual runs at the repo root.Patterns are root-anchored so tracked
example_files/*.csvinputs stayvisible.
Compatibility
shuffleoutput is byte-identical tomainfor 96- and 384-well plates, verifiedby comparing output hashes across four seeded configurations (neighbor-aware,
simple, with and without controls). Trace CSV output is unchanged for any plate
with 26 or fewer rows. Both standard sizes are unaffected.
Testing
59 tests pass, up from 10. Adds
tests/test_cli.py(9 tests), which the projectdid not previously have: CLI behaviour was untested. 12 new tests in
tests/test_plate_generator.py.ruff,ruff format,mypy,prettier, andthe packaging smoke test all pass.