# Support other metadata merging strategies

**URL:** https://forum.qiime2.org/t/support-other-metadata-merging-strategies/15907
**Category:** Developer Discussion
**Tags:** metadata
**Created:** [July 30, 2020, 5:00pm UTC](https://forum.qiime2.org/t/support-other-metadata-merging-strategies/15907 "2020-07-30T17:00:06Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![yoshiki](https://forum.qiime2.org/user_avatar/forum.qiime2.org/yoshiki/32/16_2.png) [@yoshiki](https://forum.qiime2.org/u/yoshiki)
#### Post date: [July 30, 2020, 5:00pm UTC](https://forum.qiime2.org/t/support-other-metadata-merging-strategies/15907/1 "2020-07-30T17:00:06Z")

</div>

Currently metadata files are combined with an inner join, which means that any records not present in all metadata files will be dropped. It would be useful if this could be a configurable parameter.

The use-case is to visualize feature importances in [Empress](https://github.com/biocore/empress) together with taxonomy data, and other feature-level annotations. When features are filtered, this results in the dataset shrinking in size to only include the shared set.

cc @thermokarst @andrewsanchez @ebolyen @fedarko

---

<div class="post-metadata">

### Author: ![BenKaehler](https://forum.qiime2.org/user_avatar/forum.qiime2.org/benkaehler/32/1693_2.png) [@BenKaehler](https://forum.qiime2.org/u/BenKaehler)
#### Post date: [June 28, 2023, 8:36pm UTC](https://forum.qiime2.org/t/support-other-metadata-merging-strategies/15907/2 "2023-06-28T20:36:12Z")

</div>

Hi Everyone, I just hit this issue myself, and three years on from it being posted I wonder whether anyone has looked at it or come up with a workaround?

I mean, we could tell the users to export their various forms of metadata, load them in a spreadsheet, sort them by id, then clumsily cut-and-paste them together. Or if they're programmers they could load them in dataframes and merge them properly. Neither solution is good.

---

<div class="post-metadata">

### Author: ![fedarko](https://forum.qiime2.org/user_avatar/forum.qiime2.org/fedarko/32/5361_2.png) [@fedarko](https://forum.qiime2.org/u/fedarko)
#### Post date: [June 29, 2023, 3:22am UTC](https://forum.qiime2.org/t/support-other-metadata-merging-strategies/15907/3 "2023-06-29T03:22:31Z")

</div>

I'm not aware of any "easy" workarounds to this problem. In the context of Empress, we ended up adding [a short section](https://github.com/biocore/empress#providing-multiple-metadata-files) to our README that explains the situation and links to [a small Python script](https://github.com/biocore/empress/issues/393#issuecomment-701675087) that can be used to merge taxonomy and feature importance metadata files with an outer (?) join; this script is really just following the "load them in dataframes and merge them properly" idea you suggested.

I can imagine two types of options for more elegantly handling this situation (but there are probably other solutions I'm missing 🙂 ):

1. Automatically adding extra parameters to every action / visualizer command within QIIME 2 that accepts `Metadata`; these parameters would allow users to specify how they want to merge metadata files of a given "type" (e.g. `--m-sample-metadata`) if multiple are provided for a single type (e.g. `--p-sample-metadata-merge-strategy`).

2. Providing a command within QIIME 2 (e.g. in `qiime metadata`) that merges metadata files, with the parameter above as an option. (This might get tricky, because IIRC QIIME 2 commands currently [can't output metadata files](https://forum.qiime2.org/t/how-to-output-metadata-as-an-artifact/10338).)

---

<div class="post-metadata">

### Author: ![gregcaporaso](https://forum.qiime2.org/user_avatar/forum.qiime2.org/gregcaporaso/32/17769_2.png) [@gregcaporaso](https://forum.qiime2.org/u/gregcaporaso)
#### Post date: [June 29, 2023, 5:19pm UTC](https://forum.qiime2.org/t/support-other-metadata-merging-strategies/15907/4 "2023-06-29T17:19:01Z")

</div>

Hey all,  
We do now have a way to output metadata in an artifact with the semantic type `ImmutableMetadata` (see [2023.5 release notes](https://forum.qiime2.org/t/qiime-2-2023-5-is-now-available/26579)), and this can pave the way to supporting other metadata merging strategies through specific commands as @fedarko suggests.

`ImmutableMetadata` is viewable as qiime2.Metadata, so can be used anywhere that metadata can be in QIIME 2, and it can be exported which results in a plain, old (mutable) metadata `.tsv` file. `ImmutableMetadata` will of course have provenance associated with it, and the `.tsv` of course won't, so working downstream with the `ImmutableMetadata` artifact is preferred where possible for maintaining the provenance chain.

We also have a [long-standing PR](https://github.com/qiime2/qiime2/pull/464) that addresses another issue: merging metadata with overlapping column names, which isn't possible right now.

Let me check in with the folks on my team and I'll follow up here with some notes on our plan for moving this forward.

---

<div class="post-metadata">

### Author: ![gregcaporaso](https://forum.qiime2.org/user_avatar/forum.qiime2.org/gregcaporaso/32/17769_2.png) [@gregcaporaso](https://forum.qiime2.org/u/gregcaporaso)
#### Post date: [June 29, 2023, 6:28pm UTC](https://forum.qiime2.org/t/support-other-metadata-merging-strategies/15907/5 "2023-06-29T18:28:00Z")

</div>

We had some discussion internally, and I updated [this issue](https://github.com/qiime2/q2-metadata/issues/11) on the topic. The idea here is that we'll create a simple `merge` action in q2-metadata, and we can expand on that over time (or add new special case actions as needed).

---

<div class="post-metadata">

### Author: ![BenKaehler](https://forum.qiime2.org/user_avatar/forum.qiime2.org/benkaehler/32/1693_2.png) [@BenKaehler](https://forum.qiime2.org/u/BenKaehler)
#### Post date: [July 1, 2023, 9:32am UTC](https://forum.qiime2.org/t/support-other-metadata-merging-strategies/15907/6 "2023-07-01T09:32:04Z")

</div>

Brilliant! Thanks @gregcaporaso. I look forward to trying it out.
