Open FeatureData in Artifact API

Hello @samuel.drouin!

Grabbing the UUID is straightforward (just a prop on the Artifact), while getting the other parts are pretty simple, too, but only if you know to use the view API method (we are lacking good docs in the dept, sorry!)

import qiime2
import pandas as pd

# here I am loading, but this could also be results passed
# down from a previous step.
taxonomy_artifact = qiime2.Artifact.load('taxonomy.qza')
# Get the UUID of the Artifact
print(taxonomy_artifact.uuid)
7224759e-03bb-4179-a382-485165ca8c86

# `view` as a pd.DataFrame to get the taxon and conf.
taxonomy_df = taxonomy_artifact.view(pd.DataFrame)
print(taxonomy_df.head())
                                                                              Taxon  \
Feature ID                                                                            
7fa8f515ee1ac5cb8b529b13e6a89790  k__Bacteria; p__Proteobacteria; c__Gammaproteo...   
40f13b077d41d6837ca6fae65763cf01  k__Bacteria; p__Actinobacteria; c__Actinobacte...   
2e55763e77234a7bfc3a311067a0c7e1  k__Bacteria; p__Firmicutes; c__Clostridia; o__...   
d5ef913e6aee3067001dc610ac8af1d1  k__Bacteria; p__Actinobacteria; c__Actinobacte...   
bc15061b61cf6b5002c58284591f97d4  k__Bacteria; p__Firmicutes; c__Clostridia; o__...   

                                          Confidence  
Feature ID                                            
7fa8f515ee1ac5cb8b529b13e6a89790  0.9998282422613309  
40f13b077d41d6837ca6fae65763cf01  0.9999994725274034  
2e55763e77234a7bfc3a311067a0c7e1  0.9177375883240979  
d5ef913e6aee3067001dc610ac8af1d1  0.9971204554883859  
bc15061b61cf6b5002c58284591f97d4  0.9999262723979453  

You will need to view as qiime2.Metadata, first:

import qiime2
from qiime2.plugins import metadata

taxonomy_artifact = qiime2.Artifact.load('taxonomy.qza')
taxonomy_md = taxonomy_artifact.view(qiime2.Metadata)
taxa_tab, = metadata.visualizers.tabulate(input=taxonomy_md)

Still a bit light in this department (would welcome some contributions!):

Hope that helps! :qiime2: :t_rex:

1 Like