Repository navigation
Fix plots and add_module_score reading the wrong rows of scale.data - #146
Merged
Merged
Conversation
…140) scale_data() scales only the variable features unless it is given others, so row i of scale.data is not feature i of the assay. dim_heatmap and the helper behind dot_plot, feature_plot, feature_scatter, ridge_plot, vln_plot and the spatial plots found a gene by its place in the assay's full list and used that to index scale.data: an IndexError when the place fell past the last scaled row, and another gene's row under the right label when it did not. add_module_score(layer="scale.data") had the same lookup. All three now go through the layer's own feature list. A gene that is in the assay but not in the layer raises a KeyError that names the layer and how many of the assay's features it holds. The plotting tests all scaled every feature, which makes a gene's place in the assay equal its row in the layer, so none could see it. The new tests use the standard workflow, check that their fixture can tell the two lookups apart, and were mutation-tested one site at a time. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
Fixes #140.
scale_data()scales only the variable features unless it is given others, so row i ofscale.datais not feature i of the assay. Two places still found a gene by its place in the assay's full list and used that to indexscale.data:dim_heatmapraisedIndexErrorwhen the place fell past the last scaled row, and otherwise drew another gene's row under the right label._get_expression, the helper behinddot_plot,feature_plot,feature_scatter,image_feature_plot,ridge_plot,spatial_feature_plotandvln_plot, did the same wheneverlayer="scale.data"was passed.Both now use
_resolve_layer, whichdo_heatmapalready used, so a gene is found in the layer's own feature list. A gene that is in the assay but not in the layer raises aKeyErrornaming the layer and how many of the assay's features it holds, instead of "not found in assay".One addition beyond the issue. I swept for other places that pair the assay's full feature list with a layer's matrix.
add_module_score(layer="scale.data")was the only other one (markers.pyandreduction.pywere fixed earlier, under #66). It raisedIndexErroron the standard workflow; it is fixed here by the same rule, and the defaultlayer="data"path returns the same list as before.Verification
scale.datarow.tests/test_layer_feature_alignment.py, six tests, on the standard workflow with the genes shuffled. The fixture asserts its own premise: the scaled genes are not the assay's first rows, since otherwise a lookup by position would be right by accident. That is also why the existing plotting tests missed this: every one of them scales all features._get_expressionfails three tests, intodim_heatmapone, and intoadd_module_scoreone. The test that the default layer still reads every gene stays green throughout.dim_heatmapor passeslayer="scale.data", so no committed figure can move.No release is needed for this change on its own. The CHANGELOG entry is under
[Unreleased]→ Fixed.🤖 Generated with Claude Code