[med-svn] [Git][med-team/q2-diversity-lib][upstream] New upstream version 2022.8.0

Nilesh Patra (@nilesh) gitlab at salsa.debian.org
Tue Sep 6 14:16:51 BST 2022



Nilesh Patra pushed to branch upstream at Debian Med / q2-diversity-lib


Commits:
ebddb90d by Nilesh Patra at 2022-09-06T18:00:31+05:30
New upstream version 2022.8.0
- - - - -


20 changed files:

- − .github/CONTRIBUTING.md
- − .github/ISSUE_TEMPLATE/1-user-need-help.md
- − .github/ISSUE_TEMPLATE/2-dev-need-help.md
- − .github/ISSUE_TEMPLATE/3-found-bug.md
- − .github/ISSUE_TEMPLATE/4-make-better.md
- − .github/ISSUE_TEMPLATE/5-make-new.md
- − .github/ISSUE_TEMPLATE/6-where-to-go.md
- − .github/SUPPORT.md
- − .github/pull_request_template.md
- − .github/rubric.png
- − .github/workflows/ci.yml
- ci/recipe/meta.yaml
- q2_diversity_lib/_util.py
- q2_diversity_lib/_version.py
- q2_diversity_lib/alpha.py
- q2_diversity_lib/citations.bib
- + q2_diversity_lib/examples.py
- q2_diversity_lib/plugin_setup.py
- + q2_diversity_lib/tests/test_examples.py
- q2_diversity_lib/tests/test_util.py


Changes:

