#!/usr/bin/env python # coding: utf-8 # Prepare the environments with some imports # In[1]: from qiime.sdk.workflow import WorkflowTemplate from qiime.sdk.type.primitive import Int from feature_table import rarefy from feature_table.artifact_types.feature_table import FeatureTable, Frequency # Create an artifact to work with. # In[3]: import biom from qiime.sdk.artifact import Artifact biom_path = "/Users/caporaso/code/q2d2/example-data/keyboard/q191/otu-table.tsv" table = biom.load_table(biom_path) Artifact.save(table, FeatureTable[Frequency], "nothing...", "./table.qtf") # Instantiate the workflow template (note that the output is a concrete type here, so the fact that ``Signature.__call__`` isn't actually solving anything isn't a problem yet). # In[2]: wt = WorkflowTemplate.from_function(function=rarefy, inputs={'table': FeatureTable[Frequency], 'depth': Int}, outputs={'rarefied_table': FeatureTable[Frequency]}, name="Rarefaction", doc="Let's rarefy!") # Instantiate the context. Note that it discovers its artifacts. # In[5]: from qiime.q2d3.context import Q2D3Context # In[6]: q2d3 = Q2D3Context('./') # In[7]: q2d3.data # Call the context to generate the actual job. Here we're doing some ugly stuff to grab the UUID from ``q2d3.data``, since the UUID is different everytime we run this. # In[8]: print(q2d3(wt, {'table': list(q2d3.data.keys())[0]}, {'depth': 42})) # Now, restart the kernel (see that the cell counts start over) and confirm that the job code does actually work. # In[1]: from qiime.sdk.artifact import Artifact table = Artifact('./table.qtf').data depth = 42 # In[2]: from feature_table._normalize import rarefy rarefied_table = rarefy(table=table, depth=depth) # In[3]: from feature_table.artifact_types.feature_table import Frequency from feature_table.artifact_types.feature_table import FeatureTable Artifact.save(rarefied_table, FeatureTable[Frequency], None, '/Users/caporaso/temp/q2d3-test/tmpmct3i3e_.qtf') # In[4]: get_ipython().system("tar -xvf '/Users/caporaso/temp/q2d3-test/tmpmct3i3e_.qtf'") # The table is rarefied! # In[5]: get_ipython().system('biom summarize-table -i tmpmct3i3e_/data/feature-table.biom') # In[ ]: