Skip to content

Conversation

@jagadeeshkaruturi11
Copy link

Added new section 12.3 Rarefaction to address issue #823.

Changes include:

  • Introduction to rarefaction with rarefyAssay() and niter parameter
  • Subsection on using rarefaction with alpha diversity (addAlpha)
  • Subsection on using rarefaction with beta diversity (addMDS)
  • Function comparison explaining differences between:
    • addAlpha() vs getAlpha()
    • runMDS() vs addMDS()

Includes practical code examples demonstrating iterative rarefaction with niter=100.

Added new section 12.3 Rarefaction to address issue microbiome#823.

Changes include:
- Introduction to rarefaction with rarefyAssay() and niter parameter
- Subsection on using rarefaction with alpha diversity (addAlpha)
- Subsection on using rarefaction with beta diversity (addMDS)
- Function comparison explaining differences between:
  * addAlpha() vs getAlpha()
  * runMDS() vs addMDS()

Includes practical code examples demonstrating iterative rarefaction with niter=100.
Copy link
Member

@antagomir antagomir left a comment

Choose a reason for hiding this comment

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

Nice, this could be useful & apologies for delays.

Kindly see the suggestions and we can finalize.

Comment on lines +166 to +180
# Perform iterative rarefaction
tse <- rarefyAssay(
tse,
method = "subsample",
sample = min_reads,
niter = 100
)
# Calculate alpha diversity on rarefied data
tse <- addAlpha(
tse,
assay_name = "counts_rarefied",
sample = min_reads,
niter = 100
)
Copy link
Member

Choose a reason for hiding this comment

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

addAlpha can be used independently of rarefyAssay.

Hence I am thinking that it might be more clear to show these as two separate operations that can both be feasible but each on their own right. Shall we split this chunk in two parts?

# Perform MDS ordination on rarefied data
tse <- addMDS(
tse,
assay_name = "counts_rarefied",
Copy link
Member

Choose a reason for hiding this comment

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

mia changed argument names last year; "assay_name" is deprecated and should be replaced with "assay.type" everywhere


```{r}
#| label: rarefaction-alpha
#| eval: false
Copy link
Member

Choose a reason for hiding this comment

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

Why not eval: true?


```{r}
#| label: rarefaction-beta
#| eval: false
Copy link
Member

Choose a reason for hiding this comment

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

Why not eval: true?

# Perform MDS ordination on rarefied data
tse <- addMDS(
tse,
assay_name = "counts_rarefied",
Copy link
Member

Choose a reason for hiding this comment

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

If "niter" parameter is used then doesn't it already take care or rarifification i.e. why not use assay.type="counts"?

Comment on lines +202 to +203
**`addAlpha()` vs `getAlpha()`**: Both functions calculate alpha diversity indices, but `addAlpha()` stores the results directly into the `colData` of the TreeSummarizedExperiment object, while `getAlpha()` returns the diversity values as a separate vector or matrix. Use `addAlpha()` when you want to keep all data together in one object, and `getAlpha()` when you need the diversity values for immediate use in other calculations.

Copy link
Member

Choose a reason for hiding this comment

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

I suggest to explain this earlier, where the rarified alpha diversity analysis is shown.

Comment on lines +204 to +205
**`runMDS()` vs `addMDS()`**: The `runMDS()` function calculates multidimensional scaling coordinates and returns them as a separate matrix, whereas `addMDS()` calculates the MDS coordinates and stores them directly into the `reducedDim` slot of the TreeSummarizedExperiment object. Using `addMDS()` is generally preferred as it maintains all results within the same data object, making downstream analyses and visualization more straightforward.

Copy link
Member

Choose a reason for hiding this comment

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

You could also comment whether this is available for other ordination functions e.g. runPCA, runNMDS..?

@TuomasBorman
Copy link
Contributor

Sorry, I have been too busy lately...

This PR is clashing with #819

The information on rarefaction was already updated but it is not yet rendered in the book.

This PR has useful information, but we should think about the right place for this. Rarefaction is commonly used only in alpha and beta diversity (e.g., addAlpha and addMDS).

This rarefyAssay() approach is not used often as far as I know. If it is so, I am not sure if Transformation chapter is right place for discussing rarefaction.

One option:

  1. Discuss rarefaction is high-level in Transformation chapter (although it is not data transformation). Explain the idea.
  2. Add links to Alpha and beta diversity chapters where rarefaction is discussed in aforementioned context

@antagomir
Copy link
Member

antagomir commented Dec 5, 2025

Rarefaction can be viewed as a form of transformation / normalization.

Hence I think that rarefyAssay() could be explained in the transformation chapter. We can consider whether a practical example is necessary - perhaps mentioning the existence of this function would be enough(?) It might have more use in the future, even if it is currently used less. Then one could briefly mention that by doing this, and then averaging results across multiple rarified replicates has been proposed by Schloss et al.

Then, links could be provided to the alpha and beta diversity sections for more detailed examples on those.

This way we could avoid that the boundaries between section become blurred and contents mixed?

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