BWA mem or samtools have any parameter to filter the mismatch reads?
1
0
Entering edit mode
3.0 years ago
Damon_Wan • 0

I'm looking for the parameter of BWA mem or samtools to filter out the mapped reads contain N% mismatched bases in or after reads mapping to the reference genome.

However, I can't figure out how to combain the scoring parameters of BWA mem, nither find the filtering parameters of samtools view to deal with it.

Dose anyone could give some advises?

Thanks a lot!

mapping samtools reads BWA • 1.6k views
ADD COMMENT
1
Entering edit mode
3.0 years ago

use the edit distance : NM ?

samtools view -e '[NM]>5'
ADD COMMENT
0
Entering edit mode

This is the first time that I heard about this feature. Extremely useful.

Looks like it was introduced in samtools version 1.12 (March 2021)

https://github.com/samtools/samtools/releases/

samtools view now works with the filtering expressions introduced by HTSlib. The filtering expression is passed to the program using the specific option -e or the global long option --input-fmt-option. E.g.

samtools view -e 'qname =~ "#49$" && mrefid != refid && refid != -1 &&  mrefid != -1' align.bam

for those with older versions of samtools:

mamba install samtools==1.12
ADD REPLY
0
Entering edit mode

Thanks!

But It seemed like the [NM] just counts the number of mismatched bases. How could I calculate the percentage of mismatched bases of each reads considering their length.

I simply tried samtools view -e '[NM]/qlen < 0.05' but I got errors [E::sam_passes_filter] Couldn't process filter expression

How to correct the filtering expression?

ADD REPLY

Login before adding your answer.

Traffic: 2579 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6