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

Return variable features directly if you have set them yourself #213

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

Gesmira
Copy link
Collaborator

@Gesmira Gesmira commented Jun 25, 2024

This has a corresponding fix in seurat-private: PR. s/o @longmanz for identifying and helping fix this issue.

The issue occurred when we tried to pull out VariableFeatures from an object in which we first ran FindVariableFeatures(), and then set our own VariableFeatures after. If we tried to pull out the re-set variable features, it pulled out the features previously calculated with FindVariableFeatures before

pbmc3k_v2 = FindVariableFeatures(pbmc3k)
VariableFeatures(pbmc3k_v2) <- rownames(pbmc3k_v2)[1:100]
head(pbmc3k_v2[["RNA"]]@meta.data)
# won't return the ones you've set 
head(VariableFeatures(pbmc3k_v2[["RNA"]], nfeatures = 2000))

The issue was that we have a check that we skip to the calculated variable features if nfeatures != Inf or the # of variable features. The solution is to almost always return the variable features directly if you have set them yourself.

Documented more here: https://github.com/orgs/satijalab/projects/1/views/1?pane=issue&itemId=51523433

Copy link
Collaborator

@longmanz longmanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tested the fix and it works well and as expected from my end. However, do we want to allow users to use the nfeatures = n parameter in VariableFeatures()? Now this does not work and VariableFeatures() will simply output all genes if users set VariableFeatures manually.

A naive modification would be:

if (isTRUE(x = simplify) & (is.null(x = layer) || any(is.na(x = layer))) &
         (is.infinite(x = nfeatures) || length(x = var.features) <=
          nfeatures)) {
       return(var.features) 
    } else if (isTRUE(x = simplify) & (is.null(x = layer) || any(is.na(x = layer))) &
         (is.infinite(x = nfeatures) || length(x = var.features) >
          nfeatures)) {
       return(var.features[1:nfeatures])
}

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.

2 participants