Add Metadata to artifact in artifact api

Given a qiime2 Artifact object, is there a way to add Metadata to it so when the Artifact is exported to file and then imported, the metadata remains?

I looked at this post and it seems that I will use Metadata.from_artifact() to retrieve the data but I do not know how to add it. I see there is a method Artifact.has_metadata() so I am assuming there must be some way.

The Artifact I am working with is of type FeatureTable[Frequency] and I want to have a list associated with each otu. Each list holds the otus that were collapsed when using biom.Collapse.

Hi @mahermassoud!

That’s a good intuition, however QIIME 2 doesn’t let you add metadata to artifacts. Rather it lets you use some artifacts as if they were metadata. So for example, you could create a PCoA plot and color by alpha diversity. But the alpha-diversity hasn’t had metadata attached to it, it’s just been used as if it were metadata.

It sounds like your goal is to have an OTU map? QIIME 2 doesn’t really have a notion of that, so even if that information was stored, we can’t do anything with it yet.

Just in case its useful, there’s an equivalent to biom.Collapse in QIIME 2 called qiime feauture-table group. It takes a metadata file mapping original IDs to new IDs (collapsing as needed). That mapping will be retained in provenance if you are just trying to book-keep the original IDs.

What is your ultimate goal with this information?


When I use biom.Table.collapse(), I can keep information on which IDs were collapsed. However, when I convert it into a qiime2 artifact, I lose this info since it is in the biom.Table’s metadata field.

I found a workaround.

That is correct - QIIME 2 stores taxonomy separate from the feature table. Check out this post to learn how to import a taxonomy-annotated BIOM table as FeatureData[Taxonomy].

Keep on QIIMEing! :t_rex:

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