# Problem filtering features from a table

**URL:** https://forum.qiime2.org/t/problem-filtering-features-from-a-table/32153
**Category:** User Support
**Created:** [December 18, 2024, 9:54am UTC](https://forum.qiime2.org/t/problem-filtering-features-from-a-table/32153 "2024-12-18T09:54:34Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![k.kujala](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/k/c57346/32.png) [@k.kujala](https://forum.qiime2.org/u/k.kujala)
#### Post date: [December 18, 2024, 9:54am UTC](https://forum.qiime2.org/t/problem-filtering-features-from-a-table/32153/1 "2024-12-18T09:54:34Z")

</div>

Hei,

I am trying to remove unwanted features from my feature table based on taxonomy.  
I have classified my features with the greengenes classifier and wanted to remove features with no assigned taxonomy or only assigned at the domain-level.  
I managed to remove most of them using

qiime taxa filter-table --i-table my\_table.qza --i-taxonomy my\_taxonomy.qza --p-exclude 'Unassigned','d\_\_Bacteria','d\_Archaea' --p-mode 'exact' --o-filtered-table filtered\_table.qza

However, my taxa barplot still shows taxa with the taxonomy 'd\_\_Bacteria;p\_\_;c\_\_;o\_\_;f\_\_;g\_\_;s\_\_'.

How can I remove those? I have tried --p-exclude 'd\_\_Bacteria;p\_\_;c\_\_;o\_\_;f\_\_;g\_\_;s\_\_' with both the 'exact' and 'contains' mode, but neither removed those taxa.

---

<div class="post-metadata">

### Author: ![salias](https://forum.qiime2.org/user_avatar/forum.qiime2.org/salias/32/18594_2.png) [@salias](https://forum.qiime2.org/u/salias)
#### Post date: [December 18, 2024, 10:55am UTC](https://forum.qiime2.org/t/problem-filtering-features-from-a-table/32153/2 "2024-12-18T10:55:37Z")

</div>

Hi @k.kujala and welcome to the :qiime2\_square: forum!

> [@k.kujala](#):
>
> wanted to remove features with no assigned taxonomy or only assigned at the domain-level

So you want to keep features like:

- `d __Bacteria;p__ Firmicutes;;;;;`
- `d __Bacteria;p__ Proteobacteria;c __Betaproteobacteria;o__ Neisseriales;f __Neisseriaceae;g__ Neisseria;s__subflava`

And remove features annotated like:

- `d__Bacteria;;;;;;`
- `Unassigned;;;;;;`

Note that when a taxonomic level is present in an annotation we have their prefix in the string. For example, all features with at least a phylum level assignation contains the string `p__` (note the double underscore). When a taxonomic assignation lacks phylum-level info, we don't have that string. We can use that for filtering:

```bash
qiime taxa filter-table \
  --i-table my_table.qza \
  --i-taxonomy my_taxonomy.qza \
  --p-include p__ \
  --p-mode contains \
  --o-filtered-table filtered_table.qza

```

Option `--p-include p__` basically means that all features without annotations at least as specific as phylum level will be discarded. We need to use `--p-mode contains` in order to look for partial matches of the unassigned taxa level we are looking for (see also the [filtering tutorial](https://docs.qiime2.org/2024.10/tutorials/filtering/#taxonomy-based-filtering-of-tables-and-sequences) for more info and references).

Best,

Sergio

---

<div class="post-metadata">

### Author: ![k.kujala](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/k/c57346/32.png) [@k.kujala](https://forum.qiime2.org/u/k.kujala)
#### Post date: [December 18, 2024, 3:17pm UTC](https://forum.qiime2.org/t/problem-filtering-features-from-a-table/32153/3 "2024-12-18T15:17:37Z")

</div>

Hei,

thank you for the answer. Unfortunately, it doesn't work.

To give a bit more detail, before filtering I had two types of Bacteria-taxa that didn't have taxonomy assigned at the phylum level. In the phylum-level taxa barplot those were shown as  
'd\_\_Bacteria; **' and 'd\_\_Bacteria;p**'  
The first one is removed by --p-include p\_\_ , but the second one is not.

---

<div class="post-metadata">

### Author: ![salias](https://forum.qiime2.org/user_avatar/forum.qiime2.org/salias/32/18594_2.png) [@salias](https://forum.qiime2.org/u/salias)
#### Post date: [December 18, 2024, 3:52pm UTC](https://forum.qiime2.org/t/problem-filtering-features-from-a-table/32153/4 "2024-12-18T15:52:36Z")

</div>

> [@k.kujala](#):
>
> I had two types of Bacteria-taxa that didn't have taxonomy assigned at the phylum level

> [@k.kujala](#):
>
> 'd\_\_Bacteria; **' and 'd\_\_Bacteria;p**'

The first one is indeed a feature without phylum level classification (and the command I provided to you removes them). The second one is a feature that is actually classified at the phylum level, but it doesn't have a name. You can read more about this in [this post](https://forum.qiime2.org/t/otu-taxonomic-asssignment/4186).

If you also want to get rid of those, one idea that comes to my mind is to use [RESCRIPt](https://forum.qiime2.org/t/processing-filtering-and-evaluating-the-silva-database-and-other-reference-sequence-data-with-rescript/15494) first to edit the taxonomy:

```bash
qiime rescript edit-taxonomy \
    --i-taxonomy my_taxonomy.qza \
    --p-search-strings p__; \ 
    --p-replacement-strings p__ExcludeMe; \ 
    --o-edited-taxonomy my_taxonomy_edited.qza

```

And then exclude them directly with another `qiime taxa filter-table` (this time using `--p-exclude`):

```bash
qiime taxa filter-table \
  --i-table filtered_table.qza \
  --i-taxonomy my_taxonomy_edited.qza \
  --p-exclude p__ExcludeMe \
  --p-mode contains \
  --o-filtered-table double_filtered_table.qza

```

Best,

Sergio

---

<div class="post-metadata">

### Author: ![k.kujala](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/k/c57346/32.png) [@k.kujala](https://forum.qiime2.org/u/k.kujala)
#### Post date: [December 21, 2024, 5:58pm UTC](https://forum.qiime2.org/t/problem-filtering-features-from-a-table/32153/5 "2024-12-21T17:58:52Z")

</div>

Hei,  
thanks for the explanation. I have managed to filter them by using the --p-exclude 'd\_\_Bacteria; p\_\_; c\_\_; o\_\_; f\_\_; g\_\_; s\_\_' (the space after the ; is what had been missing in my previous attempts for which I had copied the taxon "name" directly from taxa barplot). As I found the assignment to a "nameless" taxon a bit weird, I also pulled out the sequences and reclassified them using consensus-blast with very different results: some where "Unassigned", but the majority were clearly assigned at least on the phylum level (some even down to species), and to quite different phyla as well.  
I'm contemplating using consensus-blast instead of classify-sklearn for my whole dataset now.

Thanks,  
Katharina

---

<div class="post-metadata">

### Author: ![salias](https://forum.qiime2.org/user_avatar/forum.qiime2.org/salias/32/18594_2.png) [@salias](https://forum.qiime2.org/u/salias)
#### Post date: [December 22, 2024, 2:11pm UTC](https://forum.qiime2.org/t/problem-filtering-features-from-a-table/32153/6 "2024-12-22T14:11:27Z")

</div>

Hi again @k.kujala

I'm happy you got it working!

> [@k.kujala](#):
>
> I'm contemplating using consensus-blast instead of classify-sklearn for my whole dataset now

If you want more information in order to make a decision, you may want to check this post:

> [@Best Feature-Classifier?](https://forum.qiime2.org/t/best-feature-classifier/4541/4):
>
> There is no "best" — but classify-sklearn in general performs better out of the box, and is our general recommendation for 16S and ITS sequences. All are very accurate at genus level, however, and reasonably accurate at species level (which is to say the defaults are optimized to NOT classify at species level if a confident hit cannot be determined). See [this article](https://microbiomejournal.biomedcentral.com/articles/10.1186/s40168-018-0470-z) for a comparison of these and other classification methods, and some discussion of pros/cons and how to fiddle with the paramete…

Best,

Sergio

---

<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: [January 22, 2025, 8:12pm UTC](https://forum.qiime2.org/t/problem-filtering-features-from-a-table/32153/7 "2025-01-22T20:12:26Z")

</div>

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