Metadata type handling & transforming in QIIME2 plugins

Hi there,

I am trying to develop a tool suite that acts standalone and is also integrated with QIIME2. My function takes as input, among other things, an ordination and a metadatafile. The ordination oddly enough, is passed through without error when using both the standalone and qiime2 versions. However, the metadata throws an error because it has not been transformed from QIIME2 type Metadata to pd.DataFrame, whereas the ordination has no problem transforming from PCoAResult to skbio.OrdinationResults.

In a _visualizer.py file I have defined:

def hulls_plots(
    output_dir: str,
    ordination: skbio.OrdinationResults,
    metadata: pd.DataFrame,
    ...)

In my plugin_setup.py I have:

from qiime2.plugin import Metadata
from q2_types.ordination import PCoAResults
from ch.q2._visualizer import hulls_plots

plugin.visualizers.register_function(
    function=hulls_plots,
    inputs={
        'ordination': PCoAResults,
    },
    parameters={
        'metadata': Metadata,
        ...

For reference, I have been using gemelli as a roadmap on how to format my plugin. Any clarity on what might be going on under the hood and how to fix it would be greatly appreciated. For now, I have a hack-y fix that I'm not 100% satisfied with (checking type and transforming if need be)

THank you again!

Hello @Daniela_Perry1,

You figured the problem out -- there is a transformer from the semantic type PCoAResults's default format to skbio.OrdinationResults, but there is no transformer from the semantic type Metadata's default format to pd.DataFrame. You can use the to_dataframe method on the Metadata format to convert to a pandas data frame however. I'm not sure why there's no such existing transformer at the moment.

Hi @colinvwood Thank you for your reply. Sounds like my hacky fix is the most correct thing to do besides defining the transformer myself? Thank you for the feedback. On a slightly different note and as a more general piece of advice, do you have any tips on how to debug visualizations and their html renderings? Any advice is appreciated and I thank you for your time!

Hi @Daniela_Perry1, is your code online somewhere where we could take a look and give advice?

Also, this section and the associated git diff of Developing with QIIME 2 might be helpful references here.

Hello @Daniela_Perry1,

What issues exactly are you trying to debug?