Skip to content

enable highly_variable_genes_seurat_v3 to work with pseudocounts - #1642

Merged
giovp merged 4 commits into
masterfrom
high-var
Feb 22, 2021
Merged

giovp merged 4 commits into
masterfrom
high-var

Conversation

@giovp

@giovp giovp commented Feb 10, 2021 •

Copy link
Copy Markdown
Member

Hi,

I'm working with pseudocounts data (kallisto/alevin/salomon output). I think they are called "pseudocount": if a read is assigned to two regions (genes) , a probability is assigned (e.g. gene1=0.2, gene2=0.8). Nevertheless, they can still considered counts and so it would be cool to use the highly_variable_genes flavour=seuratv3 .
I added an additional argument in case users would like to enforce this, as it was similarly done/discussed in theislab/scvelo#190

Would like to hear what you guys think, pinging @adamgayoso (thanks for the great overleaf doc! )

@adamgayoso

Copy link
Copy Markdown
Member

So, without any evidence, I think it should be fine. The reason I had put an error in the first place is that the typical behavior is to pass log normalized data to this HVG function, and I didn't want people to run this incorrectly.

I think another solution would be to just throw a UserWarning, though in a way I like the idea of having an argument that disables the check_nonnegative_integer(). I think I would call it enforce_counts_seurat_v3 though.

You might also consider bypassing the check if the flag is set, because it can be slowish for large datasets.

@ivirshup

Copy link
Copy Markdown
Member

How about a check_values argument which defaults to True, and replacing the error with a warning like:

"Your data doesn't appear to be have integer values, but this method expects raw count data. Proceed with caution."

check_values is nice and generic, and could be used in other functions.

@adamgayoso

Copy link
Copy Markdown
Member

check_values is nice and generic, and could be used in other functions.

Makes sense to me. Though if check_values is False, it shouldn't even run the check, correct?

So the warning would be more like,

"'seurat_v3' flavor expects raw count data. Proceed with caution."

@ivirshup

Copy link
Copy Markdown
Member

Though if check_values is False, it shouldn't even run the check, correct?

Yes.

So the warning would be more like,

"'seurat_v3' flavor expects raw count data. Proceed with caution."

I was thinking the warning would only occur if check_values=True and non integer values were found. "partial counts" are common enough I'd agree it's not reasonable for this to error if the results are still meaningful.

@giovp
giovp requested a review from ivirshup February 12, 2021 09:18
@giovp

giovp commented Feb 12, 2021

Copy link
Copy Markdown
Member Author

thanks guys, added the check_values argument and triggred the warning.

I tried to add a test for the warning following: https://docs.pytest.org/en/stable/warnings.html
but didn't manage (couldn't find a way to test for logging ). not sure if useful anyway.

Thank you!

Comment on lines +63 to +65
logg.warning(
"`flavor='seurat_v3'` expects raw count data, but non-integers were found."
)

@ivirshup ivirshup Feb 18, 2021 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can this be an actual UserWarning?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Logging frameworks should have a way of recording warnings on their own. In general, we should not be using logg.warning

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
logg.warning(
"`flavor='seurat_v3'` expects raw count data, but non-integers were found."
)
warn(
"`flavor='seurat_v3'` expects raw count data, but non-integers were found.",
UserWarning
)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done, and added test

@giovp

giovp commented Feb 22, 2021

Copy link
Copy Markdown
Member Author

I will merge this!

