Skip to content

getTop: use include.lowest = FALSE by default for prevalence - #926

Merged
TuomasBorman merged 3 commits into
microbiome:develfrom
chenyangsu:fix/gettop-prevalence-include-lowest
Dec 2, 2026
Merged

TuomasBorman merged 3 commits into
microbiome:develfrom
chenyangsu:fix/gettop-prevalence-include-lowest

Conversation

@chenyangsu

@chenyangsu chenyangsu commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Calling getTop(GlobalPatterns, method = "prevalence", top = 5) returns features with prevalences 0.08 to 0.42 (and can include all-zero rows) because getTop() hardcodes include.lowest = TRUE in getPrevalence(). With the default detection = 0, x >= 0 assigns every non-negative row prevalence 1, diverging from getPrevalence()'s documented default include.lowest = FALSE; passing sort or include.lowest also triggers a duplicate-argument error.

getTop() now forwards ... to getPrevalence() without the hardcoded include.lowest = TRUE, so getPrevalence()'s default include.lowest = FALSE applies, and it passes na.rm. sort (alphabetical order of the output) is a regular argument of getTop(), so it no longer clashes with the sort = TRUE used to rank features. Happy to expose include.lowest explicitly in getTop() instead if you prefer.

Behaviour change

Existing code using getTop(..., method = "prevalence") can return different features. With the default detection = 0, every feature had prevalence 1, so the returned features were not the most prevalent ones; now they are ranked by the share of samples where the abundance is above detection, as in getPrevalence(). With detection > 0, abundances exactly equal to detection no longer count as present. include.lowest = TRUE gives the previous counting. Version bumped to 1.23.2, with a NEWS entry.

Testing: test-8summaries.R (15 passed), test-5prevalence.R (73 passed), test-0utilites.R (44 passed).

@antagomir antagomir left a comment

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.

Could work. Let's discuss the comments first.

Comment thread R/summaries.R Resolved
@antagomir

Copy link
Copy Markdown
Member

Thanks for the PR!

Existing code using method = "prevalence" will now return different features, it changes the behavior.

Please state this in the PR description so it goes into NEWS, and bump the version to 1.23.2.

sort (alphabetical output) no longer clashes with sort = TRUE in the getPrevalence() call, so the call does not need do.call().
@chenyangsu

Copy link
Copy Markdown
Contributor Author

I bumped the version to 1.23.2, added a NEWS entry, and added a behaviour change section to the description (46fadb1). Your suggestion works and reads better: sort is now a regular argument of getTop() (generic, method and docs), so the prevalence branch is a plain getPrevalence(assay(x, assay.type), sort = TRUE, na.rm = na.rm, ...) call with no do.call() (df2a206).

@TuomasBorman TuomasBorman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good!

@TuomasBorman

Copy link
Copy Markdown
Contributor

Thanks @chenyangsu ! I will merge this now. In separate PR, add your name to DESCRIPTION file so you will be credited from your contribution.

-Tuomas

@TuomasBorman
TuomasBorman merged commit 7fd8d61 into microbiome:devel Dec 2, 2026
1 of 2 checks passed
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