=====================================
.github/CONTRIBUTING.md deleted
=====================================
@@ -1,23 +0,0 @@
-# Contributing to this project
-
-Thanks for thinking of us :heart: :tada: - we would love a helping hand!
-
-## I just have a question
-
-> Note: Please don't file an issue to ask a question. You'll get faster results
-> by using the resources below.
-
-### QIIME 2 Users
-
-Check out the [User Docs](https://docs.qiime2.org) - there are many tutorials,
-walkthroughs, and guides available. If you still need help, please visit us at
-the [QIIME 2 Forum](https://forum.qiime2.org/c/user-support).
-
-### QIIME 2 Developers
-
-Check out the [Developer Docs](https://dev.qiime2.org) - there are many
-tutorials, walkthroughs, and guides available. If you still need help, please
-visit us at the [QIIME 2 Forum](https://forum.qiime2.org/c/dev-discussion).
-
-This document is based heavily on the following:
-https://github.com/atom/atom/blob/master/CONTRIBUTING.md


=====================================
.github/ISSUE_TEMPLATE/1-user-need-help.md deleted
=====================================
@@ -1,14 +0,0 @@
----
-name: I am a user and I need help with QIIME 2...
-about: I am using QIIME 2 and have a question or am experiencing a problem
-
----
-
-Have you had a chance to check out the docs?
-https://docs.qiime2.org
-There are many tutorials, walkthroughs, and guides available.
-
-If you still need help, please visit:
-https://forum.qiime2.org/c/user-support
-
-Help requests filed here will not be answered.


=====================================
.github/ISSUE_TEMPLATE/2-dev-need-help.md deleted
=====================================
@@ -1,12 +0,0 @@
----
-name: I am a developer and I need help with QIIME 2...
-about: I am developing a QIIME 2 plugin or interface and have a question or a problem
-
----
-
-Have you had a chance to check out the developer docs?
-https://dev.qiime2.org
-There are many tutorials, walkthroughs, and guides available.
-
-If you still need help, please visit:
-https://forum.qiime2.org/c/dev-discussion


=====================================
.github/ISSUE_TEMPLATE/3-found-bug.md deleted
=====================================
@@ -1,36 +0,0 @@
----
-name: I am a developer and I found a bug...
-about: I am a developer and I found a bug that I can describe
-
----
-
-**Bug Description**
-A clear and concise description of what the bug is.
-
-**Steps to reproduce the behavior**
-1. Go to '...'
-2. Click on '....'
-3. Scroll down to '....'
-4. See error
-
-**Expected behavior**
-A clear and concise description of what you expected to happen.
-
-**Screenshots**
-If applicable, add screenshots to help explain your problem.
-
-**Computation Environment**
-- OS: [e.g. macOS High Sierra]
-- QIIME 2 Release [e.g. 2018.6]
-
-**Questions**
-1. An enumerated list with any questions about the problem here.
-2. If not applicable, please delete this section.
-
-**Comments**
-1. An enumerated list with any other context or comments about the problem here.
-2. If not applicable, please delete this section.
-
-**References**
-1. An enumerated list of links to relevant references, including forum posts, stack overflow, etc.
-2. If not applicable, please delete this section.


=====================================
.github/ISSUE_TEMPLATE/4-make-better.md deleted
=====================================
@@ -1,26 +0,0 @@
----
-name: I am a developer and I have an idea for an improvement...
-about: I am a developer and I have an idea for an improvement to existing functionality
-
----
-
-**Improvement Description**
-A clear and concise description of what the improvement is.
-
-**Current Behavior**
-Please provide a brief description of the current behavior.
-
-**Proposed Behavior**
-Please provide a brief description of the proposed behavior.
-
-**Questions**
-1. An enumerated list of questions related to the proposal.
-2. If not applicable, please delete this section.
-
-**Comments**
-1. An enumerated list of comments related to the proposal that don't fit anywhere else.
-2. If not applicable, please delete this section.
-
-**References**
-1. An enumerated list of links to relevant references, including forum posts, stack overflow, etc.
-2. If not applicable, please delete this section.


=====================================
.github/ISSUE_TEMPLATE/5-make-new.md deleted
=====================================
@@ -1,26 +0,0 @@
----
-name: I am a developer and I have an idea for a new feature...
-about: I am a developer and I have an idea for new functionality
-
----
-
-**Addition Description**
-A clear and concise description of what the addition is.
-
-**Current Behavior**
-Please provide a brief description of the current behavior, if applicable.
-
-**Proposed Behavior**
-Please provide a brief description of the proposed behavior.
-
-**Questions**
-1. An enumerated list of questions related to the proposal.
-2. If not applicable, please delete this section.
-
-**Comments**
-1. An enumerated list of comments related to the proposal that don't fit anywhere else.
-2. If not applicable, please delete this section.
-
-**References**
-1. An enumerated list of links to relevant references, including forum posts, stack overflow, etc.
-2. If not applicable, please delete this section.


=====================================
.github/ISSUE_TEMPLATE/6-where-to-go.md deleted
=====================================
@@ -1,147 +0,0 @@
----
-name: I don't know where to file my issue...
-about: I am a developer and I don't know which repo to file this in
-
----
-
-The repos within the QIIME 2 GitHub Organization are listed below, with a brief description about the repo.
-
-Sorted alphabetically by repo name.
-
-- The CI automation engine that builds and distributes QIIME 2
-  https://github.com/qiime2/busywork/issues
-
-- A Concourse resource for working with conda
-  https://github.com/qiime2/conda-channel-resource/issues
-
-- Web app for vanity URLs for QIIME 2 data assets
-  https://github.com/qiime2/data.qiime2.org/issues
-
-- The Developer Documentation
-  https://github.com/qiime2/dev-docs/issues
-
-- A discourse plugin for handling queued/unqueued topics
-  https://github.com/qiime2/discourse-unhandled-tagger/issues
-
-- The User Documentation
-  https://github.com/qiime2/docs/issues
-
-- Rendered QIIME 2 environment files for conda
-  https://github.com/qiime2/environment-files/issues
-
-- Google Sheets Add-On for validating tabular data
-  https://github.com/qiime2/Keemei/issues
-
-- A docker image for linux-based busywork workers
-  https://github.com/qiime2/linux-worker-docker/issues
-
-- Official project logos
-  https://github.com/qiime2/logos/issues
-
-- The q2-alignment plugin
-  https://github.com/qiime2/q2-alignment/issues
-
-- The q2-composition plugin
-  https://github.com/qiime2/q2-composition/issues
-
-- The q2-cutadapt plugin
-  https://github.com/qiime2/q2-cutadapt/issues
-
-- The q2-dada2 plugin
-  https://github.com/qiime2/q2-dada2/issues
-
-- The q2-deblur plugin
-  https://github.com/qiime2/q2-deblur/issues
-
-- The q2-demux plugin
-  https://github.com/qiime2/q2-demux/issues
-
-- The q2-diversity plugin
-  https://github.com/qiime2/q2-diversity/issues
-
-- The q2-diversity-lib plugin
-  https://github.com/qiime2/q2-diversity-lib/issues
-
-- The q2-emperor plugin
-  https://github.com/qiime2/q2-emperor/issues
-
-- The q2-feature-classifier plugin
-  https://github.com/qiime2/q2-feature-classifier/issues
-
-- The q2-feature-table plugin
-  https://github.com/qiime2/q2-feature-table/issues
-
-- The q2-fragment-insertion plugin
-  https://github.com/qiime2/q2-fragment-insertion/issues
-
-- The q2-gneiss plugin
-  https://github.com/qiime2/q2-gneiss/issues
-
-- The q2-longitudinal plugin
-  https://github.com/qiime2/q2-longitudinal/issues
-
-- The q2-metadata plugin
-  https://github.com/qiime2/q2-metadata/issues
-
-- The q2-phylogeny plugin
-  https://github.com/qiime2/q2-phylogeny/issues
-
-- The q2-quality-control plugin
-  https://github.com/qiime2/q2-quality-control/issues
-
-- The q2-quality-filter plugin
-  https://github.com/qiime2/q2-quality-filter/issues
-
-- The q2-sample-classifier plugin
-  https://github.com/qiime2/q2-sample-classifier/issues
-
-- The q2-shogun plugin
-  https://github.com/qiime2/q2-shogun/issues
-
-- The q2-taxa plugin
-  https://github.com/qiime2/q2-taxa/issues
-
-- The q2-types plugin
-  https://github.com/qiime2/q2-types/issues
-
-- The q2-vsearch plugin
-  https://github.com/qiime2/q2-vsearch/issues
-
-- The CLI interface
-  https://github.com/qiime2/q2cli/issues
-
-- The prototype CWL interface
-  https://github.com/qiime2/q2cwl/issues
-
-- The prototype Galaxy interface
-  https://github.com/qiime2/q2galaxy/issues
-
-- An internal tool for ensuring header text and copyrights are present
-  https://github.com/qiime2/q2lint/issues
-
-- The prototype GUI interface
-  https://github.com/qiime2/q2studio/issues
-
-- A base template for use in official QIIME 2 plugins
-  https://github.com/qiime2/q2templates/issues
-
-- The read-only web interface at view.qiime2.org
-  https://github.com/qiime2/q2view/issues
-
-- The QIIME 2 homepage at qiime2.org
-  https://github.com/qiime2/qiime2.github.io/issues
-
-- The QIIME 2 framework
-  https://github.com/qiime2/qiime2/issues
-
-- Centralized templates for repo assets
-  https://github.com/qiime2/template-repo/issues
-
-- Scripts for building QIIME 2 VMs
-  https://github.com/qiime2/vm-playbooks/issues
-
-- Scripts for building QIIME 2 workshop clusters
-  https://github.com/qiime2/workshop-playbooks/issues
-
-- The web app that runs workshops.qiime2.org
-  https://github.com/qiime2/workshops.qiime2.org/issues


=====================================
.github/SUPPORT.md deleted
=====================================
@@ -1,112 +0,0 @@
-# QIIME 2 Users
-
-Check out the [User Docs](https://docs.qiime2.org) - there are many tutorials,
-walkthroughs, and guides available. If you still need help, please visit us at
-the [QIIME 2 Forum](https://forum.qiime2.org/c/user-support).
-
-# QIIME 2 Developers
-
-Check out the [Developer Docs](https://dev.qiime2.org) - there are many
-tutorials, walkthroughs, and guides available. If you still need help, please
-visit us at the [QIIME 2 Forum](https://forum.qiime2.org/c/dev-discussion).
-
-# General Bug/Issue Triage Discussion
-
-![rubric](./rubric.png?raw=true)
-
-# Projects/Repositories in the QIIME 2 GitHub Organization
-
-Sorted alphabetically by repo name.
-
-- [busywork](https://github.com/qiime2/busywork/issues)
-  | The CI automation engine that builds and distributes QIIME 2
-- [conda-channel-resource](https://github.com/qiime2/conda-channel-resource/issues)
-  | A Concourse resource for working with conda
-- [data.qiime2.org](https://github.com/qiime2/data.qiime2.org/issues)
-  | Web app for vanity URLs for QIIME 2 data assets
-- [dev-docs](https://github.com/qiime2/dev-docs/issues)
-  | The Developer Documentation
-- [discourse-unhandled-tagger](https://github.com/qiime2/discourse-unhandled-tagger/issues)
-  | A discourse plugin for handling queued/unqueued topics
-- [docs](https://github.com/qiime2/docs/issues)
-  | The User Documentation
-- [environment-files](https://github.com/qiime2/environment-files/issues)
-  | Rendered QIIME 2 environment files for conda
-- [Keemei](https://github.com/qiime2/Keemei/issues)
-  | Google Sheets Add-On for validating tabular data
-- [linux-worker-docker](https://github.com/qiime2/linux-worker-docker/issues)
-  | A docker image for linux-based busywork workers
-- [logos](https://github.com/qiime2/logos/issues)
-  | Official project logos
-- [q2-alignment](https://github.com/qiime2/q2-alignment/issues)
-  | The q2-alignment plugin
-- [q2-composition](https://github.com/qiime2/q2-composition/issues)
-  | The q2-composition plugin
-- [q2-cutadapt](https://github.com/qiime2/q2-cutadapt/issues)
-  | The q2-cutadapt plugin
-- [q2-dada2](https://github.com/qiime2/q2-dada2/issues)
-  | The q2-dada2 plugin
-- [q2-deblur](https://github.com/qiime2/q2-deblur/issues)
-  | The q2-deblur plugin
-- [q2-demux](https://github.com/qiime2/q2-demux/issues)
-  | The q2-demux plugin
-- [q2-diversity](https://github.com/qiime2/q2-diversity/issues)
-  | The q2-diversity plugin
-- [q2-diversity-lib](https://github.com/qiime2/q2-diversity-lib/issues)
-  | The q2-diversity-lib plugin
-- [q2-emperor](https://github.com/qiime2/q2-emperor/issues)
-  | The q2-emperor plugin
-- [q2-feature-classifier](https://github.com/qiime2/q2-feature-classifier/issues)
-  | The q2-feature-classifier plugin
-- [q2-feature-table](https://github.com/qiime2/q2-feature-table/issues)
-  | The q2-feature-table plugin
-- [q2-fragment-insertion](https://github.com/qiime2/q2-fragment-insertion/issues)
-  | The q2-fragment-insertion plugin
-- [q2-gneiss](https://github.com/qiime2/q2-gneiss/issues)
-  | The q2-gneiss plugin
-- [q2-longitudinal](https://github.com/qiime2/q2-longitudinal/issues)
-  | The q2-longitudinal plugin
-- [q2-metadata](https://github.com/qiime2/q2-metadata/issues)
-  | The q2-metadata plugin
-- [q2-phylogeny](https://github.com/qiime2/q2-phylogeny/issues)
-  | The q2-phylogeny plugin
-- [q2-quality-control](https://github.com/qiime2/q2-quality-control/issues)
-  | The q2-quality-control plugin
-- [q2-quality-filter](https://github.com/qiime2/q2-quality-filter/issues)
-  | The q2-quality-filter plugin
-- [q2-sample-classifier](https://github.com/qiime2/q2-sample-classifier/issues)
-  | The q2-sample-classifier plugin
-- [q2-shogun](https://github.com/qiime2/q2-shogun/issues)
-  | The q2-shogun plugin
-- [q2-taxa](https://github.com/qiime2/q2-taxa/issues)
-  | The q2-taxa plugin
-- [q2-types](https://github.com/qiime2/q2-types/issues)
-  | The q2-types plugin
-- [q2-vsearch](https://github.com/qiime2/q2-vsearch/issues)
-  | The q2-vsearch plugin
-- [q2cli](https://github.com/qiime2/q2cli/issues)
-  | The CLI interface
-- [q2cwl](https://github.com/qiime2/q2cwl/issues)
-  | The prototype CWL interface
-- [q2galaxy](https://github.com/qiime2/q2galaxy/issues)
-  | The prototype Galaxy interface
-- [q2lint](https://github.com/qiime2/q2lint/issues)
-  | An internal tool for ensuring header text and copyrights are present
-- [q2studio](https://github.com/qiime2/q2studio/issues)
-  | The prototype GUI interface
-- [q2templates](https://github.com/qiime2/q2templates/issues)
-  | A base template for use in official QIIME 2 plugins
-- [q2view](https://github.com/qiime2/q2view/issues)
-  | The read-only web interface at view.qiime2.org
-- [qiime2.github.io](https://github.com/qiime2/qiime2.github.io/issues)
-  | The QIIME 2 homepage at qiime2.org
-- [qiime2](https://github.com/qiime2/qiime2/issues)
-  | The QIIME 2 framework
-- [template-repo](https://github.com/qiime2/template-repo/issues)
-  | Centralized templates for repo assets
-- [vm-playbooks](https://github.com/qiime2/vm-playbooks/issues)
-  | Scripts for building QIIME 2 VMs
-- [workshop-playbooks](https://github.com/qiime2/workshop-playbooks/issues)
-  | Scripts for building QIIME 2 workshop clusters
-- [workshops.qiime2.org](https://github.com/qiime2/workshops.qiime2.org/issues)
-  | The web app that runs workshops.qiime2.org


=====================================
.github/pull_request_template.md deleted
=====================================
@@ -1,11 +0,0 @@
-Brief summary of the Pull Request, including any issues it may fix using the GitHub closing syntax:
-
-https://help.github.com/articles/closing-issues-using-keywords/
-
-Also, include any co-authors or contributors using the GitHub coauthor tag:
-
-https://help.github.com/articles/creating-a-commit-with-multiple-authors/
-
----
-
-Include any questions for reviewers, screenshots, sample outputs, etc.


=====================================
.github/rubric.png deleted
=====================================
Binary files a/.github/rubric.png and /dev/null differ


=====================================
.github/workflows/ci.yml deleted
=====================================
@@ -1,51 +0,0 @@
-name: ci
-
-on:
-  pull_request:
-  push:
-    branches:
-      - 2022.2-patches
-
-jobs:
-  lint:
-    runs-on: ubuntu-latest
-    steps:
-    - name: checkout source
-      uses: actions/checkout at v2
-
-    - name: set up python 3.8
-      uses: actions/setup-python at v1
-      with:
-        python-version: 3.8
-
-    - name: install dependencies
-      run: python -m pip install --upgrade pip
-
-    - name: lint
-      run: |
-        pip install -q https://github.com/qiime2/q2lint/archive/master.zip
-        q2lint
-        pip install -q flake8
-        flake8
-
-  build-and-test:
-    needs: lint
-    strategy:
-      matrix:
-        os: [ubuntu-latest, macos-latest]
-    runs-on: ${{ matrix.os }}
-    steps:
-    - name: checkout source
-      uses: actions/checkout at v2
-      with:
-        fetch-depth: 0
-
-    - name: set up git repo for versioneer
-      run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
-
-    - uses: qiime2/action-library-packaging at alpha1
-      with:
-        package-name: q2-diversity-lib
-        build-target: release
-        additional-tests: py.test --pyargs q2_diversity_lib
-        library-token: ${{ secrets.LIBRARY_TOKEN }}


=====================================
ci/recipe/meta.yaml
=====================================
@@ -26,8 +26,9 @@ requirements:
     - qiime2 {{ qiime2_epoch }}.*
     - q2-types {{ qiime2_epoch }}.*
     - scikit-bio {{ scikit_bio }}
-    - scipy
+    - scipy {{ scipy }}
     - unifrac {{ unifrac }}
+    - unifrac-binaries {{ unifrac_binaries }}
 
 test:
   requires:


=====================================
q2_diversity_lib/_util.py
=====================================
@@ -18,15 +18,25 @@ import biom
 from q2_types.feature_table import BIOMV210Format
 
 
-def _drop_undefined_samples(counts: np.ndarray, sample_ids: np.ndarray,
-                            minimum_nonzero_elements: int) -> (np.ndarray,
-                                                               np.ndarray):
-    nonzero_elements_per_sample = (counts != 0).sum(axis=1)
-    fancy_index = np.where(
-            nonzero_elements_per_sample < minimum_nonzero_elements)
-    filtered_counts = np.delete(counts, fancy_index, axis=0)
-    filtered_sample_ids = np.delete(sample_ids, fancy_index)
-    return (filtered_counts, filtered_sample_ids)
+def _drop_undefined_samples(table, minimum_nonzero_elements):
+    def f(v, i, m):
+        return (v > 0).sum() >= minimum_nonzero_elements
+    return table.filter(f, inplace=False)
+
+
+def _partition(table, block_size=100):
+    number_of_splits = max(1, np.ceil(len(table.ids()) / block_size))
+    splits = np.array_split(table.ids(), number_of_splits)
+    split_map = {}
+    for idx, split in enumerate(splits):
+        for id_ in split:
+            split_map[id_] = idx
+
+    def part_f(i, m):
+        return split_map[i]
+
+    for _, block in table.partition(part_f):
+        yield block
 
 
 @decorator


=====================================
q2_diversity_lib/_version.py
=====================================
@@ -23,9 +23,9 @@ def get_keywords():
     # setup.py/versioneer.py will grep for the variable names, so they must
     # each be defined on a line of their own. _version.py will just call
     # get_keywords().
-    git_refnames = " (tag: 2022.2.1, 2022.2-patches)"
-    git_full = "50ba304057b7d4821ed47d88417ac0f20f34c7f4"
-    git_date = "2022-05-30 21:32:17 -0700"
+    git_refnames = " (tag: 2022.8.0)"
+    git_full = "edb4e1ae51c65ee99c7530bcbac922ab68f78782"
+    git_date = "2022-08-23 16:28:57 +0000"
     keywords = {"refnames": git_refnames, "full": git_full, "date": git_date}
     return keywords
 


=====================================
q2_diversity_lib/alpha.py
=====================================
@@ -13,7 +13,7 @@ import biom
 from q2_types.feature_table import BIOMV210Format
 from q2_types.sample_data import AlphaDiversityFormat
 from q2_types.tree import NewickFormat
-from ._util import (_drop_undefined_samples,
+from ._util import (_drop_undefined_samples, _partition,
                     _disallow_empty_tables,
                     _validate_requested_cpus,
                     _omp_cmd_wrapper)
@@ -58,25 +58,24 @@ def faith_pd(table: BIOMV210Format, phylogeny: NewickFormat,
 @_disallow_empty_tables
 def observed_features(table: biom.Table) -> pd.Series:
     presence_absence_table = table.pa(inplace=False)
-    counts = presence_absence_table.matrix_data.toarray().astype(int).T
-    sample_ids = presence_absence_table.ids(axis='sample')
-    result = skbio.diversity.alpha_diversity(metric='observed_otus',
-                                             counts=counts, ids=sample_ids)
-    result.name = 'observed_features'
-    return result
+    return pd.Series(presence_absence_table.sum('sample').astype(int),
+                     index=table.ids(), name='observed_features')
 
 
 @_disallow_empty_tables
 def pielou_evenness(table: biom.Table,
                     drop_undefined_samples: bool = False) -> pd.Series:
-    counts = table.matrix_data.toarray().T
-    sample_ids = table.ids(axis='sample')
     if drop_undefined_samples:
-        counts, sample_ids = _drop_undefined_samples(
-                counts, sample_ids, minimum_nonzero_elements=2)
-
-    result = skbio.diversity.alpha_diversity(metric='pielou_e', counts=counts,
-                                             ids=sample_ids)
+        table = _drop_undefined_samples(table, minimum_nonzero_elements=2)
+
+    results = []
+    for partition in _partition(table):
+        counts = partition.matrix_data.T.toarray()
+        sample_ids = partition.ids(axis='sample')
+        results.append(skbio.diversity.alpha_diversity(metric='pielou_e',
+                                                       counts=counts,
+                                                       ids=sample_ids))
+    result = pd.concat(results)
     result.name = 'pielou_evenness'
     return result
 
@@ -84,25 +83,31 @@ def pielou_evenness(table: biom.Table,
 @_disallow_empty_tables
 def shannon_entropy(table: biom.Table,
                     drop_undefined_samples: bool = False) -> pd.Series:
-    counts = table.matrix_data.toarray().T
-    sample_ids = table.ids(axis='sample')
     if drop_undefined_samples:
-        counts, sample_ids = _drop_undefined_samples(
-                counts, sample_ids, minimum_nonzero_elements=1)
-    result = skbio.diversity.alpha_diversity(metric='shannon', counts=counts,
-                                             ids=sample_ids)
+        table = _drop_undefined_samples(table, minimum_nonzero_elements=1)
+
+    results = []
+    for partition in _partition(table):
+        counts = partition.matrix_data.T.toarray()
+        sample_ids = partition.ids(axis='sample')
+        results.append(skbio.diversity.alpha_diversity(metric='shannon',
+                                                       counts=counts,
+                                                       ids=sample_ids))
+    result = pd.concat(results)
     result.name = 'shannon_entropy'
     return result
 
 
 @_disallow_empty_tables
 def alpha_passthrough(table: biom.Table, metric: str) -> pd.Series:
-    # Note: some metrics require ints, but biom.Table seems to default to float
-    # (e.g. ace, lladser_pe, michaelis_menten_fit)
-    counts = table.matrix_data.astype(int).toarray().T
-    sample_ids = table.ids(axis='sample')
-
-    result = skbio.diversity.alpha_diversity(metric=metric, counts=counts,
-                                             ids=sample_ids)
+    results = []
+    for partition in _partition(table):
+        counts = partition.matrix_data.astype(int).T.toarray()
+        sample_ids = partition.ids(axis='sample')
+
+        results.append(skbio.diversity.alpha_diversity(metric=metric,
+                                                       counts=counts,
+                                                       ids=sample_ids))
+    result = pd.concat(results)
     result.name = metric
     return result


=====================================
q2_diversity_lib/citations.bib
=====================================
@@ -82,6 +82,27 @@
   doi = {10.1038/s41592-018-0187-8}
 }
 
+ at article{sfiligoi2022unifrac,
+    title = {Optimizing UniFrac with OpenACC yields >1000x speed increase},
+    author = {Sfiligoi, Igor and Armstrong, George and Gonzalez, Antonio and McDonald, Daniel and Knight, Rob},
+    journal = {mSystems},
+    year = {in press}
+}
+
+ at article{armstrong2021faithspd,
+    author = {Armstrong, George and Cantrell, Kalen and Huang, Shi and McDonald, Daniel and Haiminen, Niina and Carrieri, Anna Paola and Zhu, Qiyun and Gonzalez, Antonio and McGrath, Imran and Beck, Kristen L. and Hakim, Daniel and Havulinna, Aki S. and Méric, Guillaume and Niiranen, Teemu and Lahti, Leo and Salomaa, Veikko and Jain, Mohit and Inouye, Michael and Swafford, Austin D. and Kim, Ho-Cheol and Parida, Laxmi and Vázquez-Baeza, Yoshiki and Knight, Rob}, 
+    title = {Efficient computation of Faith's phylogenetic diversity with applications in characterizing microbiomes},
+    volume = {31}, 
+    number = {11}, 
+    pages = {2131-2137}, 
+    year = {2021}, 
+    doi = {10.1101/gr.275777.121}, 
+    abstract ={The number of publicly available microbiome samples is continually growing. As data set size increases, bottlenecks arise in standard analytical pipelines. Faith's phylogenetic diversity (Faith's PD) is a highly utilized phylogenetic alpha diversity metric that has thus far failed to effectively scale to trees with millions of vertices. Stacked Faith's phylogenetic diversity (SFPhD) enables calculation of this widely adopted diversity metric at a much larger scale by implementing a computationally efficient algorithm. The algorithm reduces the amount of computational resources required, resulting in more accessible software with a reduced carbon footprint, as compared to previous approaches. The new algorithm produces identical results to the previous method. We further demonstrate that the phylogenetic aspect of Faith's PD provides increased power in detecting diversity differences between younger and older populations in the FINRISK study's metagenomic data.}, 
+    URL = {http://genome.cshlp.org/content/31/11/2131.abstract}, 
+    eprint = {http://genome.cshlp.org/content/31/11/2131.full.pdf+html}, 
+    journal = {Genome Research} 
+}
+
 @article {lozupone2005unifrac,
 	author = {Lozupone, Catherine and Knight, Rob},
 	title = {UniFrac: a New Phylogenetic Method for Comparing Microbial Communities},


=====================================
q2_diversity_lib/examples.py
=====================================
@@ -0,0 +1,516 @@
+# ----------------------------------------------------------------------------
+# Copyright (c) 2018-2022, QIIME 2 development team.
+#
+# Distributed under the terms of the Modified BSD License.
+#
+# The full license is in the file LICENSE, distributed with this software.
+# ----------------------------------------------------------------------------
+
+import biom
+import numpy as np
+import pkg_resources
+
+from qiime2 import Artifact
+
+
+def get_test_data_path(filename):
+    return pkg_resources.resource_filename('q2_diversity_lib.tests',
+                                           f'data/{filename}')
+
+
+s_ids_1 = ['S1', 'S2', 'S3', 'S4', 'S5']
+s_ids_2 = ['S6', 'S7', 'S8', 'S9', 'S10']
+
+
+def ft1_factory():
+    return Artifact.import_data(
+        'FeatureTable[Frequency]',
+        biom.Table(np.array([[1, 0, 5, 999, 1],
+                            [0, 1, 2, 0, 5],
+                            [0, 0, 0, 1, 10]]),
+                   ['A', 'B', 'C'],
+                   s_ids_1)
+    )
+
+
+def ft2_factory():
+    return Artifact.import_data(
+        'FeatureTable[Frequency]',
+        biom.Table(np.array([[1, 10, 5, 999, 1],
+                            [5, 1, 2, 0, 5],
+                            [1, 40, 30, 10, 0]]),
+                   ['A', 'B', 'C'],
+                   s_ids_2)
+    )
+
+
+def tree_factory():
+    input_tree_fp = get_test_data_path('faith_test.tree')
+    return Artifact.import_data(
+        'Phylogeny[Rooted]', input_tree_fp
+    )
+
+
+# ------------------------ alpha-diversity -----------------------
+def faith_pd_example(use):
+    ft = use.init_artifact('feature_table', ft1_factory)
+    tree = use.init_artifact('phylogeny', tree_factory)
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='faith_pd'),
+        use.UsageInputs(table=ft, phylogeny=tree),
+        use.UsageOutputNames(vector='faith_pd_vector'))
+    result.assert_output_type('SampleData[AlphaDiversity]')
+
+
+def observed_features_example(use):
+    ft = use.init_artifact('feature_table', ft1_factory)
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='observed_features'),
+        use.UsageInputs(table=ft),
+        use.UsageOutputNames(vector='obs_feat_vector'))
+    result.assert_output_type('SampleData[AlphaDiversity]')
+
+    # AssertRegex for lines in output files
+    exp = zip(s_ids_1, [1, 1, 2, 2, 3])
+    for id, val in exp:
+        result.assert_has_line_matching(
+            path='alpha-diversity.tsv',
+            expression=f'{id}\t{val}'
+        )
+
+
+def pielou_evenness_example(use):
+    ft = use.init_artifact('feature_table', ft1_factory)
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='pielou_evenness'),
+        use.UsageInputs(table=ft),
+        use.UsageOutputNames(vector='pielou_vector')
+    )
+    result.assert_output_type('SampleData[AlphaDiversity]')
+
+
+def pielou_drop_example(use):
+    ft = use.init_artifact('feature_table', ft1_factory)
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='pielou_evenness'),
+        use.UsageInputs(table=ft, drop_undefined_samples=True),
+        use.UsageOutputNames(vector='pielou_vector')
+    )
+    result.assert_output_type('SampleData[AlphaDiversity]')
+
+
+def shannon_entropy_example(use):
+    ft = use.init_artifact('feature_table', ft1_factory)
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='shannon_entropy'),
+        use.UsageInputs(table=ft),
+        use.UsageOutputNames(vector='shannon_vector')
+    )
+    result.assert_output_type('SampleData[AlphaDiversity]')
+
+
+def shannon_drop_example(use):
+    ft = use.init_artifact('feature_table', ft1_factory)
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='shannon_entropy'),
+        use.UsageInputs(table=ft, drop_undefined_samples=True),
+        use.UsageOutputNames(vector='shannon_vector')
+    )
+    result.assert_output_type('SampleData[AlphaDiversity]')
+
+
+# ------------------------ beta-diversity -----------------------
+def bray_curtis_example(use):
+    ft = use.init_artifact('feature_table', ft1_factory)
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='bray_curtis'),
+        use.UsageInputs(table=ft),
+        use.UsageOutputNames(distance_matrix='bray_curtis_dm')
+    )
+    result.assert_output_type('DistanceMatrix')
+
+
+def bray_curtis_n_jobs_example(use):
+    ft = use.init_artifact('feature_table', ft1_factory)
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='bray_curtis'),
+        use.UsageInputs(table=ft, n_jobs=1),
+        use.UsageOutputNames(distance_matrix='bray_curtis_dm')
+    )
+    result.assert_output_type('DistanceMatrix')
+
+
+def bray_curtis_auto_jobs_example(use):
+    ft = use.init_artifact('feature_table', ft1_factory)
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='bray_curtis'),
+        use.UsageInputs(table=ft, n_jobs='auto'),
+        use.UsageOutputNames(distance_matrix='bray_curtis_dm')
+    )
+    result.assert_output_type('DistanceMatrix')
+
+
+def jaccard_example(use):
+    ft = use.init_artifact('feature_table', ft1_factory)
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='jaccard'),
+        use.UsageInputs(table=ft),
+        use.UsageOutputNames(distance_matrix='jaccard_dm')
+    )
+    result.assert_output_type('DistanceMatrix')
+
+
+def jaccard_n_jobs_example(use):
+    ft = use.init_artifact('feature_table', ft1_factory)
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='jaccard'),
+        use.UsageInputs(table=ft, n_jobs=1),
+        use.UsageOutputNames(distance_matrix='jaccard_dm')
+    )
+    result.assert_output_type('DistanceMatrix')
+
+
+def jaccard_auto_jobs_example(use):
+    ft = use.init_artifact('feature_table', ft1_factory)
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='jaccard'),
+        use.UsageInputs(table=ft, n_jobs='auto'),
+        use.UsageOutputNames(distance_matrix='jaccard_dm')
+    )
+    result.assert_output_type('DistanceMatrix')
+
+
+def u_u_example(use):
+    ft = use.init_artifact('feature_table', ft1_factory)
+    tree = use.init_artifact('phylogeny', tree_factory)
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='unweighted_unifrac'),
+        use.UsageInputs(table=ft, phylogeny=tree),
+        use.UsageOutputNames(distance_matrix='unweighted_unifrac_dm')
+    )
+    result.assert_output_type('DistanceMatrix')
+
+
+def u_u_n_threads_example(use):
+    ft = use.init_artifact('feature_table', ft1_factory)
+    tree = use.init_artifact('phylogeny', tree_factory)
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='unweighted_unifrac'),
+        use.UsageInputs(table=ft, phylogeny=tree, threads=1),
+        use.UsageOutputNames(distance_matrix='unweighted_unifrac_dm')
+    )
+    result.assert_output_type('DistanceMatrix')
+
+
+def u_u_auto_threads_example(use):
+    ft = use.init_artifact('feature_table', ft1_factory)
+    tree = use.init_artifact('phylogeny', tree_factory)
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='unweighted_unifrac'),
+        use.UsageInputs(table=ft, phylogeny=tree, threads='auto'),
+        use.UsageOutputNames(distance_matrix='unweighted_unifrac_dm')
+    )
+    result.assert_output_type('DistanceMatrix')
+
+
+def u_u_bypass_tips_example(use):
+    ft = use.init_artifact('feature_table', ft1_factory)
+    tree = use.init_artifact('phylogeny', tree_factory)
+    use.comment("bypass_tips can be used with any threads setting, "
+                "but auto may be a good choice if you're trimming run time.")
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='unweighted_unifrac'),
+        use.UsageInputs(table=ft, phylogeny=tree,
+                        threads='auto', bypass_tips=True),
+        use.UsageOutputNames(distance_matrix='unweighted_unifrac_dm')
+    )
+    result.assert_output_type('DistanceMatrix')
+
+
+def w_u_example(use):
+    ft = use.init_artifact('feature_table', ft1_factory)
+    tree = use.init_artifact('phylogeny', tree_factory)
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='weighted_unifrac'),
+        use.UsageInputs(table=ft, phylogeny=tree),
+        use.UsageOutputNames(distance_matrix='weighted_unifrac_dm')
+    )
+    result.assert_output_type('DistanceMatrix')
+
+
+def w_u_n_threads_example(use):
+    ft = use.init_artifact('feature_table', ft1_factory)
+    tree = use.init_artifact('phylogeny', tree_factory)
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='weighted_unifrac'),
+        use.UsageInputs(table=ft, phylogeny=tree, threads=1),
+        use.UsageOutputNames(distance_matrix='weighted_unifrac_dm')
+    )
+    result.assert_output_type('DistanceMatrix')
+
+
+def w_u_auto_threads_example(use):
+    ft = use.init_artifact('feature_table', ft1_factory)
+    tree = use.init_artifact('phylogeny', tree_factory)
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='weighted_unifrac'),
+        use.UsageInputs(table=ft, phylogeny=tree, threads='auto'),
+        use.UsageOutputNames(distance_matrix='weighted_unifrac_dm')
+    )
+    result.assert_output_type('DistanceMatrix')
+
+
+def w_u_bypass_tips_example(use):
+    ft = use.init_artifact('feature_table', ft1_factory)
+    tree = use.init_artifact('phylogeny', tree_factory)
+    use.comment("bypass_tips can be used with any threads setting, "
+                "but auto may be a good choice if you're trimming run time.")
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='weighted_unifrac'),
+        use.UsageInputs(table=ft, phylogeny=tree,
+                        threads='auto', bypass_tips=True),
+        use.UsageOutputNames(distance_matrix='weighted_unifrac_dm')
+    )
+    result.assert_output_type('DistanceMatrix')
+
+
+# ------------------------ Passthrough Methods ------------------------
+def alpha_passthrough_example(use):
+    ft = use.init_artifact('feature_table', ft1_factory)
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='alpha_passthrough'),
+        use.UsageInputs(table=ft, metric='simpson'),
+        use.UsageOutputNames(vector='simpson_vector')
+    )
+    result.assert_output_type('SampleData[AlphaDiversity]')
+
+
+def beta_passthrough_example(use):
+    ft = use.init_artifact('feature_table', ft1_factory)
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='beta_passthrough'),
+        use.UsageInputs(table=ft, metric='euclidean'),
+        use.UsageOutputNames(distance_matrix='euclidean_dm')
+    )
+    result.assert_output_type('DistanceMatrix')
+
+
+def beta_passthrough_n_jobs_example(use):
+    ft = use.init_artifact('feature_table', ft1_factory)
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='beta_passthrough'),
+        use.UsageInputs(table=ft, metric='kulsinski', n_jobs=1),
+        use.UsageOutputNames(distance_matrix='kulsinski_dm')
+    )
+    result.assert_output_type('DistanceMatrix')
+
+
+def beta_passthrough_auto_jobs_example(use):
+    ft = use.init_artifact('feature_table', ft1_factory)
+    use.comment("A default pseudocount of 1 is added to feature counts. "
+                "Pseudocount is ignored for non-compositional metrics.")
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='beta_passthrough'),
+        use.UsageInputs(table=ft, metric='aitchison', n_jobs='auto'),
+        use.UsageOutputNames(distance_matrix='aitchison_dm')
+    )
+    result.assert_output_type('DistanceMatrix')
+
+
+def beta_passthrough_pseudocount_example(use):
+    ft = use.init_artifact('feature_table', ft1_factory)
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='beta_passthrough'),
+        use.UsageInputs(table=ft, metric='aitchison', n_jobs='auto',
+                        pseudocount=5),
+        use.UsageOutputNames(distance_matrix='aitchison_dm')
+    )
+    result.assert_output_type('DistanceMatrix')
+
+
+def beta_phylo_passthrough_example(use):
+    ft = use.init_artifact('feature_table', ft1_factory)
+    tree = use.init_artifact('phylogeny', tree_factory)
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='beta_phylogenetic_passthrough'),
+        use.UsageInputs(table=ft, phylogeny=tree,
+                        metric='weighted_normalized_unifrac'),
+        use.UsageOutputNames(distance_matrix='weighted_normalized_unifrac_dm')
+    )
+    result.assert_output_type('DistanceMatrix')
+
+
+def beta_phylo_passthrough_n_threads_example(use):
+    ft = use.init_artifact('feature_table', ft1_factory)
+    tree = use.init_artifact('phylogeny', tree_factory)
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='beta_phylogenetic_passthrough'),
+        use.UsageInputs(table=ft, phylogeny=tree, threads=1,
+                        metric='weighted_normalized_unifrac'),
+        use.UsageOutputNames(distance_matrix='weighted_normalized_unifrac_dm')
+    )
+    result.assert_output_type('DistanceMatrix')
+
+
+def beta_phylo_passthrough_auto_threads_example(use):
+    ft = use.init_artifact('feature_table', ft1_factory)
+    tree = use.init_artifact('phylogeny', tree_factory)
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='beta_phylogenetic_passthrough'),
+        use.UsageInputs(table=ft, phylogeny=tree, threads='auto',
+                        metric='weighted_normalized_unifrac'),
+        use.UsageOutputNames(distance_matrix='weighted_normalized_unifrac_dm')
+    )
+    result.assert_output_type('DistanceMatrix')
+
+
+def beta_phylo_passthrough_bypass_tips_example(use):
+    ft = use.init_artifact('feature_table', ft1_factory)
+    tree = use.init_artifact('phylogeny', tree_factory)
+    use.comment("bypass_tips can be used with any threads setting, "
+                "but auto may be a good choice if you're trimming run time.")
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='beta_phylogenetic_passthrough'),
+        use.UsageInputs(table=ft, phylogeny=tree,
+                        metric='weighted_normalized_unifrac',
+                        threads='auto', bypass_tips=True),
+        use.UsageOutputNames(distance_matrix='weighted_normalized_unifrac_dm')
+    )
+    result.assert_output_type('DistanceMatrix')
+
+
+def beta_phylo_passthrough_variance_adjusted_example(use):
+    use.comment(
+        "Chang et al's variance adjustment may be applied to any unifrac "
+        "method by using this passthrough function.")
+    ft = use.init_artifact('feature_table', ft1_factory)
+    tree = use.init_artifact('phylogeny', tree_factory)
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='beta_phylogenetic_passthrough'),
+        use.UsageInputs(table=ft, phylogeny=tree,
+                        metric='weighted_unifrac',
+                        threads='auto',
+                        variance_adjusted=True),
+        use.UsageOutputNames(distance_matrix='var_adj_weighted_unifrac_dm')
+    )
+    result.assert_output_type('DistanceMatrix')
+
+
+def beta_phylo_passthrough_min_generalized_unifrac_example(use):
+    use.comment(
+        "Generalized unifrac is passed alpha=1 by default. "
+        "This is roughly equivalent to weighted normalized unifrac, "
+        "which method will be used instead, because it is better optimized."
+    )
+    ft = use.init_artifact('feature_table', ft1_factory)
+    tree = use.init_artifact('phylogeny', tree_factory)
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='beta_phylogenetic_passthrough'),
+        use.UsageInputs(table=ft, phylogeny=tree,
+                        metric='generalized_unifrac'),
+        use.UsageOutputNames(distance_matrix='generalized_unifrac_dm')
+    )
+    result.assert_output_type('DistanceMatrix')
+
+
+def beta_phylo_passthrough_generalized_unifrac_example(use):
+    use.comment("passing a float between 0 and 1 to 'alpha' gives you control "
+                "over the importance of sample proportions.")
+    ft = use.init_artifact('feature_table', ft1_factory)
+    tree = use.init_artifact('phylogeny', tree_factory)
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='beta_phylogenetic_passthrough'),
+        use.UsageInputs(table=ft, phylogeny=tree,
+                        metric='generalized_unifrac',
+                        alpha=0.75),
+        use.UsageOutputNames(distance_matrix='generalized_unifrac_dm')
+    )
+    result.assert_output_type('DistanceMatrix')
+
+
+def beta_phylo_meta_passthrough_example(use):
+    use.comment(
+        "For brevity, these examples are focused on meta-specific parameters. "
+        "See the documentation for beta_phylogenetic_passthrough for "
+        "additional relevant information."
+    )
+    ft1 = use.init_artifact('feature_table1', ft1_factory)
+    ft2 = use.init_artifact('feature_table2', ft2_factory)
+    tree1 = use.init_artifact('phylogeny1', tree_factory)
+    tree2 = use.init_artifact('phylogeny2', tree_factory)
+    use.comment("NOTE: the number of trees and tables must match.")
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='beta_phylogenetic_meta_passthrough'),
+        use.UsageInputs(tables=[ft1, ft2], phylogenies=[tree1, tree2],
+                        metric='weighted_normalized_unifrac'),
+        use.UsageOutputNames(distance_matrix='ft1_ft2_w_norm_unifrac_dm')
+    )
+    result.assert_output_type('DistanceMatrix')
+
+
+def beta_phylo_meta_weights_example(use):
+    ft1 = use.init_artifact('feature_table1', ft1_factory)
+    ft2 = use.init_artifact('feature_table2', ft2_factory)
+    tree = use.init_artifact('phylogeny', tree_factory)
+    use.comment("The number of weights must match the number of tables/trees.")
+    use.comment("If meaningful, it is possible to pass the same phylogeny "
+                "more than once.")
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='beta_phylogenetic_meta_passthrough'),
+        use.UsageInputs(tables=[ft1, ft2], phylogenies=[tree, tree],
+                        metric='weighted_normalized_unifrac',
+                        weights=[3.0, 42.0]),
+        use.UsageOutputNames(distance_matrix='ft1_ft2_w_norm_unifrac_dm')
+    )
+    result.assert_output_type('DistanceMatrix')
+
+
+def beta_phylo_meta_consolidation_example(use):
+    ft1 = use.init_artifact('feature_table1', ft1_factory)
+    ft2 = use.init_artifact('feature_table2', ft2_factory)
+    tree1 = use.init_artifact('phylogeny1', tree_factory)
+    tree2 = use.init_artifact('phylogeny2', tree_factory)
+    result, = use.action(
+        use.UsageAction(plugin_id='diversity_lib',
+                        action_id='beta_phylogenetic_meta_passthrough'),
+        use.UsageInputs(tables=[ft1, ft2], phylogenies=[tree1, tree2],
+                        metric='weighted_normalized_unifrac',
+                        weights=[0.4, 0.6],
+                        consolidation='skipping_missing_values'),
+        use.UsageOutputNames(distance_matrix='ft1_ft2_w_norm_unifrac_dm')
+    )
+    result.assert_output_type('DistanceMatrix')