@giovp giovp changed the title add pseudocount arg to highly_variable_genes_seurat_v3 enable highly_variable_genes_seurat_v3 to work with pseudocounts Feb 22, 2021
@giovp
giovp merged commit 1043c69 into master Feb 22, 2021
@giovp
giovp deleted the high-var branch February 22, 2021 14:06
Comment on lines +60 to +63
if check_values:
warnings.warn(
"`flavor='seurat_v3'` expects raw count data, but non-integers were found.",
UserWarning,

@adamgayoso adamgayoso Feb 22, 2021 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think a bug has been introduced @ivirshup @giovp. Namely, the call to check_nonnegative_integers(X) was removed (should be here on line 61) if returns False, raise the warning

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

On another note, in this current state check_nonnegative_integers is an unused import. Do you guys check for this with flake8?

Comment on lines +23 to 24
check_values: Optional[bool] = True,
span: Optional[float] = 0.3,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

shouldn't both not be Optional?

@giovp

giovp commented Feb 22, 2021

Copy link
Copy Markdown
Member Author

really bad job from my side, thanks @adamgayoso for checking it🙏 reverted PR on master
will fix it shortly

@giovp
giovp restored the high-var branch February 23, 2021 10:20
jlause added a commit to jlause/scanpy that referenced this pull request Mar 12, 2021
ivirshup added a commit that referenced this pull request Mar 29, 2022
* adding core functions and documentation for pearson residual normalization and hvg selection

* adding Pearson residual+PCA bundles, minor bug fixes

* some style cleanup, minor fixes

* adapting _normalize_pearson_residuals() to cleaned-up _normalized_total() from #1667

* updating layer management as in #1667 for _highly_variable_pearson_residuals() as well

* slight performance improvement for sparse input

* style cleanup

* fixing import issue, fixing docstring style, adding check_values param and warning as in #1642

* fixed small NameError, simplified clip argument

* remove pd.categorical()

* adding check_values to docstrings and remaining pearson residual functions

* np.empty instead of np.nan

* add references to docstrings, add HVG details to docstring

* exposing pca keyword arguments to the user for the bundle/recipe functions

* removed unneeded reversal in hvg, fix kwargs_pca bug, consistent defaults across files

* fixing handling of `inplace` and `subset` arguments (see issue #1886), explicit typing of output, adding theta input check

* renaming output fields for consistency, fixing minor bug

* renaming output fields for consistency

* adding function that prepares testdata (used for pearson residual tests)

* adding tests for all pearson residual functions

* fix precommit high_var_genes

* try to get precommit to work

* try to get precommit to work

* fix recipes

* fix normalization

* remove relative imports

* fix docstrings

* retry to build docs

* fix highvar docstring

* more fixing docstrings

* docs build locally ? 🔨

* minor cleanup test normalization

* more minor cleanups

* final cleanup normalization

* fixes high var

* init experimental module

* fix column ordering for batch case

* moving to experimental, minor fix for experimental version of hvg selection

* linking tests to new experimental submodule, style cleanup

* adapt input arguments and docstring for experimental version of hvg selection function

* add recipes

* fix docs

* add correct module docs

* fix recipe docstrings

* try fix indentation

* fix indentation

* fix

* new indentation

* add space

* fixing typo in docstring

* renaming pca output fields

* adapting tests to new output fieldname

* fix docs 🔨

* update docs

* fix test 🔨

* ensure argument and docstring consistency

* update citation year

* cleaning imports in `preprocessing` functions

* making inputcheck tests specific to error/warning messages

* making inputcheck tests specific to error/warning messages

* resolve HVGs across batches more cleanly, fix dtype issue

* renaming pca input arguments

* renaming pca input arguments

* _pca bundle: more efficient copy handling, added input check. both _pca and _recipe: varm field for PCs, adapted tests and docs

* move repeated inputcheck code to helpers

* merging tests *_values and *_general

* condense code in pearson hvg selection test, smaller test data for speedup

* condensing code in normalization tests

* add asteriks for keyword

* updating refs to Genome Biology publication

* cleanup helpers.py

* cleanup main files as requested by @ivirshup

* revert unneeded settingWithCopy fix

* cache data

* use doc_params for doc

* fix doc_params var

* finalize docs

* fix param doc

* wrong var still

* add cached datasets module and test on high_var_genes tests

* use new cache dataset module for tests

* fix precommit

* fix docs

* fix reference and add notebook to tutorials

* add release note

* add release note

* fix release note

* typo

* remove duplicate reference

* fixing black flake etc requirements

* add _pca function to release note

* last edits to docs

* fix release and tutorial image

* try fix pre-commit

* minor docs

* Remove accidentally included files from merge

Co-authored-by: giovp <[email protected]>
Co-authored-by: Isaac Virshup <[email protected]>
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.

3 participants