# 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,
)

qiime feature-table summarize \
--i-table filtered-table-4.qza \
--o-visualization filtered-table-4-summ.qzv

use.action(
use.UsageAction(plugin_id='feature_table', action_id='summarize'),
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

• 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'},
max_depth=33000,
)

qiime diversity alpha-rarefaction \
--i-table filtered-table-4.qza \
--p-metrics shannon \
--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'},
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.)

• 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

• shannon-rarefaction-plot.qzv | view | download

## 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,
)

qiime diversity beta-rarefaction \
--i-table filtered-table-4.qza \
--p-metric braycurtis \
--p-clustering-method nj \
--p-sampling-depth 10000 \
--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,
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

• 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

• braycurtis-rarefaction-plot.qzv | view | download