Hi, All,
I am working on a plugin, and I am struggling a little with the definition of the function underlying one of my plugin actions (note: NOT the action itself--I feel like I have a pretty clear idea of how to define the types of the action inputs and outputs using SemanticTypes). I've described details of my efforts at the bottom, but I think my basic question is: when I am defining a function underlying an action, what kinds of "types" are legal to specify for the input and output parameters?
I failed when specifying typing
-library-based types (like Dict[str, float]
) for outputs, and when specifying QIIME built-in types (like qiime2.plugin.List[qiime2.plugin.Str]
). However, I succeeded using python native types like dict
or other package's types like pandas.DataFrame
, as well as any object type I defined myself (e.g., class LinearRegressionsYamlFormat(model.TextFileFormat):
). I think my mental model of what can be used here is lacking Can anyone point me to a resource to set me straight, or educate me here?
Many thanks,
Amanda
Gory Details:
In my case, I have all the plugin chrome set up and the action defined:
plugin.methods.register_function(
function=q2_pysyndna.fit,
<etc>
... and I am working on the definition of the fit
function. I originally had it defined like this:
from typing import Dict, List, Union
def fit(syndna_concs: pandas.DataFrame,
syndna_counts: biom.Table,
metadata: Metadata,
min_sample_count: int = 1) -> \
(Dict[str, Union[Dict[str, float], None]], List[str]):
# for testing only
linregs_dict = {"example_test": {
"slope": 1.24675913604407,
"intercept": -7.155318973708384,
"rvalue": 0.9863241797356326,
"pvalue": 1.505381146809759e-07,
"stderr": 0.07365795255302438,
"intercept_stderr": 0.2563956755844754}}
log_msgs_list = ["test log message 1"]
return linregs_dict, log_msgs_list
However, when I tried to run the action, this failed way down in qiime2.core.type.signature
in the coerce_given_outputs
function, where it complained that the type of the output_view (dict
) is not the same as the spec.view_type (Dict[str, Union[Dict[str, float], None]]
) (see
qiime2/qiime2/core/type/signature.py at d56401b26a2230a9acbba2ec3a8b398e52e934b5 · qiime2/qiime2 · GitHub ). Testing showed that replacing typing-library-based hint in the fit
definition above with (dict, list)
worked. (I was a little surprised, as I was able to successfully use typing hints from the typing
library in other parts of the plugin--for example, I was able to define a transformer that worked on a manually-created dict like the one above using the definition def _2(data: Dict[str, Union[Dict[str, float], None]]) -> LinearRegressionYamlFormat: <etc>
.) After this, I thought that maybe I should be using QIIME types as outputs, so (for testing purposes), I ditched the dict
part of the output and just tried defining a return value for a list of strings as qiime2.plugin.List[qiime2.plugin.Str]
, but that produced the same type(output_view) != spec.view_type error.