fix: raise clear error when window_size is too large#1152
fix: raise clear error when window_size is too large#1152suhr25 wants to merge 11 commits intomalariagen:masterfrom
Conversation
…gwss Signed-off-by: Suhrid Marwah <suhridmarwah07@gmail.com>
|
Hi @jonbrenas, |
|
Hi @suhr25, would there be a way to instead raise a warning and modify the |
Replace hard error when window_size exceeds available SNPs with a warning, and automatically adjust window_size to the maximum valid value so that computation can proceed. Signed-off-by: Suhrid Marwah <suhridmarwah07@gmail.com>
1b9797e to
a05bab0
Compare
|
Thanks for the suggestion! @jonbrenas Let me know if you would prefer any different handling. |
|
Hi @jonbrenas, |
|
Thanks @suhr25, Because we want to have a moving statistics, the window size would need to be a factor smaller than the number of SNPs (let's say, 10 by default but it should be a parameter). The window size should thus be adjusted, unless it falls under a given number (again it should be a parameter with a default value say 1 000), in which your original error message probably becomes the solution. |
|
Sure thanks, |
|
Thanks, that makes sense. I've updated the implementation to automatically adjust window_size when possible and only raise an error for very small SNP counts. Let me know if you prefer different defaults. |
|
Hi @jonbrenas , |
|
Hi @jonbrenas, |
|
Hi @suhr25, Both _min_snps_threshold and _window_adjustment_factor should be parameters of the function (with these values by default as most people will not set values for them). |
ce9a455 to
2d0c75f
Compare
- Define min_snps_threshold and window_adjustment_factor as Annotated TypeAlias in fst_params.py so numpydoc_decorator 2.2.1 can extract their documentation automatically (plain int params without Annotated or explicit parameters dict cause DocumentationError at import time) - Add explicit parameters dict entries to @doc(fst_gwss) as belt-and- suspenders documentation for both new parameters - Switch fst_gwss signature from plain int to fst_params.min_snps_threshold and fst_params.window_adjustment_factor (consistent with codebase style) - Replace unseeded random.choice/random.sample in new tests with seeded np.random.choice (matching all existing tests that use np.random seeded with 42 via the autouse session fixture) - Remove import random from test_fst.py (no longer needed)
|
Hi @jonbrenas, |
SUMMARY
Fixes a crash when
window_sizeis too large in Fst GWSS by raising a clear error instead of returning empty data.FIX
Before
After
VERIFICATION
Using a large
window_sizeon a small region used to crash with anIndexError. Now it raises a clearValueError. A test confirms this behavior.