seurat-object icon indicating copy to clipboard operation
seurat-object copied to clipboard

Unexpected values returned by FetchData() / unsafe programming / change help

Open vertesy opened this issue 2 months ago • 2 comments

Dear Seurat Team,

I used FetchData(object = obj, vars = "UMAP_1") to retrieve UMAP coordinates in Seurat.utils::AutoNumber.by.UMAP().

This worked until Seurat v5. After Seurat v5 it still executed without a warning, but the coordinates returned did not correspond to the umap plotted.

What happens?

  1. In v5 UMAP_1 got renamed to umap_1, in @reductions$umap
  2. FetchData now silently returns UMAP_1 from obj@reductions$ref.umap instead from obj@reductions$umap.
  3. I did not even know about ref.umap, and getting values from it is very unexpected when asking for a umap coordinate. I needed to look through 2MB of "str(obj)" output to get this info.
  4. The solution is that I will not use FetchData, bc I rather break the code then get meaningless values to figure out much later.

Solutions

  1. FetchData is unsafe currently, even if it "works correctly". Please add some reporting or break early.
  2. Please change help. Stop recommending in ?FetchData to use as: pc1 <- FetchData(object = pbmc_small, vars = 'PC_1'), bc apparently you would need to specify the PCA slot to be sure what to get.
  3. I encountered now multiple times such unsafe programming in Seurat, where sth is returned without message/warning/error, so this is also a general request to increase prudency. See example: NA values in DiscretePalette needed to be handled by quick and dirty Seurat.utils::DiscretePaletteSafe().

Thank you for your time sharing and maintaining the code. Abel

vertesy avatar Apr 16 '24 15:04 vertesy