# Filtering out ASVs from DADA2 based on length

**URL:** https://forum.qiime2.org/t/filtering-out-asvs-from-dada2-based-on-length/9217
**Category:** User Support
**Tags:** dada2
**Created:** [April 12, 2019, 1:48am UTC](https://forum.qiime2.org/t/filtering-out-asvs-from-dada2-based-on-length/9217 "2019-04-12T01:48:09Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![camillaln](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/c/96bed5/32.png) [@camillaln](https://forum.qiime2.org/u/camillaln)
#### Post date: [April 12, 2019, 1:48am UTC](https://forum.qiime2.org/t/filtering-out-asvs-from-dada2-based-on-length/9217/1 "2019-04-12T01:48:09Z")

</div>

Hi,

I am wondering an option to filter out features (ASVs) based on lenght has been added.  
I found some discussion about it ([Comparison of DADA2 with Deblur](https://forum.qiime2.org/t/comparison-of-dada2-with-deblur/3503)) but could not find if a solution to this anywhere.

Thanks,  
Camilla

---

<div class="post-metadata">

### Author: ![devonorourke](https://forum.qiime2.org/user_avatar/forum.qiime2.org/devonorourke/32/3110_2.png) [@devonorourke](https://forum.qiime2.org/u/devonorourke)
#### Post date: [April 12, 2019, 1:39pm UTC](https://forum.qiime2.org/t/filtering-out-asvs-from-dada2-based-on-length/9217/2 "2019-04-12T13:39:28Z")

</div>

Hi @camillaln,  
I'm not sure if you're talking about 16S data, ITS data, or something else, but I've encountered a similar question about how to process my COI amplicons. One thing I've seen in the forum posted before is that it's dangerous to filter for a specific single value because it ignores/discards the (likely) true biological variation that exists in the marker gene as well as whatever bioinformatic noise you might be hoping to remove.  
In the link you provided there is a function `qiime deblur denoise-16S` with the parameter `–o-stats trimmed/deblur/deblur-stats.qza` being passed that is used to then generate the subsequent data table showing the frequency of the lengths of the features. Unfortunately that doesn't show you the length of each feature, and I don't know of any QIIME function to do that.  
You could however export the `–o-representative-sequences` artifact into a fasta file, then count the lengths of each feature with whatever program you want (Python, R)... here's one way to do in using just bash:

```auto
cat dna-sequences.fasta | paste - - | sed 's/>//' | awk '{ print $1,length($2) }' | sort -k2,2n

```

You'll get a two-column table of the feature ID and the length, sorted with the shortest at the top of the list. That might give you a sense of how many (and which) features are items you think are of interest to filter out. Once you make a list (`droplist.txt`) of those features you want to remove, then you can use existing QIIME functions to create the filtered table and sequence `.qza`'s you want:

```auto
qiime feature-table filter-features \
--i-table original.table.qza \
--m-metadata-file droplist.txt \
--p-exclude-ids \
--o-filtered-table filtered.table.qza

qiime feature-table filter-seqs \
--i-data original.seqs.qza \
--m-metadata-file droplist.txt \
--p-exclude-ids \
--o-filtered-data filtered.seqs.qza

```

---

<div class="post-metadata">

### Author: ![camillaln](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/c/96bed5/32.png) [@camillaln](https://forum.qiime2.org/u/camillaln)
#### Post date: [April 12, 2019, 5:11pm UTC](https://forum.qiime2.org/t/filtering-out-asvs-from-dada2-based-on-length/9217/3 "2019-04-12T17:11:36Z")

</div>

Thank you! This is really helpful,  
Camilla

---

<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: [April 12, 2019, 6:20pm UTC](https://forum.qiime2.org/t/filtering-out-asvs-from-dada2-based-on-length/9217/4 "2019-04-12T18:20:18Z")

</div>

Just wanted to toss out one more option for length-based filtering:

```bash
qiime feature-table filter-seqs \
    --i-data seqs.qza \
    --m-metadata-file seqs.qza \
    --p-where 'length(sequence) > 4' \
    --o-filtered-data filtered-seqs.qza 

```

This works by viewing the `FeatureData[Sequence]` as Metadata, and then using a SQL-where clause to compute the length. The advantage here is then you don't have to export anything. This command above would keep any sequences longer than 4 nts.

:qiime2:

---

<div class="post-metadata">

### Author: ![devonorourke](https://forum.qiime2.org/user_avatar/forum.qiime2.org/devonorourke/32/3110_2.png) [@devonorourke](https://forum.qiime2.org/u/devonorourke)
#### Post date: [April 12, 2019, 6:44pm UTC](https://forum.qiime2.org/t/filtering-out-asvs-from-dada2-based-on-length/9217/5 "2019-04-12T18:44:50Z")

</div>

I just wanted to show off my Bash chops @thermokarst - way to burst my bubble with your one liner! 😄

---

<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: [May 14, 2019, 12:44am UTC](https://forum.qiime2.org/t/filtering-out-asvs-from-dada2-based-on-length/9217/6 "2019-05-14T00:44:52Z")

</div>

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