# Issue filtering multiple specific taxa out of feature table

**URL:** <https://forum.qiime2.org/t/issue-filtering-multiple-specific-taxa-out-of-feature-table/18496>\
**Category:** User Support\
**Tags:** filter-features, filtering\
**Created:** [February 16, 2021, 5:01pm UTC](https://forum.qiime2.org/t/issue-filtering-multiple-specific-taxa-out-of-feature-table/18496 "2021-02-16T17:01:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cjone228](https://forum.qiime2.org/user_avatar/forum.qiime2.org/cjone228/32/5613_2.png) [@cjone228](https://forum.qiime2.org/u/cjone228)\
**Post date:** [February 16, 2021, 5:01pm UTC](https://forum.qiime2.org/t/issue-filtering-multiple-specific-taxa-out-of-feature-table/18496/1 "2021-02-16T17:01:18Z")

</div>

Hi all,

My colleague @Lauren and I are trying to filter a list of 25 specific contaminants out of our feature table in order to then do further analysis without them being included. We would like to target each contaminant down to the species level.

Before trying to filter out all 25 at once, I tried to filter out just 3 contaminants as a test run. The code is as follows:

```
#!/bin/bash
#SBATCH -c 5
#SBATCH -t 24:00:00
#SBATCH --mail-type=all
#SBATCH --mail-user=cjone228@jhu.edu
#SBATCH --job-name="test filtering contam"
#SBATCH --mem=5G
#SBATCH -p parallel
#SBATCH --array=1-6

# configure
source ~/.bashrc
source activate qiime2-2020.6

# array for different regions ${SLURM_ARRAY_TASK_ID} goes from 1 to 6
declare -a arr=("v2" "v3" "v4" "v67" "v8" "v9")
#TASKID=1
REGION=${arr[${SLURM_ARRAY_TASK_ID}-1]}
echo "$REGION"
mkdir -p $outDir/$REGION

qiime taxa filter-table \
  --i-table ../analysis/P05-clust-tree-cm-goods/$REGION/table.qza \
  --i-taxonomy ../analysis/P05-clust-tree-cm-goods/$REGION/tax-class.qza \
  --p-mode exact \
  --p-exclude "k __Bacteria; p__ Actinobacteria; c __Actinobacteria; o__ Actinomycetales; f __Actinomycetaceae; g__ Varibaculum; s __unassigned","k__ Bacteria; p __Actinobacteria; c__ Actinobacteria; o __Corynebacteriales; f__ Corynebacteriaceae; g __Corynebacterium_1; s__ Corynebacterium_amycolatum","k __Bacteria; p__ Actinobacteria; c __Actinobacteria; o__ Micrococcales; f __Microbacteriaceae; g__ Microbacterium; s__unassigned" \
  --o-filtered-table ../analysis/P05-clust-tree-cm-goods/$REGION/$REGION-test-filtered-table.qza \
  --verbose

qiime feature-table summarize \
  --i-table ../analysis/P05-clust-tree-cm-goods/$REGION/$REGION-test-filtered-table.qza \
  --o-visualization ../analysis/P05-clust-tree-cm-goods/$REGION/$REGION-test-filtered-table.qzv \
  --m-sample-metadata-file ../data/atcc-metadata.tsv \

```

To reiterate, the 3 contaminants we tried to filter out in this test run were:

1. k\_\_Bacteria; p\_\_Actinobacteria; c\_\_Actinobacteria; o\_\_Actinomycetales; f\_\_Actinomycetaceae; g\_\_Varibaculum; s\_\_unassigned
2. k\_\_Bacteria; p\_\_Actinobacteria; c\_\_Actinobacteria; o\_\_Corynebacteriales; f\_\_Corynebacteriaceae; g\_\_Corynebacterium\_1; s\_\_Corynebacterium\_amycolatum
3. k\_\_Bacteria; p\_\_Actinobacteria; c\_\_Actinobacteria; o\_\_Micrococcales; f\_\_Microbacteriaceae; g\_\_Microbacterium; s\_\_unassigned

They were only present in 1 of our 5 samples in the V67 region. The code ran with no errors, but when I compared the filtered V67 feature table to the original V67 feature table, only the 2nd contaminant in the list was filtered!

![Screen Shot 2021-02-15 at 8.45.02 PM](https://forum.qiime2.org/images/transparent.png) ![Screen Shot 2021-02-15 at 8.45.10 PM](https://forum.qiime2.org/images/transparent.png)

I verified which taxa was eliminated by finding the uuid of the one feature that was eliminated in the feature detail tab, and then looking up its taxonomic assignment in one of our other files.

Any ideas as to how we can fix this issue and eventually filter out all 25 contaminants?

Thanks,  
Carli :qiime2:

---

<div class="post-metadata">

**Author:** ![timanix](https://forum.qiime2.org/user_avatar/forum.qiime2.org/timanix/32/17879_2.png) [@timanix](https://forum.qiime2.org/u/timanix)\
**Post date:** [February 16, 2021, 6:45pm UTC](https://forum.qiime2.org/t/issue-filtering-multiple-specific-taxa-out-of-feature-table/18496/2 "2021-02-16T18:45:26Z")

</div>

Hi!

> [@cjone228](#):
>
> Any ideas as to how we can fix this issue and eventually filter out all 25 contaminants?

Double check if you misspelled the taxonomy annotation, even one error will force plugin to fail filtering from a table.

> [@cjone228](#):
>
> They were only present in 1 of our 5 samples in the V67 region.

As a variant, you can use [filter-features: Filter features from table — QIIME 2 2020.11.1 documentation](https://docs.qiime2.org/2020.11/plugins/available/feature-table/filter-features/) to filter the table based on the number of samples in which feature was found.  
If you have a table with different regions, you can divide a table by regions, apply filtration and merge it back.

---

<div class="post-metadata">

**Author:** ![SoilRotifer](https://forum.qiime2.org/user_avatar/forum.qiime2.org/soilrotifer/32/21071_2.png) [@SoilRotifer](https://forum.qiime2.org/u/SoilRotifer)\
**Post date:** [February 16, 2021, 6:50pm UTC](https://forum.qiime2.org/t/issue-filtering-multiple-specific-taxa-out-of-feature-table/18496/3 "2021-02-16T18:50:29Z")

</div>

Hi @cjone228,

I think the issue is that you have multiple separate doube-quoted strings:  
`--p-exclude "k __Bacteria; ...","k__ Bacteria; ...","k__Bacteria; ..."`

Keep everything in one double-quoted string and separate each taxonomy string by commas:

`--p-exclude "k __Bacteria; p__ Actinobacteria; c __Actinobacteria; o__ Actinomycetales; f __Actinomycetaceae; g__ Varibaculum; s __unassigned,k__ Bacteria; p __Actinobacteria; c__ Actinobacteria; o __Corynebacteriales; f__ Corynebacteriaceae; g __Corynebacterium_1; s__ Corynebacterium_amycolatum,k __Bacteria; p__ Actinobacteria; c __Actinobacteria; o__ Micrococcales; f __Microbacteriaceae; g__ Microbacterium; s__unassigned"`

I've just tried this on one of may feature-tables and it worked as expected. Give this a try and let us know how it goes. 🙂

I noticed that you have selected to remove two different `s __unassigned` taxa. You should likely take a look at the taxa that have been flagged within the same genera without a species label, _e.g._ `g__ Varibaculum` and `g__Microbacterium`. Just because they do not have the the ambiguous species label does not mean they should remain in your data as they may still be what you consider contaminants.

-Cheers!

---

<div class="post-metadata">

**Author:** ![cjone228](https://forum.qiime2.org/user_avatar/forum.qiime2.org/cjone228/32/5613_2.png) [@cjone228](https://forum.qiime2.org/u/cjone228)\
**Post date:** [February 16, 2021, 7:27pm UTC](https://forum.qiime2.org/t/issue-filtering-multiple-specific-taxa-out-of-feature-table/18496/4 "2021-02-16T19:27:36Z")

</div>

Hi there,

Thanks for the suggestion! I just tried that, but unfortunately got the same result... super weird. I am not sure what to do from here...

Carli

---

<div class="post-metadata">

**Author:** ![SoilRotifer](https://forum.qiime2.org/user_avatar/forum.qiime2.org/soilrotifer/32/21071_2.png) [@SoilRotifer](https://forum.qiime2.org/u/SoilRotifer)\
**Post date:** [February 16, 2021, 7:47pm UTC](https://forum.qiime2.org/t/issue-filtering-multiple-specific-taxa-out-of-feature-table/18496/5 "2021-02-16T19:47:32Z")

</div>

That is indeed odd. I'd be happy to look at the data if you'd like to share them with me privately.

Otherwise be sure that there are no odd hidden characters or white-spaces in your taxonomy strings. Perhaps export the taxonomy qza file as a text file. Then copy the strings you want directly from that file and try again?

-Mike

---

<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 20, 2021, 1:47am UTC](https://forum.qiime2.org/t/issue-filtering-multiple-specific-taxa-out-of-feature-table/18496/6 "2021-03-20T01:47:34Z")

</div>

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