How to extract alignments with 0 mismatch from sam or bam file by using samtools?
3
0
Entering edit mode
3.5 years ago
khanhlpbao • 0

I have a single-ended sam files generated from bwa with default settings for NIPT calculation. How can I extract a sam or bam files that contains only alignments that have 0 mismatch by using samtools?

bam samtools sam • 3.4k views
ADD COMMENT
1
Entering edit mode
3.5 years ago
samtools view -e '[NM]==0' -O BAM -o out.bam   in.bam

requires a recent version of samtools.

ADD COMMENT
0
Entering edit mode

Oops those were from my notes dates 5 years back my bad. edited my answer.

ADD REPLY
0
Entering edit mode
3.5 years ago
badribio ▴ 290

You could use this samtools view -h bwa.bam | grep "NM:i:0" | samtools view -O BAM -o bwa.filtered.bam

ADD COMMENT
0
Entering edit mode

Thanks, can I replace bwa.bam with bwa.sam? Or I need to convert it to bam first?

ADD REPLY
0
Entering edit mode

this is wrong, the last command is trying to read a file bwa.filtered.bam. You want .. | samtools view -O BAM -o bwa.filtered.bam

ADD REPLY
0
Entering edit mode

Hi, by somehow it shows error: no header when type together but worked when I type them separately

ADD REPLY

Login before adding your answer.

Traffic: 1953 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