Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DefaultDimReduc<-? #203

Open
samuel-marsh opened this issue Apr 26, 2024 · 7 comments
Open

Add DefaultDimReduc<-? #203

samuel-marsh opened this issue Apr 26, 2024 · 7 comments

Comments

@samuel-marsh
Copy link

Hi Seurat Team,

Before attempting PR on this (which would be slightly more complicated than what I've done before) I wanted to just inquire about whether this is something that would be accepted or whether there is reason to leave as is. If this sounds like something that you would be open to PR on please let me know and I'll work on implementing it.

Best,
Sam

Basically wondering about implementing DefaultDimReduc<- to allow users to manually set the default dimensionality reduction. Right now, the function just checks for umap, tsne, pca in object reductions slot, and then prioritizes which one is default in that order.

The place I see this being most relevant is if users either want to save multiple reductions of the same type with different parameters (by changing key for each one when running commands) or if for instance they have run tsne and umap but want tsne to be their default. It would save entering extra parameter for reduction each time when plotting if the default could be updated.

From looking at things my thoughts on how to implement this would be to add new slot in Seurat class called active.reduc (similar to active.assay slot) and then DefaultDimReduc can check for a value in that slot or use current default ordering (umap, tsne, pca).

DefaultDimReduc<- would then have a check to ensure that the value being set matched a present reduction in the object so that it couldn't be set to non-present value.

If you have any thoughts, changes, or other suggestions please let me know.

Thanks again for all you do!
Sam

@samuel-marsh
Copy link
Author

Hi @dcollins15,

Tagging you for poke on this (not yet a PR but maybe a PR lol) issue too. If this is something you and team would be ammenable to adding I'm happy to work and submit an actual PR, so just let me know.

Thanks as always!
Sam

@nikofleischer
Copy link

I was just looking for this feature and sad I couldn't find it. Second it.

@dcollins15
Copy link
Collaborator

Hey @samuel-marsh,

This seems like a great idea to me! If you're still willing to implement it, I'd love for you to submit a PR. Happy to provide any support to help move this forward 🚀

Thanks for your continued contribution! I know I speak for everyone when I express my gratitude 🙂

@mojaveazure
Copy link
Member

@samuel-marsh @dcollins15 One thing to note is that DefaultDimReduc() is assay-aware, meaning it doesn't just search for dimensional reductions based on names, but also takes into account the assay used to generate each reduction. If you have a multi-modal object and have calculated a UMAP on each assay, when you switch the default assay DefaultDimReduc() will return the UMAP generated on the new default assay, not just the first DimReduc named "umap"

I would also caution against adding a new slot unless absolutely necessary. Changing the slot composition does weird things thanks to S4 caching, hence the need for UpdateSlots(); as much as possible, I would recommend against an over-reliance on UpdateSlots() as it recursively disassembles and re-assembles S4 objects, which can be quite expensive if there's a lot of data or complexity (like what Seurat v5 offers) to an S4 object

@samuel-marsh
Copy link
Author

@mojaveazure good points! Do you have any suggestions for implementation of function that wouldn't rely on new slot?

@mojaveazure
Copy link
Member

@samuel-marsh You could probably rely on Tool<-() to store a named vector of DimReduc names indexed by the assay that they've been set as default for (one DimReduc per assay). Then DefaultDimReduc() could be updated to make use of that Tool entry and ask:

  • has a DimReduc been specified as default for the given assay? If not, use the existing routine to select a default DimReduc
  • if yes, ask if that DimReduc exists. If it doesn't, throw an error (rlang::abort()) (or maybe a warning rlang::warn() and use the existing routine to select a default DimReduc?)
  • if the assigned DimReduc exists, return it

I think this is best done at the Seurat level rather than the Assay or DimReduc level, as Assays and DimReducs don't know about each other. I don't have the time to sketch out a full scaffold of these functions at the moment, sorry

@samuel-marsh
Copy link
Author

Hi @mojaveazure,

That's super helpful, thanks so much!!

@dcollins15 I'll work on PR and ping you here if I run into any issues.

Thanks both again!
Sam

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

No branches or pull requests

4 participants