# Formatting a QIIME2 feature table for the R version of DADA2?

**URL:** https://forum.qiime2.org/t/formatting-a-qiime2-feature-table-for-the-r-version-of-dada2/13387
**Category:** User Support
**Created:** [January 29, 2020, 9:35pm UTC](https://forum.qiime2.org/t/formatting-a-qiime2-feature-table-for-the-r-version-of-dada2/13387 "2020-01-29T21:35:36Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![ctekellogg](https://forum.qiime2.org/user_avatar/forum.qiime2.org/ctekellogg/32/5742_2.png) [@ctekellogg](https://forum.qiime2.org/u/ctekellogg)
#### Post date: [January 29, 2020, 9:35pm UTC](https://forum.qiime2.org/t/formatting-a-qiime2-feature-table-for-the-r-version-of-dada2/13387/1 "2020-01-29T21:35:36Z")

</div>

Hello,

I would like to explore the possibility of using the `collapseNoMismatch` function available in the R implementation of DADA2 to merge the feature tables that I generated using the QIIME2 implementation of DADA2. (only discovered that this function existed after doing all of the denoising and read merging in QIIME2 using `qiime dada2 denoise-paired`). Does anyone have any tips on getting QIIME2 generated ASV tables into the right form to work with DADA2 in R. Judging from this post:

[Exporting DADA2 (R package) results to work with qiime2](https://forum.qiime2.org/t/exporting-dada2-r-package-results-to-work-with-qiime2/2573)

I see that the feature tables will need to be transposed for the R implementation, but is there an easy way to have the row headers be the actual sequences rather than the feature ID that is the default row header in QIIME2, since i think this is necessary for the R version? (short of copy and pasting the sequences from the rep seq file...)

Thank you!  
Colleen

---

<div class="post-metadata">

### Author: ![Mehrbod\_Estaki](https://forum.qiime2.org/user_avatar/forum.qiime2.org/mehrbod_estaki/32/4001_2.png) [@Mehrbod\_Estaki](https://forum.qiime2.org/u/Mehrbod_Estaki)
#### Post date: [January 30, 2020, 6:36am UTC](https://forum.qiime2.org/t/formatting-a-qiime2-feature-table-for-the-r-version-of-dada2/13387/2 "2020-01-30T06:36:54Z")

</div>

Hi @ctekellogg,  
Have you seen the nifty [qiime2R](https://github.com/jbisanz/qiime2R) package? I think that will make your life pretty easy.  
I'm not sure if there is an easy way to replace the hashed IDs with their corresponding sequences in Qiime2, certainly doable in R, you'll need to import both your table and rep-seqs file and use the latter to rename rownames in your table.  
By the way, you can also transpose your table either in Q2 with the [feature-table transpose](https://docs.qiime2.org/2019.10/plugins/available/feature-table/transpose/) action too.

---

<div class="post-metadata">

### Author: ![Nicholas\_Bokulich](https://forum.qiime2.org/user_avatar/forum.qiime2.org/nicholas_bokulich/32/19937_2.png) [@Nicholas\_Bokulich](https://forum.qiime2.org/u/Nicholas_Bokulich)
#### Post date: [January 30, 2020, 12:44pm UTC](https://forum.qiime2.org/t/formatting-a-qiime2-feature-table-for-the-r-version-of-dada2/13387/3 "2020-01-30T12:44:22Z")

</div>

> [@Mehrbod\_Estaki](#):
>
> I’m not sure if there is an easy way to replace the hashed IDs with their corresponding sequences in Qiime2

Sure there is — secret QIIME 2 method. Use `qiime feature-table group` to relabel.

We have a few examples floating around the forum of using this as a sneaky way to relabel sample IDs, e.g., here:

> [@Problem with 'taxa collapse'](https://forum.qiime2.org/t/problem-with-taxa-collapse/9081/2):
>
> Hi @allebiotech, Sounds like the problem may be that your sample IDs are all numbers? While this is not forbidden in QIIME 2 metadata formats, it is discouraged since it can cause cryptic bugs like this to emerge when some of the underlying packages that QIIME 2 uses cannot handle numeric sample IDs. If I am wrong, and your sample IDs are not numbers, please ignore what I have to say below and instead do the following: please report the full error message please run qiime feature-table summ…

But `group` can operate on feature IDs as well, and the same trick applies... additionally, we can transform a `FeatureData[Sequence]` artifact to metadata so that the sequence gets read in as the new label. Proof (using the moving pics tutorial data and Artifact API):

```auto
>>> import qiime2 as q2, pandas as pd
>>> from qiime2.plugins import feature_table as ft
>>> tab = q2.Artifact.load('table.qza')
>>> seqs = q2.Artifact.load('rep-seqs.qza')
>>> t2, = ft.actions.group(tab, 'feature', seqs.view(q2.Metadata).get_column('Sequence'), 'sum')
>>> tab.view(pd.DataFrame).columns
Index(['4b5eeb300368260019c1fbc7a3c718fc', 'fe30ff0f71a38a39cf1717ec2be3a2fc',
       'd29fe3c70564fc0f69f2c03e0d1e5561', '868528ca947bc57b69ffdf83e6b73bae',
       '154709e160e8cada6bfb21115acc80f5', '1d2e5f3444ca750c85302ceee2473331',
       '0305a4993ecf2d8ef4149fdfc7592603', 'cb2fe0146e2fbcb101050edb996a0ee2',
       '997056ba80681bbbdd5d09aa591eadc0', '3c9c437f27aca05f8db167cd080ff1ec',
       ...
       'ad492bcae03f566b36a19e31f04d659a', 'eb8ef4756ed538fe480d979e740a04d8',
       '5db2cf37007f874e25eb2c901917e15a', 'fa3729663b98de0c0af7913e9f30c19e',
       '504572e3afd673db749ee5e8e3e57b97', 'a6b6f29a1196cacfc392e3d71f55e2a2',
       '0e5df3d01cc073e3c9674c2534169f03', '06845c67bc4203081a981200f33e87eb',
       '98d250a339a635f20e26397dafc6ced3', '1830c14ead81ad012f1db0e12f8ab6a4'],
      dtype='object', length=770)
>>> t2.view(pd.DataFrame).columns
Index(['TACGGAGGATCCGAGCGTTATCCGGATTTATTGGGTTTAAAGGGAGCGTAGATGGATGTTTAAGTCAGTTGTGAAAGTTTGCGGCTCAACCGTAAAATTGCAGTTGATACTGGATATCTT',
       'TACGTAGGGTGCGAGCGTTAATCGGAATTACTGGGCGTAAAGCGAGCGCAGACGGTTACTTAAGCAGGATGTGAAATCCCCGGGCTCAACCTGGGAACTGCGTTCTGAACTGGGTGACTA',
       'TACGTAGGTCCCGAGCGTTGTCCGGATTTATTGGGCGTAAAGCGAGCGCAGGCGGTTAGATAAGTCTGAAGTTAAAGGCTGTGGCTTAACCATAGTACGCTTTGGAAACTGTTTAACTTG',
       'TACGGAGGATCCGAGCGTTATCCGGATTTATTGGGTTTAAAGGGAGCGTAGATGGATGTTTAAGTCAGTTGTGAAAGTTTGCGGCTCAACCGTAAAATTGCAGTTGATACTGGATGTCTT',
       'TACGGAGGATCCGAGCGTTATCCGGATTTATTGGGTTTAAAGGGAGCGTAGGTGGATTGTTAAGTCAGTTGTGAAAGTTTGCGGCTCAACCGTAAAATTGCAGTTGAAACTGGCAGTCTT',
       'TACGGAGGGTGCGAGCGTTAATCGGAATAACTGGGCGTAAAGGGCACGCAGGCGGTGACTTAAGTGAGGTGTGAAAGCCCCGGGCTTAACCTGGGAATTGCATTTCATACTGGGTCGCTA',
       'TACGGAGGATCCGAGCGTTATCCGGATTTATTGGGTTTAAAGGGAGCGTAGGCGGACGCTTAAGTCAGTTGTGAAAGTTTGCGGCTCAACCGTAAAATTGCAGTTGATACTGGGTGTCTT',
       'TACGTAGGTGGCAAGCGTTATCCGGAATTATTGGGCGTAAAGCGCGCGTAGGCGGTTTTTTAAGTCTGATGTGAAAGCCCACGGCTCAACCGTGGAGGGTCATTGGAAACTGGAAAACTT',
       'TACGTATGTCACAAGCGTTATCCGGATTTATTGGGCGTAAAGCGCGTCTAGGTGGTTATGTAAGTCTGATGTGAAAATGCAGGGCTCAACTCTGTATTGCGTTGGAAACTGCATGACTAG',
       'TACGGAAGGTCCAGGCGTTATCCGGATTTATTGGGTTTAAAGGGAGCGTAGGCTGGAGATTAAGTGTGTTGTGAAATGTAGACGCTCAACGTCTGAATTGCAGCGCATACTGGTTTCCTT',
       ...
       'TACGTAGAAGACTAGTGTTATTCATCTTTAATAGGTTTAAAGGGTACCTAGACGGTAAATTTAATCTTTAACAGGATATGTTTTTACTAGAGTTTTATATGAGGAGGGGAGTATTTATGG',
       'CACGGAAGGGGCAAGCGTTGCTCGTAAGTATTGGGCGTAAAGAGTTTGTAGGCGGTTTTTCAAAAAACTTGGTTTTCCATCCGGCTACGACATGGTTAACCTTGCTTGAGTTCAGTCTTT',
       'TACGGAGGATGCGAGCGTTATCCGGATTTATTGGGTTTAAAGGGTGCGCAGGCGGAAGATCAAGTCAGCGGTAAAATTGAGAGGCTCAACCTCTTCGAGCCGTTGAAACTGGTTTTCTTG',
       'GACGGAGGGTGCTAGCGTTGTTCGGAATTACTGGGCGTAAAGGGCGCGTAGGCGGCCCTGTCAGTCGGGTGTGAAAGCCCGGGGCTCAACCCCGGAACGGCACCCGAGACGGCAGGGCTG',
       'GACGGAGGATGCAAGCGTTATCCGGAATGATTGGGCGTAAAGCGTCTGTAGGTGGATTGTAAAGTCCTCTGTTAAAGATCTGGGCTTAACCCAGTTCAAGCAGTGGAAACTTATAATCTA',
       'TACGAAGGGTGCAAGCGTTATTCGGAATCATTGGGCGTAAAGCGCGCGCAGGCGGATCAGCAAGTCAGATGTGAAATCTCAGGGCTCAACCCTGAAACTGCGTCTGAAACTGCTAGTCTA',
       'TACGTAGGGTGCAAGCGTTATCCGGAATTACTGGGCGTAAAGGGTGCGTAGGCGGCATGGCAAGTCAGAAGTGAAAGGCAATAGCTTAACTATTGTTAGCTTTTGAAACTGCTAAGCTTG',
       'TACGGAGGGTGCGAGCGTTATTCGGATTCACTGGGCGTAAAGCGCATGTAGGCGGTTTCGTAAGTCTGATGTGAAAGCCCTCGACTTAATCGAGGAAGTGCATTGGATACTGCGAGGCTA',
       'TACGTAGGTGGCGAGCGTTATCCGGAATTACTGGGTGTAAAGGGCGTGTAGGCGGCACTGTAAGTCAGATGTGAAATCTCCCGGCTCAACCGGGAGCGTGCATCTGATACTGCAGTACTT',
       'TACGTAGGGTGCAAGCATTATCCGGAGTGACTGGGCGTAAAGAGTTGCGTAGGCGGTTTAATAAGTGAATAGTGAAACCTGGTGGCTCAACCATACAGACTATTATTCAAACTGTTAAAC'],
      dtype='object', length=770)

```

So the CLI equivalent would be something like:

```auto
qiime feature-table group \
    --i-table table.qza \
    --p-axis feature \
    --m-metadata-file rep-seqs.qza \
    --m-metadata-column Sequence \
    --p-mode sum \
    --o-grouped-table new-table.qza

```

Enjoy!

---

<div class="post-metadata">

### Author: ![ctekellogg](https://forum.qiime2.org/user_avatar/forum.qiime2.org/ctekellogg/32/5742_2.png) [@ctekellogg](https://forum.qiime2.org/u/ctekellogg)
#### Post date: [January 30, 2020, 12:48pm UTC](https://forum.qiime2.org/t/formatting-a-qiime2-feature-table-for-the-r-version-of-dada2/13387/4 "2020-01-30T12:48:47Z")

</div>

Hi @Mehrbod_Estaki - I have not seen that R package. I'll take a look as I imagine it will come in handy, if not now, in the future.

And, @Nicholas_Bokulich - thank you for this example to (attempt to) make the changes in QIIME2 first before exporting the feature tables for R.

I'll give this a shot!  
Thank you,  
Colleen

---

<div class="post-metadata">

### Author: ![system](https://forum-qiime2-org.s3.dualstack.us-west-2.amazonaws.com/original/3X/2/1/21af5fe23cb6f4579467c66a9ed94e55274ca7bd.svg) [@system](https://forum.qiime2.org/u/system)
#### Post date: [March 1, 2020, 11:49pm UTC](https://forum.qiime2.org/t/formatting-a-qiime2-feature-table-for-the-r-version-of-dada2/13387/7 "2020-03-01T23:49:59Z")

</div>

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