Skip to content

Plot a repeated feature once, and say when cells have no identity - #10478

Closed
BenjaminDEMAILLE wants to merge 1 commit into
satijalab:mainfrom
BenjaminDEMAILLE:fix/dotplot-duplicates-and-na
Closed

BenjaminDEMAILLE wants to merge 1 commit into
satijalab:mainfrom
BenjaminDEMAILLE:fix/dotplot-duplicates-and-na

Conversation

@BenjaminDEMAILLE

Copy link
Copy Markdown
Contributor

Two ways DotPlot() fails on input it should handle. Both found by sweeping the plotting functions with degenerate but ordinary arguments; VlnPlot() and FeaturePlot() handle the same inputs.

A feature named twice

> DotPlot(object, features = c(markers, markers[1]))
Error in `levels<-`: factor level [4] is duplicated

From

data.plot$features.plot <- factor(x = data.plot$features.plot, levels = features)

The features are there only to fix the order of the axis, so they are taken unique. This happens as soon as marker lists are combined, and with a named list (the grouped dot plot) it is unavoidable when a gene marks two groups.

Cells with no identity

> DotPlot(object, features = markers)
Error in `rbind`: duplicate 'row.names' are not allowed

CellsByIdentities() returns a group for NA, padded with NA cell names, and those reach FetchData(). The per-group frames then fail to bind. Such cells are now dropped, with

Warning: 3 cells have no identity and are not shown

Both the cell names and the identity column are filtered, so this holds whether or not the padding itself is fixed. With satijalab/seurat-object#302 (which fixes the padding) but without this change, the same call still fails, differently:

Error: replacement has 1 row, data has 0

so the two are complementary rather than duplicates.

Tests

tests/testthat/test_dotplot_features_idents.R: a repeated feature plotted once, a feature repeated across named groups, cells with no identity warned about and excluded, and the ordinary case unchanged.

Three assertions fail without the change. Full suite NOT_CRAN=true: 1188 passing, the only 2 failures being the pre-existing Read10X_Image ones fixed in #10454.

🤖 Generated with Claude Code

Two ways DotPlot() fails on input it should handle.

A feature named twice, which happens as soon as marker lists are combined,
becomes a duplicated factor level:

  > DotPlot(object, features = c(markers, markers[1]))
  Error in `levels<-`: factor level [4] is duplicated

The features are only there to fix the order of the axis, so take them
unique. VlnPlot() already tolerates this.

Cells with no identity come back from CellsByIdentities() as NA. Those NAs
reach FetchData(), and the per-group frames then fail to bind:

  > DotPlot(object, features = markers)
  Error in `rbind`: duplicate 'row.names' are not allowed

Drop them, and say how many were left out. Both the cell names and the
identity column are filtered, so this holds whether or not the NA padding
from CellsByIdentities() is fixed as well (satijalab/seurat-object#302).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@BenjaminDEMAILLE

Copy link
Copy Markdown
Contributor Author

Superseded by #10492, which groups five small independent fixes into one review. The commit is carried over unchanged; closing here to keep the queue down rather than because anything was wrong with it.

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