# Trim based on quality score not the sequence position

**URL:** https://forum.qiime2.org/t/trim-based-on-quality-score-not-the-sequence-position/6830
**Category:** User Support
**Created:** [November 7, 2018, 12:50pm UTC](https://forum.qiime2.org/t/trim-based-on-quality-score-not-the-sequence-position/6830 "2018-11-07T12:50:25Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![Negin](https://forum.qiime2.org/user_avatar/forum.qiime2.org/negin/32/5030_2.png) [@Negin](https://forum.qiime2.org/u/Negin)
#### Post date: [November 7, 2018, 12:50pm UTC](https://forum.qiime2.org/t/trim-based-on-quality-score-not-the-sequence-position/6830/1 "2018-11-07T12:50:25Z")

</div>

Hi,

I have a question about quality check and trimming in qiime2. I usually trimmed my sequences based on the primer sequence and the quality score below 20 using trimmoatic. However, the way trimming works with qiime 2 is that we should trim based on the sample position where the quality drops. However, my quality drops at 236 position and goes up again at 245. Is there anyway that I can trim at a specific quality instead of a position? Also, for trimming the primer, should I use --p-trim-left 19 if my primer is 19 nucleotide?

Thanks

 ![51%20PM](https://forum-qiime2-org.s3.dualstack.us-west-2.amazonaws.com/original/2X/7/7133dc3bdd77abb4bfe77a6fa06867d106c1055d.png)

---

<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: [November 7, 2018, 1:02pm UTC](https://forum.qiime2.org/t/trim-based-on-quality-score-not-the-sequence-position/6830/2 "2018-11-07T13:02:02Z")

</div>

> [@Negin](#):
>
> the way trimming works with qiime 2 is that we should trim based on the sample position where the quality drops.

That is a misunderstanding.

1. QIIME 2 has multiple different approaches to trimming available.
2. For manual trimming we usually recommend trimming where quality drops off below a threshold (my rule of thumb is where median Q drops \< 20), not just arbitrarily wherever quality begins dropping.

One reason why we usually recommend manual trimming at a specific site is because otherwise identical sequences trimmed to different lengths will be considered different ASVs/OTUs, skewing diversity estimates. This is less of a concern with paired-end sequences, as sequences are being merged back into complete amplicons or dropped if they are too short.

> [@Negin](#):
>
> I usually trimmed my sequences based on the primer sequence and the quality score below 20 using trimmoatic.

You can do that in QIIME 2 as well! See the [quality-filter](https://docs.qiime2.org/2018.8/plugins/available/quality-filter/) plugin. Additionally, dada2 has a `--p-trunc-q` parameter to perform this type of trimming (e.g., see [here](https://docs.qiime2.org/2018.8/plugins/available/dada2/denoise-paired/)).

> [@Negin](#):
>
> for trimming the primer, should I use --p-trim-left 19 if my primer is 19 nucleotide?

Yes, if your primers are still in the sequence (they aren't always, depending on the sequencing protocol you used).

I hope that helps!

---

<div class="post-metadata">

### Author: ![Negin](https://forum.qiime2.org/user_avatar/forum.qiime2.org/negin/32/5030_2.png) [@Negin](https://forum.qiime2.org/u/Negin)
#### Post date: [November 7, 2018, 5:22pm UTC](https://forum.qiime2.org/t/trim-based-on-quality-score-not-the-sequence-position/6830/3 "2018-11-07T17:22:15Z")

</div>

> [@Nicholas\_Bokulich](#):
>
> One reason why we usually recommend manual trimming at a specific site is because otherwise identical sequences trimmed to different lengths will be considered different ASVs/OTUs, skewing diversity estimates. This is less of a concern with paired-end sequences, as sequences are being merged back into complete amplicons or dropped if they are too short.

Do you recommend that I use paired-end sequences if I have them? Our previous experience in the lab was that we usually got less diversity and worse reads when we used both sequences. My concern for cutting the sequences at a specific length is that I will lose a lot of reads. Also, if I trim them based on quality score of 20, anyways the length would change between different reads. How can I avoid that?

---

<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: [November 7, 2018, 5:37pm UTC](https://forum.qiime2.org/t/trim-based-on-quality-score-not-the-sequence-position/6830/4 "2018-11-07T17:37:27Z")

</div>

> [@Negin](#):
>
> Do you recommend that I use paired-end sequences if I have them?

that's a matter of personal taste/goals. I have been in your same position — bad merges on paired-end reads are worse than just using single-end. But I would always give it a shot if you have the data.

> [@Negin](#):
>
> My concern for cutting the sequences at a specific length is that I will lose a lot of reads.

You lose some information, but that may not necessarily impact classification and it is better than skewing diversity estimates. Depends on your goals, though (e.g., if you only care about taxonomic classification, not diversity estimates, then it all comes out in the wash)

> [@Negin](#):
>
> Also, if I trim them based on quality score of 20, anyways the length would change between different reads. How can I avoid that?

Yep, that's the point I was making above. There is no avoiding that if you are using single-end reads and want to trim dynamically. If using single-end I would just recommend at a fixed position.

Your reads look like they are high quality so you could probably get by without truncating! Let dada2 filter out the few sequences that do contain too many errors. (still trim out your primer(s))

---

<div class="post-metadata">

### Author: ![Negin](https://forum.qiime2.org/user_avatar/forum.qiime2.org/negin/32/5030_2.png) [@Negin](https://forum.qiime2.org/u/Negin)
#### Post date: [November 7, 2018, 8:13pm UTC](https://forum.qiime2.org/t/trim-based-on-quality-score-not-the-sequence-position/6830/5 "2018-11-07T20:13:33Z")

</div>

> [@Nicholas\_Bokulich](#):
>
> Your reads look like they are high quality so you could probably get by without truncating! Let dada2 filter out the few sequences that do contain too many errors. (still trim out your primer(s))

Hi Nicholas,

Thank you so much for your helpful comments. So if I do not truncate and only remove the primers, is that how my code should look like? and would that also filter out erroneous sequences or should I add anything to this code for that? I am new to qiime 2, so please forgive my ignorance.

qiime dada2 denoise-single   
--i-demultiplexed-seqs V4-20181012-demux.qza   
--p-trim-left 19   
--o-representative-sequences V4-20181012-rep-seqs-dada2.qza   
--o-table V4-20181012-table-dada2.qza   
--o-denoising-stats V4-20181012-stats-dada2.qza

And I imagine I do not need to include --p-trunc-len ?

---

<div class="post-metadata">

### Author: ![Negin](https://forum.qiime2.org/user_avatar/forum.qiime2.org/negin/32/5030_2.png) [@Negin](https://forum.qiime2.org/u/Negin)
#### Post date: [November 7, 2018, 8:14pm UTC](https://forum.qiime2.org/t/trim-based-on-quality-score-not-the-sequence-position/6830/6 "2018-11-07T20:14:29Z")

</div>

> [@Nicholas\_Bokulich](#):
>
> that’s a matter of personal taste/goals. I have been in your same position — bad merges on paired-end reads are worse than just using single-end. But I would always give it a shot if you have the data.

Sure. I will try both and compare the data. If I use paired-end reads, then I guess I can trim based on a specific quality score and get away with read length issue, right?

---

<div class="post-metadata">

### Author: ![Negin](https://forum.qiime2.org/user_avatar/forum.qiime2.org/negin/32/5030_2.png) [@Negin](https://forum.qiime2.org/u/Negin)
#### Post date: [November 7, 2018, 8:16pm UTC](https://forum.qiime2.org/t/trim-based-on-quality-score-not-the-sequence-position/6830/7 "2018-11-07T20:16:51Z")

</div>

> [@Nicholas\_Bokulich](#):
>
> You lose some information, but that may not necessarily impact classification and it is better than skewing diversity estimates. Depends on your goals, though (e.g., if you only care about taxonomic classification, not diversity estimates, then it all comes out in the wash)

so the reason I was concerned about this was because I have a few negative control samples (water). Truncating at position 236, removed most of the reads for two of them and I ended up having only 1 and 4 reads left for them. They originally had more than 200.

---

<div class="post-metadata">

### Author: ![Negin](https://forum.qiime2.org/user_avatar/forum.qiime2.org/negin/32/5030_2.png) [@Negin](https://forum.qiime2.org/u/Negin)
#### Post date: [November 7, 2018, 8:41pm UTC](https://forum.qiime2.org/t/trim-based-on-quality-score-not-the-sequence-position/6830/8 "2018-11-07T20:41:32Z")

</div>

> [@Negin](#):
>
> And I imagine I do not need to include --p-trunc-len ?

sorry I figured it should be there but I should set it at 0  
--p-trunc-len 0 /

---

<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: [November 8, 2018, 1:50pm UTC](https://forum.qiime2.org/t/trim-based-on-quality-score-not-the-sequence-position/6830/9 "2018-11-08T13:50:36Z")

</div>

> [@Negin](#):
>
> would that also filter out erroneous sequences or should I add anything to this code for that?

Yes

> [@Negin](#):
>
> If I use paired-end reads, then I guess I can trim based on a specific quality score and get away with read length issue, right?

Correct — as long as trimming based on quality scores doesn't trim too much and the sequences cannot overlap.

> [@Negin](#):
>
> so the reason I was concerned about this was because I have a few negative control samples (water). Truncating at position 236, removed most of the reads for two of them and I ended up having only 1 and 4 reads left for them. They originally had more than 200.

This is caused by one of two things:

1. you have already trimmed the reads based on quality, so some of those sequences are shorter than 236 and get filtered out automatically.
2. those negative control sequences are so riddled with errors that they get filtered out if you cut at a position that seems reasonable for other samples.

---

<div class="post-metadata">

### Author: ![Negin](https://forum.qiime2.org/user_avatar/forum.qiime2.org/negin/32/5030_2.png) [@Negin](https://forum.qiime2.org/u/Negin)
#### Post date: [November 8, 2018, 6:51pm UTC](https://forum.qiime2.org/t/trim-based-on-quality-score-not-the-sequence-position/6830/10 "2018-11-08T18:51:18Z")

</div>

I tried dada2 with –p-trunc-len 0 / and –p-trim-left 19 and checked my read counts again. The issue persists with negative controls. Even though I did not truncate, read counts are still dramatically low (4 for negative control 1 and 2 for negative control 2). I imagine this happened as part of quality filtering that dada2 does. How would dada2 do this when I never asked it to do using any command line?

---

<div class="post-metadata">

### Author: ![Negin](https://forum.qiime2.org/user_avatar/forum.qiime2.org/negin/32/5030_2.png) [@Negin](https://forum.qiime2.org/u/Negin)
#### Post date: [November 8, 2018, 6:52pm UTC](https://forum.qiime2.org/t/trim-based-on-quality-score-not-the-sequence-position/6830/11 "2018-11-08T18:52:02Z")

</div>

I did not trim them before so it should be the second reason.

---

<div class="post-metadata">

### Author: ![Negin](https://forum.qiime2.org/user_avatar/forum.qiime2.org/negin/32/5030_2.png) [@Negin](https://forum.qiime2.org/u/Negin)
#### Post date: [November 8, 2018, 6:53pm UTC](https://forum.qiime2.org/t/trim-based-on-quality-score-not-the-sequence-position/6830/12 "2018-11-08T18:53:36Z")

</div>

> [@Negin](#):
>
> How would dada2 do this when I never asked it to do using any command line?

I mean the quality filtering. I did not use anything except for

qiime dada2 denoise-single  
–i-demultiplexed-seqs V4-20181012-demux.qza  
–p-trim-left 19  
–p-trunc-len 0 /  
–o-representative-sequences V4-20181012-rep-seqs-dada2.qza  
–o-table V4-20181012-table-dada2.qza  
–o-denoising-stats V4-20181012-stats-dada2.qza

Which part of this is asking for quality filtering?

---

<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: [November 8, 2018, 7:07pm UTC](https://forum.qiime2.org/t/trim-based-on-quality-score-not-the-sequence-position/6830/13 "2018-11-08T19:07:30Z")

</div>

dada2 always performs quality filtering — it _is_ a denoising method, not a dereplication method.

> [@Negin](#):
>
> Even though I did not truncate, read counts are still dramatically low (4 for negative control 1 and 2 for negative control 2).

Rather, this could be _because you did not truncate_. Without any truncation, you are including low-quality bases (I am guessing the negative controls have lower quality reads overall since you mention this is expressed most strongly in the controls). dada2 is going to toss out any read that has \> 2 probably errors. This is the whole purpose of truncation prior to using dada2.

Before proceeding, I recommend that you [check out the original publication for dada2](https://www.nature.com/articles/nmeth.3869) to learn more.

You should also always examine the stats file output by dada2 (use `qiime metadata tabulate` to view as a QZV file) — this will tell you at which point of the dada2 pipeline reads are being dropped. Since you are doing single-end this is almost certainly at the filtering step, but could also be chimera filtering.

I think it is probably a _good_ thing that your negative control reads are being filtered. They may be chimera or other bad reads and dada2 is doing its job. But you need to check out that stats file to figure out more.

---

<div class="post-metadata">

### Author: ![Negin](https://forum.qiime2.org/user_avatar/forum.qiime2.org/negin/32/5030_2.png) [@Negin](https://forum.qiime2.org/u/Negin)
#### Post date: [November 8, 2018, 7:55pm UTC](https://forum.qiime2.org/t/trim-based-on-quality-score-not-the-sequence-position/6830/14 "2018-11-08T19:55:54Z")

</div>

> [@Nicholas\_Bokulich](#):
>
> dada2 is going to toss out any read that has \> 2 probably errors.

Thank you for your reply. So does this mean that even if I do not specify a parameter, the default value will be executed?

---

<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: [November 8, 2018, 8:26pm UTC](https://forum.qiime2.org/t/trim-based-on-quality-score-not-the-sequence-position/6830/15 "2018-11-08T20:26:40Z")

</div>

> [@Negin](#):
>
> So does this mean that even if I do not specify a parameter, the default value will be executed?

That statement is true for any method in any software: if you do not specify a parameter setting, the default is used.

So in this case `--p-max-ee` is the parameter that performs pre-denoising filtering. You can adjust that parameter if you think this is too stringent for your data, but that sort of runs counter to the purpose of using dada2 (and QC in general) unless if, e.g., you have very long reads and think that 2 is not appropriate.

---

<div class="post-metadata">

### Author: ![Negin](https://forum.qiime2.org/user_avatar/forum.qiime2.org/negin/32/5030_2.png) [@Negin](https://forum.qiime2.org/u/Negin)
#### Post date: [November 9, 2018, 12:14am UTC](https://forum.qiime2.org/t/trim-based-on-quality-score-not-the-sequence-position/6830/16 "2018-11-09T00:14:59Z")

</div>

Thanks so much Nicholas for your help. I posted another topic here [FastQC compared to QIIME 2 quality plot](https://forum.qiime2.org/t/fastqc-compared-to-qiime-2-quality-plot/6865)

I would be appreciated if you could take a look at that.

---

<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 10, 2018, 6:23am UTC](https://forum.qiime2.org/t/trim-based-on-quality-score-not-the-sequence-position/6830/17 "2018-12-10T06:23:12Z")

</div>

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