Selecting an Even Sampling Depth#

Rarefying, rarefaction, and q2-boots#

A first step in analyzing our microbiome feature table is to choose an “even sampling depth”, or the number of sequences that we should select at random from each of our samples to ensure that all samples are sequenced at equivalent depth or with equivalent effort. This processes is referred to as rarefying our feature table. Rarefying feature tables, or sampling them to a user-specified sampling depth and discarding samples with a total frequency that is less than the sampling depth, is a bit of a controversial topic because it throws away some of the data that was collected and is subject to biases as a result. Rarefaction differs in a subtle way from rarefying, in that it involves repeat sampling from the input feature table to a user-specified sampling depth. These concepts were recently discussed in [Sch24]. In this tutorial, for the sake of time, we are going to focus our diversity analyses on rarefying (i.e., a single iteration of random sampling). To perform rarefaction-based diversity analysis with QIIME 2, refer to the q2-boots plugin [RGH+24].

Selecting an even sampling depth#

To start our diversity analyses, we first need to determine what even sampling depth (or “rarefaction depth”) we want to select for computing our diversity metrics. Because most diversity metrics are sensitive to different sampling depths across different samples, it is common to randomly subsample the counts from each sample to a specific value. For example, if you define your sampling depth as 500 sequences per sample, the counts in each sample will be subsampled without replacement so that each sample in the resulting table has a total count of 500. If the total count for any sample(s) are smaller than this value, those samples will be dropped from the downstream analyses. Choosing this value is tricky. We recommend making your choice by reviewing the information presented in the feature table summary file. Choose a value that is as high as possible (so you retain more sequences per sample) while excluding as few samples as possible.

Open up the feature table summary that you previously created with either Galaxy or in your QIIME 2 container and we’ll discuss this as a group.

Alpha rarefaction plots#

After choosing an even sampling depth, it’s helpful to see if your diversity metrics appear stable at that depth of coverage. You can do this for alpha diversity using an alpha rarefaction plot.

import qiime2.plugins.diversity.actions as diversity_actions

obs_features_alpha_rarefaction_viz, = diversity_actions.alpha_rarefaction(
    table=feature_table,
    metrics={'observed_features'},
    metadata=sample_metadata_md,
    max_depth=33000,
)
builtins <- import_builtins()
diversity_actions <- import("qiime2.plugins.diversity.actions")

action_results <- diversity_actions$alpha_rarefaction(
    table=feature_table,
    metrics=builtins$set(list('observed_features')),
    metadata=sample_metadata_md,
    max_depth=33000L,
)
obs_features_alpha_rarefaction_viz <- action_results$visualization
qiime diversity alpha-rarefaction \
  --i-table feature-table.qza \
  --p-metrics observed_features \
  --m-metadata-file sample-metadata.tsv \
  --p-max-depth 33000 \
  --o-visualization obs-features-alpha-rarefaction.qzv
use.action(
    use.UsageAction(plugin_id='diversity', action_id='alpha_rarefaction'),
    use.UsageInputs(table=autofmt_table, metrics={'observed_features'},
                    metadata=sample_metadata, max_depth=33000),
    use.UsageOutputNames(visualization='obs-features-alpha-rarefaction'))
Using the qiime2 diversity alpha-rarefaction tool:
  1. Set “table” to #: feature-table.qza

  2. Set “max_depth” to 33000

  3. Expand the additional options section

    1. For “metrics”:

      1. Set “element” to observed_features

      2. (Do not insert additional values.)

    2. For “metadata”:

      • Press the + Insert metadata button to set up the next steps.

        1. Leave as Metadata from TSV

        2. Set “Metadata Source” to sample-metadata.tsv

  4. Press the Execute button.

Once completed, for the new entry in your history, use the Edit button to set the name as follows:

(Renaming is optional, but it will make any subsequent steps easier to complete.)

History Name

“Name” to set (be sure to press Save)

#: qiime2 diversity alpha-rarefaction [...] : visualization.qzv

obs-features-alpha-rarefaction.qzv