# How to extract sequences for specific samples in dataset?

**URL:** https://forum.qiime2.org/t/how-to-extract-sequences-for-specific-samples-in-dataset/28310
**Category:** User Support
**Created:** [November 15, 2023, 8:05pm UTC](https://forum.qiime2.org/t/how-to-extract-sequences-for-specific-samples-in-dataset/28310 "2023-11-15T20:05:30Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![ag1170](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/a/e56c9b/32.png) [@ag1170](https://forum.qiime2.org/u/ag1170)
#### Post date: [November 15, 2023, 8:05pm UTC](https://forum.qiime2.org/t/how-to-extract-sequences-for-specific-samples-in-dataset/28310/1 "2023-11-15T20:05:30Z")

</div>

I have looked in the qiime2 forum but no answers have been able to help me yet.

I have 27 samples. I want to extract the rep seqs from one specific sample so I can BLAST them and compare to an isolate I have from this sample's same sampling site. I seem to be repeatedly misunderstanding how I can do this.

So far I have seen these posts:

> [@Error with feature-table filter-seqs: All features were filtered out of the data.](https://forum.qiime2.org/t/error-with-feature-table-filter-seqs-all-features-were-filtered-out-of-the-data/9296):
>
> Dear all, I was trying to run the following command: qiime feature-table filter-seqs \ --i-data allBatches-representativeSeqs.qza \ --m-metadata-file metadata\_allBatches\_full.tsv \ --p-where "organ\_blank IN ('lung', 'blank')" \ --o-filtered-data lungBlank\_allBatches-repSeqs.qza However, I was unable due to an error. Does anyone have an idea of what might be going on? I know that this would not filter all samples out as organ\_blank can take other values. The error message is: Traceb…

> [@How to extract specific sequences per sample?](https://forum.qiime2.org/t/how-to-extract-specific-sequences-per-sample/4073):
>
> Hi, I want to extract specific sequences and check their abundance in different samples/ know from which sample they originate. I have 16S data, and I’m interested in just specific group of microorganisms. So, I would like to extract their sequences in order to create a phylogenetic tree, and be able to link the obtained results with samples metadata. Is that possible? Thanks in advance!

> [@How to get separate sequence fasta file for each sample from feature table after dada2 filtering](https://forum.qiime2.org/t/how-to-get-separate-sequence-fasta-file-for-each-sample-from-feature-table-after-dada2-filtering/9486/4):
>
> Hi @sajjad.sarikhan, Sorry but I'm not sure I quite understand still what you are trying to do. When you say "qiime2 database correspondong to my samples", what exactly are you referring to? If your end goal is to have a separate feature-table, phylogenetic tree, representative-sequences.. etc for each sample instead of the normal combined approach, you can achieve this using a combination of some of the available [filtering methods](https://docs.qiime2.org/2019.1/tutorials/filtering/) after creating the combined version of said files. For examp…

But they either weren't specific enough for what I am trying to do or weren't helpful enough for me (I'm new to QIIME2 btw).

So far I have tried creating a simplified metadata file with only the sample ID of the sample I want to retain, and then I tried using that simplified metadata file in filter-seqs against the OG repseqs from deblur:

qiime feature-table filter-seqs --i-data ../deblur-repseqs.qza --m-metadata-file sample-metadata-dconly.tsv --o-filtered-data dc-onlyseqs

But i received the error:  
**Plugin error from feature-table:**

**All features were filtered out of the data.**

**Debug info has been saved to /tmp/qiime2-q2cli-err-a8ngb9bw.log**

I have also tried doing this command where I tried doing filter-samples using my table.qza after deblur (i previously already filtered things like Mitochondria and chloroplasts that I didn't want) with my simplified metadata file and then exported it, but it gave me a .biom file that I can't make any sense of (It opens with TextEditor but its mostly nonsensical):

qiime feature-table filter-samples --i-table ../deblur-filttable4.qza --m-metadata-file sample-metadata-dconly.tsv --o-filtered-table dconly-table

qiime tools export --input-path dconly-table.qza --output-path dconly-tableexp

Clearly I am doing something wrong and I can't seem to figure out what on my own. All help is greatly appreciated!

---

<div class="post-metadata">

### Author: ![jphagen](https://forum.qiime2.org/user_avatar/forum.qiime2.org/jphagen/32/17133_2.png) [@jphagen](https://forum.qiime2.org/u/jphagen)
#### Post date: [November 15, 2023, 9:47pm UTC](https://forum.qiime2.org/t/how-to-extract-sequences-for-specific-samples-in-dataset/28310/2 "2023-11-15T21:47:56Z")

</div>



---

<div class="post-metadata">

### Author: ![jphagen](https://forum.qiime2.org/user_avatar/forum.qiime2.org/jphagen/32/17133_2.png) [@jphagen](https://forum.qiime2.org/u/jphagen)
#### Post date: [November 15, 2023, 10:08pm UTC](https://forum.qiime2.org/t/how-to-extract-sequences-for-specific-samples-in-dataset/28310/3 "2023-11-15T22:08:27Z")

</div>

Hi @ag1170,  
You are very close, thanks for putting in the work to learn Qiime2! You need to take the output of your `qiime feature-table filter-samples` and put it into `qiime feature-table filter-seqs`  
You will need to run the commands from [filter-table filter-seqs](https://docs.qiime2.org/2023.9/plugins/available/feature-table/filter-seqs/)  
The commands should be:

```auto
qiime feature-table filter-seqs
--i-data ../deblur-repseqs.qza
--i-table ../deblur-filttable4.qza
--o-filtered-data <output file name here>

```

Give that a try and let me know if you have any problems. After this step you should be able to visualize your seqs and BLAST.  
-Hannah

---

<div class="post-metadata">

### Author: ![jphagen](https://forum.qiime2.org/user_avatar/forum.qiime2.org/jphagen/32/17133_2.png) [@jphagen](https://forum.qiime2.org/u/jphagen)
#### Post date: [November 15, 2023, 10:08pm UTC](https://forum.qiime2.org/t/how-to-extract-sequences-for-specific-samples-in-dataset/28310/4 "2023-11-15T22:08:30Z")

</div>



---

<div class="post-metadata">

### Author: ![ag1170](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/a/e56c9b/32.png) [@ag1170](https://forum.qiime2.org/u/ag1170)
#### Post date: [November 17, 2023, 6:33pm UTC](https://forum.qiime2.org/t/how-to-extract-sequences-for-specific-samples-in-dataset/28310/5 "2023-11-17T18:33:22Z")

</div>

Thank you for your reply.

So I ran the command you gave, which worked, but it looks like all the samples are still pooled together. How can I discern which sequences are from my specific sample of interest?

---

<div class="post-metadata">

### Author: ![cherman2](https://forum.qiime2.org/user_avatar/forum.qiime2.org/cherman2/32/17129_2.png) [@cherman2](https://forum.qiime2.org/u/cherman2)
#### Post date: [November 17, 2023, 6:53pm UTC](https://forum.qiime2.org/t/how-to-extract-sequences-for-specific-samples-in-dataset/28310/6 "2023-11-17T18:53:48Z")

</div>

Hi @ag1170,  
Can you please provide your table where you filtered down to one sample ( should be your output from qiime `qiime feature-table filter-sample` and your output from `qiime feature-table filter-seqs`.

qiime feature-table filter-sample should filter down your table to one sample.  
`qiime feature-table filter-seqs` should filter your sequences down to just sequences in that sample.

Hope this help!  
🐢

---

<div class="post-metadata">

### Author: ![ag1170](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/a/e56c9b/32.png) [@ag1170](https://forum.qiime2.org/u/ag1170)
#### Post date: [November 17, 2023, 8:58pm UTC](https://forum.qiime2.org/t/how-to-extract-sequences-for-specific-samples-in-dataset/28310/7 "2023-11-17T20:58:58Z")

</div>

Sure, for that I ran:

qiime feature-table filter-samples --i-table ../deblur-filttable4.qza --m-metadata-file sample-metadata-dconly.tsv --o-filtered-table dconly-table

The output is:  
[dconly-table.qza](https://forum.qiime2.org/uploads/short-url/xJvivDboIMDJiz6NcRDAwLpYc5M.qza) (129.9 KB)

For filter-seqs I ran:  
qiime feature-table filter-seqs --i-data ../deblur-repseqs.qza --i-table dconly-table.qza --o-filtered-data dconly

The output is:  
[dconly.qza](https://forum.qiime2.org/uploads/short-url/6s9MdvVfcWfio5xNqYbhCkaY9tJ.qza) (144.4 KB)

Thanks again!

---

<div class="post-metadata">

### Author: ![lizgehret](https://forum.qiime2.org/user_avatar/forum.qiime2.org/lizgehret/32/17128_2.png) [@lizgehret](https://forum.qiime2.org/u/lizgehret)
#### Post date: [November 17, 2023, 9:07pm UTC](https://forum.qiime2.org/t/how-to-extract-sequences-for-specific-samples-in-dataset/28310/8 "2023-11-17T21:07:59Z")

</div>



---

<div class="post-metadata">

### Author: ![cherman2](https://forum.qiime2.org/user_avatar/forum.qiime2.org/cherman2/32/17129_2.png) [@cherman2](https://forum.qiime2.org/u/cherman2)
#### Post date: [November 17, 2023, 9:12pm UTC](https://forum.qiime2.org/t/how-to-extract-sequences-for-specific-samples-in-dataset/28310/9 "2023-11-17T21:12:01Z")

</div>

Hi @ag1170  
Looking at your table after you filter you have 2 samples remaining. Is that what you are expecting?

 ![Screenshot 2023-11-17 at 2.01.32 PM](https://forum-qiime2-org.s3.dualstack.us-west-2.amazonaws.com/original/3X/9/2/92d8e3dd1db5c0e845a84bf0ebb064adf8e2903b.png)

---

<div class="post-metadata">

### Author: ![cherman2](https://forum.qiime2.org/user_avatar/forum.qiime2.org/cherman2/32/17129_2.png) [@cherman2](https://forum.qiime2.org/u/cherman2)
#### Post date: [November 17, 2023, 9:12pm UTC](https://forum.qiime2.org/t/how-to-extract-sequences-for-specific-samples-in-dataset/28310/10 "2023-11-17T21:12:09Z")

</div>



---

<div class="post-metadata">

### Author: ![ag1170](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/a/e56c9b/32.png) [@ag1170](https://forum.qiime2.org/u/ag1170)
#### Post date: [November 18, 2023, 3:09pm UTC](https://forum.qiime2.org/t/how-to-extract-sequences-for-specific-samples-in-dataset/28310/11 "2023-11-18T15:09:43Z")

</div>

Yes, so now I want to separate the rep seqs that are specific to those two samples.

---

<div class="post-metadata">

### Author: ![lizgehret](https://forum.qiime2.org/user_avatar/forum.qiime2.org/lizgehret/32/17128_2.png) [@lizgehret](https://forum.qiime2.org/u/lizgehret)
#### Post date: [November 20, 2023, 5:14pm UTC](https://forum.qiime2.org/t/how-to-extract-sequences-for-specific-samples-in-dataset/28310/12 "2023-11-20T17:14:55Z")

</div>



---

<div class="post-metadata">

### Author: ![cherman2](https://forum.qiime2.org/user_avatar/forum.qiime2.org/cherman2/32/17129_2.png) [@cherman2](https://forum.qiime2.org/u/cherman2)
#### Post date: [November 20, 2023, 5:51pm UTC](https://forum.qiime2.org/t/how-to-extract-sequences-for-specific-samples-in-dataset/28310/13 "2023-11-20T17:51:59Z")

</div>

Hi @ag1170  
You need to filter down your table to one sample and then filter your rep-seqs using your table.  
Run this but there should only be one sample in your metadata.

> [@ag1170](#):
>
> qiime feature-table filter-samples --i-table ../deblur-filttable4.qza --m-metadata-file sample-metadata-dconly.tsv --o-filtered-table dconly-table

Then run this to filter down to your one sample table.

> [@ag1170](#):
>
> qiime feature-table filter-seqs --i-data ../deblur-repseqs.qza --i-table dconly-table.qza --o-filtered-data dconly

That should allow you to blast the sequences for each sample.

---

<div class="post-metadata">

### Author: ![cherman2](https://forum.qiime2.org/user_avatar/forum.qiime2.org/cherman2/32/17129_2.png) [@cherman2](https://forum.qiime2.org/u/cherman2)
#### Post date: [November 20, 2023, 5:52pm UTC](https://forum.qiime2.org/t/how-to-extract-sequences-for-specific-samples-in-dataset/28310/14 "2023-11-20T17:52:02Z")

</div>



---

<div class="post-metadata">

### Author: ![ag1170](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/a/e56c9b/32.png) [@ag1170](https://forum.qiime2.org/u/ag1170)
#### Post date: [November 20, 2023, 8:42pm UTC](https://forum.qiime2.org/t/how-to-extract-sequences-for-specific-samples-in-dataset/28310/15 "2023-11-20T20:42:19Z")

</div>

This worked! Thank you for your help. Some of my confusion was that the filtered vs unfiltered repseqs files looked very similar, but when looking closer I noticed that it did indeed filter, but this particular sample just has many more sequences compared to the other samples!

---

<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: [December 22, 2023, 2:42am UTC](https://forum.qiime2.org/t/how-to-extract-sequences-for-specific-samples-in-dataset/28310/16 "2023-12-22T02:42:41Z")

</div>

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