Identifying an even sampling depth for use in diversity metrics#

As we begin performing more analyses of the samples in our feature table, an important parameter that needs to be define is the even sampling (i.e. rarefaction) depth that diversity metrics need to be computed at. 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.

Generate a feature table summary#

First, let’s create and view a summary of the most recent feature table that was created.

filtered_table_4_summ_viz, = feature_table_actions.summarize(
    table=filtered_table_4,
    sample_metadata=sample_metadata_md,
)
action_results <- feature_table_actions$summarize(
    table=filtered_table_4,
    sample_metadata=sample_metadata_md,
)
filtered_table_4_summ_viz <- action_results$visualization
qiime feature-table summarize \
  --i-table filtered-table-4.qza \
  --m-sample-metadata-file sample-metadata.tsv \
  --o-visualization filtered-table-4-summ.qzv
use.action(
    use.UsageAction(plugin_id='feature_table', action_id='summarize'),
    use.UsageInputs(table=filtered_table_4, sample_metadata=sample_metadata),
    use.UsageOutputNames(visualization='filtered_table_4_summ'),
)
Using the qiime2 feature-table summarize tool:
  1. Set “table” to #: filtered-table-4.qza

  2. Expand the additional options section

    • For “sample_metadata”:

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

        1. Leave as Metadata from TSV

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

  3. 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 feature-table summarize [...] : visualization.qzv

filtered-table-4-summ.qzv

Alpha rarefaction plots#

After choosing an even sampling depth, it’s also helpful to see if your diversity metrics appear to have stabilizes 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

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

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

  2. Set “max_depth” to 33000

  3. Expand the additional options section

    1. For “metrics”:

      1. Set “element” to shannon

      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

shannon-rarefaction-plot.qzv

Beta rarefaction plots#

Similarly, you can evaluate whether your beta diversity metrics appear stable at the depth you have selected.

braycurtis_rarefaction_plot_viz, = diversity_actions.beta_rarefaction(
    table=filtered_table_4,
    metric='braycurtis',
    clustering_method='nj',
    sampling_depth=10000,
    metadata=sample_metadata_md,
)
action_results <- diversity_actions$beta_rarefaction(
    table=filtered_table_4,
    metric='braycurtis',
    clustering_method='nj',
    sampling_depth=10000L,
    metadata=sample_metadata_md,
)
braycurtis_rarefaction_plot_viz <- action_results$visualization
qiime diversity beta-rarefaction \
  --i-table filtered-table-4.qza \
  --p-metric braycurtis \
  --p-clustering-method nj \
  --p-sampling-depth 10000 \
  --m-metadata-file sample-metadata.tsv \
  --o-visualization braycurtis-rarefaction-plot.qzv
use.action(
    use.UsageAction(plugin_id='diversity', action_id='beta_rarefaction'),
    use.UsageInputs(table=filtered_table_4, metric='braycurtis',
                    clustering_method='nj', sampling_depth=10000,
                    metadata=sample_metadata),
    use.UsageOutputNames(visualization='braycurtis_rarefaction_plot'))
Using the qiime2 diversity beta-rarefaction tool:
  1. Set “table” to #: filtered-table-4.qza

  2. Set “metric” to braycurtis

  3. Set “clustering_method” to nj

  4. For “metadata”:

    • Perform the following steps.

      1. Leave as Metadata from TSV

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

  5. Set “sampling_depth” to 10000

  6. 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 beta-rarefaction [...] : visualization.qzv

braycurtis-rarefaction-plot.qzv