I'm having a technical issue following the Artifact API page

Hi, I’m relatively new to QIIME2 and this is my very first post at the forum. First off, thank you very much for your hard work! QIIME2 is one of the most well-documented and easy-to-use tools I have worked with.

That said, I’m having an issue when trying to follow the little tutorial in the Artifact API page, specifically this part:

>>> from qiime2.plugins import diversity
>>> alpha_result = diversity.methods.alpha(table=rarefied_table, metric='observed_features')

When I try above, I get the following error:

AttributeError                            Traceback (most recent call last)
<ipython-input-8-c293158ee7dc> in <module>
----> 1 alpha_result = diversity.methods.alpha(table=rarefied_table, metric='observed_otus')

AttributeError: module 'qiime2.plugins.diversity.methods' has no attribute 'alpha'

I have a feeling that there got to be an easy explanation for this, but I just can’t think of one. Can anyone enlighten me what went wrong?


Welcome to the forum @sbslee and thanks for your kind comments!

The short answer is that the q2-diversity plugin was updated recently to make the alpha method into a pipeline. So you can replace diversity.methods.alpha with diversity.actions.alpha to use that action.

Thanks for bringing this up, we can fix this in the next release of the QIIME 2 docs (most tutorials are automatically tested but this one is not).

I have assigned @ChrisKeefe, he may be able to give you more insight on the changes to alpha if needed.

Good luck!

1 Like

Thanks for catching that documentation bug :bug: , @sbslee!
And sorry! That must have been frustrating. We undertook a major reorganization of q2-diversity during the last two release cycles (2020.6, 2020.8), during which alpha, beta, and their phylogenetic counterparts were refactored as pipelines. This failure to update the docs slipped through.

If you run into this again, here’s a trick. In QIIME 2, there are three types of Actions: Methods, Pipelines, and Visualizers. (They all subclass Action, if you’re familiar with object-oriented programming concepts).

If you’re not sure which type of Action the command you want is, the API should let you use the more-general <plugin>.action.<command> syntax in place of, say, <plugin>.methods.<command>. @Nicholas_Bokulich’s example above does exactly that:

If you’re using tab-complete, it’s usually easier to find what you’re looking for if you use the right type:

… but you’ll notice that alpha shows up alongside everything else in the complete list of Actions:

Thanks again for calling this to our attention! I’ll fix it ASAP.
Chris :baby_chick:

EDIT: This issue will be fixed here.


Thank you very much for your detailed explanation, Chris! I have been using QIIME2 CLI extensively, but now I want to work more with the QIIME2 Python API. Your reply is very useful in this regard. Keep up the great work!

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.