Longitudinal ANOVA using the artifact API

Hi all,
I really enjoy using the artifact API to create jupyter notebooks for all my work with Qiime2.

But due to little documentation for plugin usage with the python API I need your help using the longitudinal ANOVA visualization plugin (in qiime2-2020.8)

The task is to test whether multiple effect impact alpha diversity (in this case, the pielou eveness). Let me start by saying this plugin works in the CLI version as follows:
qiime longitudinal anova
–m-metadata-file ./alpha_vector_pielou.qza
–m-metadata-file ./metadata.tsv
–p-formula ‘pielou_evenness ~ Salinity * Tank’
–o-visualization ./alpha_anova_pielou.qzv

However, using the artifact API I get an error trying to supply two metadata variables:

from qiime2.plugins.longitudinal.visualizers import anova
anova(metadata=(metadata_table, pielou_alpha_vector.view(qiime2.Metadata)), formula='pielou_evenness ~ Salinity * Tank').visualization.save('alpha_anova_pielou.qzv')

The error being:

    TypeError: Parameter 'metadata' received (Metadata
    --------
    27 IDs x 6 columns
    Sample name: ColumnProperties(type='categorical')
    Group:       ColumnProperties(type='categorical')
    Tank:        ColumnProperties(type='categorical')
    Salinity:    ColumnProperties(type='categorical')
    Day:         ColumnProperties(type='categorical')
    Barcode:     ColumnProperties(type='categorical')

    Call to_dataframe() for a tabular representation., Metadata
    --------
    24 IDs x 1 column
    pielou_evenness: ColumnProperties(type='numeric')

    Call to_dataframe() for a tabular representation.) as an argument, which is incompatible with parameter type: Metadata

I am out of ideas how to resolve this error. If I inspect the pielou vector .qza as metadata, it reports the correct type:

pielou_alpha_vector.view(qiime2.Metadata)

Metadata
--------
24 IDs x 1 column
pielou_evenness: ColumnProperties(type='numeric')

Call to_dataframe() for a tabular representation.

Thank you very much for your feedback and for making qiime2 such a great resource.

1 Like

UPDATE: I found a messy workaround, where the two metadata sources have to be merged/joined as dataframes and then imported as one metadata again:

joined_metadata_table = qiime2.metadata.Metadata(metadata_table.to_dataframe().join(pielou_alpha_vector.view(qiime2.Metadata).to_dataframe()))

And the longitudinal anova will then work as:

from qiime2.plugins.longitudinal.visualizers import anova
anova(metadata=joined_metadata_table,formula='pielou_evenness ~ Salinity*Tank').visualization.save(expname+'_alpha_anova_pielou.qzv')

Is there an elegant way to do this?

1 Like

Hi @Alxdu,

:heart:

Let me give you a bit of insight on what q2CLI is doing on your behalf. When you input arguments like this:

q2CLI is merging those for you under the hood, see the following:

https://dev.qiime2.org/latest/api-reference/metadata/#qiime2.metadata.Metadata.merge

So you should do something like this:

anova(metadata=metadata_table.merge(pielou_alpha_vector.view(qiime2.Metadata)), ...

Give that a spin and let me know if you're still having trouble!

2 Likes

Thank you @Nicholas_Bokulich. That worked really well. And I assume it will work in other plugins which accept multiple metadata input.

On a related note, if I can piggy back on this example, is there a description of the interpretation of results in the longitudinal ANOVA test? (maybe also related to using this test with alpha diversity metrics)

Thank you.

please open a new topic. New question, new Topic. This makes distinct questions easier for others to find and follow. Please also share your results (QZV) and ask a specific question, as usual, to get the best answer. Thanks :slight_smile:

Will do. A specific example is not needed. I was just curious about the official meaning of some of the column headings in the results tables (especially to the pair-wise t-test). I can take a good guess, but I thought there would be a document that explains the output.

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