# Filter representative sequences according to sequence's length

**URL:** https://forum.qiime2.org/t/filter-representative-sequences-according-to-sequences-length/11998
**Category:** User Support
**Tags:** feature-table
**Created:** [October 16, 2019, 2:23pm UTC](https://forum.qiime2.org/t/filter-representative-sequences-according-to-sequences-length/11998 "2019-10-16T14:23:22Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![sixvable](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@sixvable](https://forum.qiime2.org/u/sixvable)
#### Post date: [October 16, 2019, 2:23pm UTC](https://forum.qiime2.org/t/filter-representative-sequences-according-to-sequences-length/11998/1 "2019-10-16T14:23:22Z")

</div>

Hello qiime2 team!

Recently I deal with my raw sequence which is sequenced under Miseq PE300 mode.  
The quality of sequence is not really good.When I denoise it I found some representative sequences which are short than my expecting length.I blast it and I am sure they are not my target sequences.  
So I want to filter my rep-seqs by length but I could not find a plugin which provide the function directly(Just like --p-min-length and --p-max-length).  
Although I could transform it to an excel sheet and filter under microsoft office but I still want an easier way by deal under qiime2!  
Could u implement that function in next version?😀

---

<div class="post-metadata">

### Author: ![yanxianl](https://forum.qiime2.org/user_avatar/forum.qiime2.org/yanxianl/32/2039_2.png) [@yanxianl](https://forum.qiime2.org/u/yanxianl)
#### Post date: [October 16, 2019, 2:42pm UTC](https://forum.qiime2.org/t/filter-representative-sequences-according-to-sequences-length/11998/2 "2019-10-16T14:42:32Z")

</div>

Hi,

I'm not aware of QIIME2 command lines for filtering sequences based on length. Depending on the primers used, [the amplicon sizes may actually vary quite a bit](https://forum.qiime2.org/t/can-we-use-extracted-reference-reads-to-calculate-expected-amplicon-sizes/11038/3). If the goal is to remove the non-targetted sequences, you can try the [q2-quality-control plugin](https://docs.qiime2.org/2019.7/tutorials/quality-control/), which allows you to filter sequences by alignment, say to a reference database to exclude non-bacterial sequences.

Hope that helps.

-Yanxian

---

<div class="post-metadata">

### Author: ![sixvable](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@sixvable](https://forum.qiime2.org/u/sixvable)
#### Post date: [October 16, 2019, 3:34pm UTC](https://forum.qiime2.org/t/filter-representative-sequences-according-to-sequences-length/11998/3 "2019-10-16T15:34:33Z")

</div>

Thank u @yanxianl  
My sequences is actually targeting a functional gene so it has no reference database.  
And some sequences length is far from my target amplicon size so I am sure they are not my aim sequences 😆 .Also check by blast to NT reference datasets.  
Now I just try to filterd it using vsearch.

---

<div class="post-metadata">

### Author: ![Nicholas\_Bokulich](https://forum.qiime2.org/user_avatar/forum.qiime2.org/nicholas_bokulich/32/19937_2.png) [@Nicholas\_Bokulich](https://forum.qiime2.org/u/Nicholas_Bokulich)
#### Post date: [October 17, 2019, 2:16am UTC](https://forum.qiime2.org/t/filter-representative-sequences-according-to-sequences-length/11998/4 "2019-10-17T02:16:40Z")

</div>

> [@sixvable](#):
>
> My sequences is actually targeting a functional gene so it has no reference database.

You can make one — it sounds like you already found one! This one:

> [@sixvable](#):
>
> NT reference datasets

It would just take a few representative sequences to do the trick, but the more the merrier.

> [@sixvable](#):
>
> Now I just try to filterd it using vsearch.

That would do the same exact thing as what @yanxianl is recommending. With vsearch you will still presumably need some reference sequences to align against.

---

<div class="post-metadata">

### Author: ![sixvable](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@sixvable](https://forum.qiime2.org/u/sixvable)
#### Post date: [October 17, 2019, 3:28am UTC](https://forum.qiime2.org/t/filter-representative-sequences-according-to-sequences-length/11998/5 "2019-10-17T03:28:09Z")

</div>

Thank for advice @Nicholas_Bokulich

> [@Nicholas\_Bokulich](#):
>
> You can make one — it sounds like you already found one!

My target amplicon is Bacterial amoA( **ammonium monooxygenase subunit A** ) . There is actually no good performance reference dataset.

> [@Nicholas\_Bokulich](#):
>
> It would just take a few representative sequences to do the trick, but the more the merrier.

Here is my rep-seqs file which only filter the singleton.[rep-seqs-nosinglton.qzv](https://forum.qiime2.org/uploads/short-url/8tkhF14QotCok556hI08Rj2zBuM.qzv) (282.3 KB)  
My target amplicon sequence size is 452bp but as u can see there is still some rep-seqs which is lower than 400bp(some even only 180bp 😆).  
I have arranged my own reference database but I am not sure it would assign with a good performance.I have to test and adjust my reference database later. I dont want to take the risk to assign my feature and filter by it beacuse some real target may be discard due to uncorrect annotation.  
Filter it first by rep-seqs length seems lower risk to me.

> [@Nicholas\_Bokulich](#):
>
> That would do the same exact thing as what @yanxianl is recommending. With vsearch you will still presumably need some reference sequences to align against.

Now I use vsearch to filter it by command  
**Vsearch --fastx\_filter rep-seqs-nonsingleton.fasta --fastq\_minlen 400 --fastaout file**

Is there a better way deal with that issue?

---

<div class="post-metadata">

### Author: ![Nicholas\_Bokulich](https://forum.qiime2.org/user_avatar/forum.qiime2.org/nicholas_bokulich/32/19937_2.png) [@Nicholas\_Bokulich](https://forum.qiime2.org/u/Nicholas_Bokulich)
#### Post date: [October 17, 2019, 3:30am UTC](https://forum.qiime2.org/t/filter-representative-sequences-according-to-sequences-length/11998/6 "2019-10-17T03:30:09Z")

</div>

> [@sixvable](#):
>
> Now I use vsearch to filter it by command  
> **Vsearch --fastx\_filter rep-seqs-nonsingleton.fasta --fastq\_minlen 400 --fastaout file**

Sure that works — I had assumed you were using vsearch to filter by alignment

> [@sixvable](#):
>
> I have arranged my own reference database but I am not sure it would assign with a good performance.I have to test and adjust my reference database later. I dont want to take the risk to assign my feature and filter by it beacuse some real target may be discard due to uncorrect annotation.

I was not recommending that you classify taxonomically, nor is @yanxianl. the `q2-quality-control` plugin would blast your sequences against a set of reference sequences and discard based on alignment quality.

Sounds like you have sorted things out with vsearch, though, and that's fine 😄

---

<div class="post-metadata">

### Author: ![sixvable](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@sixvable](https://forum.qiime2.org/u/sixvable)
#### Post date: [October 17, 2019, 4:03am UTC](https://forum.qiime2.org/t/filter-representative-sequences-according-to-sequences-length/11998/7 "2019-10-17T04:03:51Z")

</div>

Thank u nick

> [@Nicholas\_Bokulich](#):
>
> I was not recommending that you classify taxonomically, nor is @yanxianl. the `q2-quality-control` plugin would blast your sequences against a set of reference sequences and discard based on alignment quality.

Now I know what u mean about using `q2-quality-control` to filter my sequences.I will try that later！ 😀 Great solution!  
Still I would want an implement of length filtering in qiime2 plugin.  
Also I was banned a few month ago because a crosslink. May I unbanned now?😬

---

<div class="post-metadata">

### Author: ![Nicholas\_Bokulich](https://forum.qiime2.org/user_avatar/forum.qiime2.org/nicholas_bokulich/32/19937_2.png) [@Nicholas\_Bokulich](https://forum.qiime2.org/u/Nicholas_Bokulich)
#### Post date: [October 17, 2019, 4:09am UTC](https://forum.qiime2.org/t/filter-representative-sequences-according-to-sequences-length/11998/8 "2019-10-17T04:09:38Z")

</div>

> [@sixvable](#):
>
> Still I would want an implement of length filtering in qiime2 plugin.

I agree that would be useful — any interest in contributing to the q2-vsearch plugin?

---

<div class="post-metadata">

### Author: ![sixvable](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@sixvable](https://forum.qiime2.org/u/sixvable)
#### Post date: [October 17, 2019, 4:19am UTC](https://forum.qiime2.org/t/filter-representative-sequences-according-to-sequences-length/11998/10 "2019-10-17T04:19:33Z")

</div>

> [@Nicholas\_Bokulich](#):
>
> I agree that would be useful — any interest in contributing to the q2-vsearch plugin?

Honestly I have no abilility to do this work.I am barely dont know how to use python.😥

---

<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: [November 17, 2019, 10:26am UTC](https://forum.qiime2.org/t/filter-representative-sequences-according-to-sequences-length/11998/11 "2019-11-17T10:26:30Z")

</div>

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