Repository navigation
Draw groups in a categorical column's own order, so reorder_ident has an effect - #149
Merged
Merged
Conversation
… an effect (#143) In Seurat the order of a factor's levels decides the order of the groups in DotPlot and VlnPlot, and ReorderIdent changes the plots by changing the levels. dot_plot, vln_plot, dim_plot, feature_scatter, do_heatmap and ridge_plot sorted the groups themselves with ident_sort_key whatever the categories said, so a lineage-ordered dot plot was not possible and reorder_ident did nothing to them. A shared helper now follows a categorical column's categories, or the active identity's. Categories that are only the sorted order every categorical starts with are not an order anyone chose: pd.Categorical(values) and rename_idents leave "1", "10", "2", and those still sort numbers first as before. That is what keeps the six existing numbers-first tests green, and making the helper honour the default order fails all of them. Categories with no cells are not drawn, and a missing value, which pandas 2 and 3 spell differently after astype(str), is still last. find_clusters already orders its categories numbers then names, and no tutorial sets a category order, so no existing workflow changes. The two spatial dim plots use a plain sorted() and are left alone, since changing them would move committed spatial figures; ROADMAP.md says so. 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 #143.
In Seurat the order of a factor's levels decides the order of the groups in
DotPlotandVlnPlot, andReorderIdentchanges the plots by changing the levels.dot_plotandvln_plotsorted the groups themselves, whatever the categories said, so a lineage-ordered dot plot was not possible andreorder_identhad no effect on them.What changed
A shared helper,
_group_levels, follows a categorical column's categories, or the active identity's, and six plots use it:dot_plotandvln_plotas reported, anddim_plot,feature_scatter,do_heatmapandridge_plot, which sort their groups with the same line. The issue says the other plots were not checked; they were and they share the defect. Their colours follow, ashue_palis assigned in level order in R.The one design decision.
obj.identsis always apd.Categorical, andpd.Categorical(values)andrename_identsgive it pandas' default categories: string-sorted, so"1", "10", "2". Honouring those blindly would undo the numbers-first ordering thatident_sort_keyand its six existing tests deliberately provide ("a dataset with eleven or more clusters would come back in a different cluster order from Seurat's"). So categories that are only the sorted order every categorical starts with are not treated as an order anyone chose and are sorted as before, numbers first. Any other order is followed.reorder_identand areorder_categoriescall both land on the second branch.find_clustersalready orders its categories numbers then names, so nothing changes for an existing workflow. No tutorial sets a category order. Categories with no cells are not drawn, as ggplot drops unused levels, and a missing value is still drawn last.Verification
Zeta, Mu, Alphafordot_plot,vln_plot, and afterreorder_ident.tests/test_plot_group_order.py: all six plots, through both the active identity and a metadata column, plusreorder_ident, plus the helper's edge cases.ridge_plotlosing its reversal.git statusafterwards was empty, so every figure and tracked handoff file is byte-identical to the committed one.plotting.py(133), mypy at its 4 baseline errors.Not changed
image_dim_plotandspatial_dim_plotuse a plainsorted(), so they also ignore a categorical's order and put"10"before"2". That is an older and different ordering from the one above, and changing it would move committed spatial tutorial figures.ROADMAP.mdlists it, and replaces itsvln_plotgroup-order item, whose group-order half this fixes; the median-bar half remains.No release is needed for this change on its own. The CHANGELOG entry is under
[Unreleased]→ Fixed.🤖 Generated with Claude Code