=====================================
q2_diversity_lib/plugin_setup.py
=====================================
@@ -15,7 +15,7 @@ from q2_types.sample_data import AlphaDiversity, SampleData
 from q2_types.distance_matrix import DistanceMatrix
 from unifrac._meta import CONSOLIDATIONS
 
-from . import alpha, beta, __version__
+from . import alpha, beta, __version__, examples
 
 citations = Citations.load('citations.bib', package='q2_diversity_lib')
 plugin = Plugin(
@@ -73,7 +73,9 @@ plugin.methods.register_function(
     name="Faith's Phylogenetic Diversity",
     description="Computes Faith's Phylogenetic Diversity for all samples in "
                 "a feature table.",
-    citations=[citations['faith1992conservation']]
+    examples={'basic': examples.faith_pd_example},
+    citations=[citations['faith1992conservation'],
+               citations['armstrong2021faithspd']]
 )
 
 plugin.methods.register_function(
@@ -91,7 +93,8 @@ plugin.methods.register_function(
                                    "observed features."},
     name="Observed Features",
     description="Compute the number of observed features for each sample in a "
-                "feature table"
+                "feature table",
+    examples={'basic': examples.observed_features_example}
 )
 
 plugin.methods.register_function(
@@ -110,6 +113,8 @@ plugin.methods.register_function(
     name="Pielou's Evenness",
     description="Compute Pielou's Evenness for each sample in a "
                 "feature table",
+    examples={'basic': examples.pielou_evenness_example,
+              'dropping undefined samples': examples.pielou_drop_example},
     citations=[citations['pielou1966measurement']]
 )
 
@@ -130,6 +135,8 @@ plugin.methods.register_function(
     name="Shannon's Entropy",
     description="Compute Shannon's Entropy for each sample in a "
                 "feature table",
+    examples={'basic': examples.shannon_entropy_example,
+              'dropping undefined samples': examples.shannon_drop_example},
     citations=[citations['shannon1948communication']]
 )
 
@@ -154,6 +161,12 @@ plugin.methods.register_function(
                 "identical. Please consider the impact on your results if "
                 "you use Bray-Curtis with count data that has not been "
                 "adjusted (normalized).",
+    examples={"run on one core (by default)": examples.bray_curtis_example,
+              "to run on n cores, replace 1 here with your preferred integer":
+              examples.bray_curtis_n_jobs_example,
+              "use 'auto' to run on all of host system's available CPU cores":
+              examples.bray_curtis_auto_jobs_example,
+              },
     citations=[citations['sorensen1948method']])
 
 # TODO: Augment citations as needed
@@ -175,6 +188,12 @@ plugin.methods.register_function(
                 "presence/absence data. Data of type "
                 "FeatureTable[Frequency | Relative Frequency] is reduced"
                 "to presence/absence prior to calculation.",
+    examples={"run on one core (by default)": examples.jaccard_example,
+              "to run on n cores, replace 1 here with your preferred integer":
+              examples.jaccard_n_jobs_example,
+              "use 'auto' to run on all of host system's available CPU cores":
+              examples.jaccard_auto_jobs_example,
+              },
     citations=[citations['jaccard1908nouvelles']])
 
 
@@ -207,6 +226,14 @@ plugin.methods.register_function(
     name="Unweighted Unifrac",
     description="Compute Unweighted Unifrac for each sample in a "
                 "feature table",
+    examples={"run on one core (by default)": examples.u_u_example,
+              "to run on n cores, replace 1 here with your preferred integer":
+              examples.u_u_n_threads_example,
+              "use 'auto' to run on all of host system's available CPU cores":
+              examples.u_u_auto_threads_example,
+              "use bypass_tips to trade specificity for reduced compute time":
+              examples.u_u_bypass_tips_example,
+              },
     citations=[
         citations['lozupone2005unifrac'],
         citations['lozupone2007unifrac'],
@@ -243,6 +270,14 @@ plugin.methods.register_function(
     name="Weighted Unifrac",
     description="Compute Weighted Unifrac for each sample in a "
                 "feature table",
+    examples={"run on one core (by default)": examples.w_u_example,
+              "to run on n cores, replace 1 here with your preferred integer":
+              examples.w_u_n_threads_example,
+              "use 'auto' to run on all of host system's available CPU cores":
+              examples.w_u_auto_threads_example,
+              "use bypass_tips to trade specificity for reduced compute time":
+              examples.w_u_bypass_tips_example,
+              },
     citations=[
         citations['lozupone2005unifrac'],
         citations['lozupone2007unifrac'],
@@ -266,7 +301,8 @@ plugin.methods.register_function(
     name="Alpha Passthrough (non-phylogenetic)",
     description="Computes a vector of values (one value for each samples in a "
                 "feature table) using the scikit-bio implementation of the "
-                "selected alpha diversity metric."
+                "selected alpha diversity metric.",
+    examples={'basic': examples.alpha_passthrough_example},
 )
 
 
@@ -293,6 +329,16 @@ plugin.methods.register_function(
     description="Computes a distance matrix for all pairs of samples in a "
                 "feature table using the scikit-bio implementation of the "
                 "selected beta diversity metric.",
+    examples={"run on one core (by default)":
+              examples.beta_passthrough_example,
+              "to run on n cores, replace 1 here with your preferred integer":
+              examples.beta_passthrough_n_jobs_example,
+              "use 'auto' to run on all of host system's available CPU cores":
+              examples.beta_passthrough_auto_jobs_example,
+              "use 'pseudocount' to manually set a pseudocount for " +
+              "compositional metrics":
+              examples.beta_passthrough_pseudocount_example,
+              },
 )
 
 
@@ -339,6 +385,21 @@ plugin.methods.register_function(
     description="Computes a distance matrix for all pairs of samples in a "
                 "feature table using the unifrac implementation of the "
                 "selected beta diversity metric.",
+    examples={"run on one core (by default)":
+              examples.beta_phylo_passthrough_example,
+              "to run on n cores, replace 1 here with your preferred integer":
+              examples.beta_phylo_passthrough_n_threads_example,
+              "use 'auto' to run on all of host system's available CPU cores":
+              examples.beta_phylo_passthrough_auto_threads_example,
+              "use bypass_tips to trade specificity for reduced compute time":
+              examples.beta_phylo_passthrough_bypass_tips_example,
+              "variance adjustment":
+              examples.beta_phylo_passthrough_variance_adjusted_example,
+              "minimal generalized unifrac":
+              examples.beta_phylo_passthrough_min_generalized_unifrac_example,
+              "generalized unifrac":
+              examples.beta_phylo_passthrough_generalized_unifrac_example,
+              },
     citations=[
         citations['lozupone2005unifrac'],
         citations['lozupone2007unifrac'],
@@ -346,7 +407,8 @@ plugin.methods.register_function(
         citations['lozupone2011unifrac'],
         citations['mcdonald2018unifrac'],
         citations['chang2011variance'],
-        citations['chen2012genUnifrac']
+        citations['chen2012genUnifrac'],
+        citations['sfiligoi2022unifrac']
     ]
 )
 
@@ -402,6 +464,12 @@ plugin.methods.register_function(
     description="Computes a distance matrix for all pairs of samples in the "
                 "set of feature table and phylogeny pairs, using the unifrac "
                 "implementation of the selected beta diversity metric.",
+    examples={
+        "Basic meta unifrac": examples.beta_phylo_meta_passthrough_example,
+        "meta with weights": examples.beta_phylo_meta_weights_example,
+        "changing the consolidation method":
+        examples.beta_phylo_meta_consolidation_example,
+    },
     citations=[
         citations['lozupone2005unifrac'],
         citations['lozupone2007unifrac'],


=====================================
q2_diversity_lib/tests/test_examples.py
=====================================
@@ -0,0 +1,16 @@
+# ----------------------------------------------------------------------------
+# Copyright (c) 2018-2022, QIIME 2 development team.
+#
+# Distributed under the terms of the Modified BSD License.
+#
+# The full license is in the file LICENSE, distributed with this software.
+# ----------------------------------------------------------------------------
+
+from qiime2.plugin.testing import TestPluginBase
+
+
+class UsageExampleTests(TestPluginBase):
+    package = 'q2_diversity_lib.tests'
+
+    def test_usage_examples(self):
+        self.execute_examples()


=====================================
q2_diversity_lib/tests/test_util.py
=====================================
@@ -9,6 +9,7 @@
 from unittest import mock
 
 import numpy as np
+import numpy.testing as npt
 import biom
 import psutil
 from qiime2 import Artifact
@@ -16,7 +17,31 @@ from qiime2.plugin.testing import TestPluginBase
 from q2_types.feature_table import BIOMV210Format
 from q2_types.tree import NewickFormat
 
-from .._util import _disallow_empty_tables, _validate_requested_cpus
+from .._util import (_disallow_empty_tables, _validate_requested_cpus,
+                     _partition)
+
+
+class PartitionTests(TestPluginBase):
+    package = 'q2_diversity_lib.tests'
+
+    def test_table_below_batch_size(self):
+        tab = biom.example_table.copy()
+        partitions = list(_partition(tab, block_size=10))
+        self.assertEqual(len(partitions), 1)
+        self.assertEqual(tab, partitions[0])
+
+    def test_table_above_batch_size(self):
+        tab = biom.example_table.copy()
+        partitions = list(_partition(tab, block_size=2))
+        self.assertEqual(len(partitions), 2)
+        npt.assert_equal(partitions[0].ids(), tab.ids()[:2])
+        npt.assert_equal(partitions[1].ids(), tab.ids()[2])
+
+    def test_table_equal_to_batch_size(self):
+        tab = biom.example_table.copy()
+        partitions = list(_partition(tab, block_size=3))
+        self.assertEqual(len(partitions), 1)
+        self.assertEqual(tab, partitions[0])
 
 
 class DisallowEmptyTablesTests(TestPluginBase):



View it on GitLab: https://salsa.debian.org/med-team/q2-diversity-lib/-/commit/ebddb90d643e998c4264e28e886830ed1b766550

-- 
View it on GitLab: https://salsa.debian.org/med-team/q2-diversity-lib/-/commit/ebddb90d643e998c4264e28e886830ed1b766550
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20220906/24bf8dd5/attachment-0001.htm>


More information about the debian-med-commit mailing list