# Obtaining sequences per biological sample - version 2

**URL:** https://forum.qiime2.org/t/obtaining-sequences-per-biological-sample-version-2/14195
**Category:** User Support
**Created:** [March 25, 2020, 12:08am UTC](https://forum.qiime2.org/t/obtaining-sequences-per-biological-sample-version-2/14195 "2020-03-25T00:08:23Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![rnasrah](https://forum.qiime2.org/user_avatar/forum.qiime2.org/rnasrah/32/13101_2.png) [@rnasrah](https://forum.qiime2.org/u/rnasrah)
#### Post date: [March 25, 2020, 12:08am UTC](https://forum.qiime2.org/t/obtaining-sequences-per-biological-sample-version-2/14195/1 "2020-03-25T00:08:23Z")

</div>

]

 ![Screen Shot 2020-03-24 at 8.04.21 PM](https://forum-qiime2-org.s3.dualstack.us-west-2.amazonaws.com/original/2X/9/9580aa94b8ca2662025a405530fe3461e590869b.png)  
Hello,  
you have helped me with the same question back in 2017 with the older qiime, so apologies in advance for asking this again but cannot seem to do it with qiime2-2020.2.

How can I can basically get the following: matrix of sample x feature frequencies like shown in attached photo.  
So just to recap, my dream file would look something like in the picture below (and instead of the feature ID, if I can get the actual sequence).

Thanks so much once again,

Rima

---

<div class="post-metadata">

### Author: ![jwdebelius](https://forum.qiime2.org/user_avatar/forum.qiime2.org/jwdebelius/32/9655_2.png) [@jwdebelius](https://forum.qiime2.org/u/jwdebelius)
#### Post date: [March 25, 2020, 12:19am UTC](https://forum.qiime2.org/t/obtaining-sequences-per-biological-sample-version-2/14195/2 "2020-03-25T00:19:07Z")

</div>

Hi @rnasrah,

👋

There should be a flag, `--p-no-hashed-feature-ids` that will let you keep your original sequences in the feature table.

Best,  
Justine

---

<div class="post-metadata">

### Author: ![rnasrah](https://forum.qiime2.org/user_avatar/forum.qiime2.org/rnasrah/32/13101_2.png) [@rnasrah](https://forum.qiime2.org/u/rnasrah)
#### Post date: [March 25, 2020, 1:19am UTC](https://forum.qiime2.org/t/obtaining-sequences-per-biological-sample-version-2/14195/3 "2020-03-25T01:19:02Z")

</div>

Hi Justine!  
Where would I find this? in which command?

Basically I want to export this "table" and work on it in excel outside of qiime.

Thanks!

---

<div class="post-metadata">

### Author: ![thermokarst](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/t/8e7dd6/32.png) [@thermokarst](https://forum.qiime2.org/u/thermokarst)
#### Post date: [March 25, 2020, 2:12pm UTC](https://forum.qiime2.org/t/obtaining-sequences-per-biological-sample-version-2/14195/4 "2020-03-25T14:12:10Z")

</div>



---

<div class="post-metadata">

### Author: ![rnasrah](https://forum.qiime2.org/user_avatar/forum.qiime2.org/rnasrah/32/13101_2.png) [@rnasrah](https://forum.qiime2.org/u/rnasrah)
#### Post date: [March 25, 2020, 6:35pm UTC](https://forum.qiime2.org/t/obtaining-sequences-per-biological-sample-version-2/14195/5 "2020-03-25T18:35:01Z")

</div>

Hello again,

So basically,  
I did the following commands:

qiime tools export   
--input-path table.qza   
--output-path exported-paired-table

then i used the convert biom function to convert it to a tsv file and open it in excel...

So now, my excel file gives me the frequency of each feature ID in each biological sample. However, instead of feature ID, I would like to get the **actual sequence**. How can I do that?

Thanks so much!

---

<div class="post-metadata">

### Author: ![jwdebelius](https://forum.qiime2.org/user_avatar/forum.qiime2.org/jwdebelius/32/9655_2.png) [@jwdebelius](https://forum.qiime2.org/u/jwdebelius)
#### Post date: [March 25, 2020, 6:53pm UTC](https://forum.qiime2.org/t/obtaining-sequences-per-biological-sample-version-2/14195/6 "2020-03-25T18:53:17Z")

</div>

Hi @rnasrah,

You're on the right track, I think!

I haven't tested this yet (but its on my list of things to do today), but basically, I think you need to convert the representative sequences into a table and then add that as metadata. Let me play around with it and I'll get back to you soon.

Best,  
Justine

---

<div class="post-metadata">

### Author: ![jwdebelius](https://forum.qiime2.org/user_avatar/forum.qiime2.org/jwdebelius/32/9655_2.png) [@jwdebelius](https://forum.qiime2.org/u/jwdebelius)
#### Post date: [March 25, 2020, 9:44pm UTC](https://forum.qiime2.org/t/obtaining-sequences-per-biological-sample-version-2/14195/7 "2020-03-25T21:44:05Z")

</div>

The thing I thought was going to work, didn't work. So, I think I have a solution, but its somewhat inelegant and requires you to do some work in python. There are three paramters in this script you need to change:

1. `table_fp` should be the path to your actual table
2. `seq_fp` should be the path to your actual sequences
3. `out_fp` should be the place you want to save the sequences. This will be a tab-seperated file for excel.

```python
import pandas as pd
from qiime2 import Artifact

table_fp = 'table.qza' # The actual path to your table
seq_fp = 'seq.qza' # The actual path to your sequences
out_fp = 'new_table.tsv' # the actual place you want to save the table with the the sequences

table = Artifact.load(table_fp).view(pd.DataFrame).T
repseq = Artifact.load(seq_fp).view(pd.Series).apply(lambda x: ''.join(str(x))

combined = pd.concat(axis=1, sort=False, objs=[table, repseq.loc[table.index])
combined.rename(columns={0: "representative_sequence"}, inplace=True)

combined.to_csv(out_fp, sep='\t')

```

You can run it by opening an ipython interpreter on your terminal by typing `ipython` and then run each line of code, updating your path for the three fp values.

Let us know how it works!

Best,  
Justine

---

<div class="post-metadata">

### Author: ![jwdebelius](https://forum.qiime2.org/user_avatar/forum.qiime2.org/jwdebelius/32/9655_2.png) [@jwdebelius](https://forum.qiime2.org/u/jwdebelius)
#### Post date: [March 25, 2020, 9:44pm UTC](https://forum.qiime2.org/t/obtaining-sequences-per-biological-sample-version-2/14195/8 "2020-03-25T21:44:32Z")

</div>



---

<div class="post-metadata">

### Author: ![rnasrah](https://forum.qiime2.org/user_avatar/forum.qiime2.org/rnasrah/32/13101_2.png) [@rnasrah](https://forum.qiime2.org/u/rnasrah)
#### Post date: [March 26, 2020, 12:49am UTC](https://forum.qiime2.org/t/obtaining-sequences-per-biological-sample-version-2/14195/9 "2020-03-26T00:49:01Z")

</div>

Thanks Justine.  
So i tried to do what you said: ran ipython on my terminal window and ran the first command "import pandas as pd" and I got an error message (please see attached).

 ![Screen Shot 2020-03-25 at 8.44.15 PM](https://forum-qiime2-org.s3.dualstack.us-west-2.amazonaws.com/original/2X/8/8f66a886032cf2bf2a29917384e12644e5004b96.png)

---

<div class="post-metadata">

### Author: ![rnasrah](https://forum.qiime2.org/user_avatar/forum.qiime2.org/rnasrah/32/13101_2.png) [@rnasrah](https://forum.qiime2.org/u/rnasrah)
#### Post date: [March 26, 2020, 12:50am UTC](https://forum.qiime2.org/t/obtaining-sequences-per-biological-sample-version-2/14195/10 "2020-03-26T00:50:07Z")

</div>

Hi again,

I was thinking my other option would be just to get the rep-seqs.qza file in excel and then I can just match with sequences/feature IDs from that file with the frequencies in the other file (i.e through R for example). Is there a way I can do that? (convert my rep-seqs.qza file). Please see attached picture of what part of the rep-seqs.qza file I would like to extract).

 ![Screen Shot 2020-03-25 at 8.47.40 PM](https://forum-qiime2-org.s3.dualstack.us-west-2.amazonaws.com/original/2X/9/93c4ec04e7c33afd8982c9f1947d1832c53137e3.png)

Thanks so much!  
Rima

---

<div class="post-metadata">

### Author: ![jwdebelius](https://forum.qiime2.org/user_avatar/forum.qiime2.org/jwdebelius/32/9655_2.png) [@jwdebelius](https://forum.qiime2.org/u/jwdebelius)
#### Post date: [March 26, 2020, 2:10am UTC](https://forum.qiime2.org/t/obtaining-sequences-per-biological-sample-version-2/14195/11 "2020-03-26T02:10:34Z")

</div>

Hi @rnasrah,

You need to run the code in your qiime2 enviroment. So, conda activate qiime2-... and then open ipython and run the code.

I looked at exporting the. rep seqs to a table, and they come out as a fasta in the current set up, which unfortunately, messed up my original idea.

Best,  
Justine

---

<div class="post-metadata">

### Author: ![rnasrah](https://forum.qiime2.org/user_avatar/forum.qiime2.org/rnasrah/32/13101_2.png) [@rnasrah](https://forum.qiime2.org/u/rnasrah)
#### Post date: [March 26, 2020, 2:42am UTC](https://forum.qiime2.org/t/obtaining-sequences-per-biological-sample-version-2/14195/12 "2020-03-26T02:42:02Z")

</div>

> [@jwdebelius](#):
>
> combined.to\_csv(out\_fp, sep='\t')

Hi again Justine,

So I ran the code in ipython (see attached) and I still get the same frequency matrix: feature ID x biological samples.

But instead of feature ID, I would like the actual sequence.

Attached is a copy of my code and of the output file. Did I miss anything?

Thanks so much!

 ![Screen Shot 2020-03-25 at 10.41.19 PM](https://forum-qiime2-org.s3.dualstack.us-west-2.amazonaws.com/original/2X/5/504353b16c224217465539a765e5a3c5fae514bf.jpeg) ![Screen Shot 2020-03-25 at 10.40.48 PM](https://forum-qiime2-org.s3.dualstack.us-west-2.amazonaws.com/original/2X/3/3ecb868f4853c10836f9c66190ae56fff8d784eb.png)

---

<div class="post-metadata">

### Author: ![jwdebelius](https://forum.qiime2.org/user_avatar/forum.qiime2.org/jwdebelius/32/9655_2.png) [@jwdebelius](https://forum.qiime2.org/u/jwdebelius)
#### Post date: [March 26, 2020, 4:08pm UTC](https://forum.qiime2.org/t/obtaining-sequences-per-biological-sample-version-2/14195/14 "2020-03-26T16:08:32Z")

</div>

Hi @rnasrah,

So, it ran correctly, but this adds the sequence at. the end as metadata. You could take the last sequence column in excel and move it over, or add one line to the end of the python after

```python
combined.rename(columns={0:"representative_sequence"}, inplace=True)
combined.set_index("representative_sequence", inplace=True)
combined.to_csv(out_fp, sep='\t')

```

@Nicholas_Bokulich also suggested this thread, because he thinks more qiime-o-matically than I do. So, I may have sent you on a wild goose chase (sorry).

> [@Formatting a QIIME2 feature table for the R version of DADA2?](https://forum.qiime2.org/t/formatting-a-qiime2-feature-table-for-the-r-version-of-dada2/13387/3):
>
> 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: [https://forum.qiime2.org/t/problem-with-taxa-collapse/9081/2?u=nicholas\_bokulich](https://forum.qiime2.org/t/problem-with-taxa-collapse/9081/2) 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…

Best,  
Justine

---

<div class="post-metadata">

### Author: ![rnasrah](https://forum.qiime2.org/user_avatar/forum.qiime2.org/rnasrah/32/13101_2.png) [@rnasrah](https://forum.qiime2.org/u/rnasrah)
#### Post date: [March 26, 2020, 5:14pm UTC](https://forum.qiime2.org/t/obtaining-sequences-per-biological-sample-version-2/14195/16 "2020-03-26T17:14:59Z")

</div>

Thanks so much Justine and Nicholas!

Sorry, my bad, did not notice the last column! It worked like you suggested so thanks once again!

---

<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: [April 26, 2020, 11:14pm UTC](https://forum.qiime2.org/t/obtaining-sequences-per-biological-sample-version-2/14195/17 "2020-04-26T23:14:59Z")

</div>

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