How to get samtools flagstats results from samtools view
1
0
Entering edit mode
3.2 years ago

Hello,

I have been working with samtools and I want to get a count of how many properly paired and mapped reads are within a region. I had been doing this previously:

When I run samtools flagstat I get the following result

261533415 + 0 in total (QC-passed reads + QC-failed reads)
81513623 + 0 secondary
0 + 0 supplementary
0 + 0 duplicates
236213573 + 0 mapped (90.32% : N/A)
180019792 + 0 paired in sequencing
90009896 + 0 read1
90009896 + 0 read2
154569772 + 0 properly paired (85.86% : N/A)
154569772 + 0 with itself and mate mapped
130178 + 0 singletons (0.07% : N/A)
0 + 0 with mate mapped to a different chr
0 + 0 with mate mapped to a different chr (mapQ>=5)

I want to know how many of the paired in sequencing reads are within a region of a bed file. I have been doing this with samtools view -L ${my_bed} -c -F 1028 ${bam} but when I run that I get more reads than paired in sequencing, i.e: 181377346

Could someone tell me the exact flagged codes to use to get the paired in sequencing reads?

samtools flagstat • 1.1k views
ADD COMMENT
1
Entering edit mode
3.2 years ago
ATpoint 81k

Try samtools view -L ${my_bed} -F 1028 ${bam} | samtools flagstat - to get the flagstat output directly, rather than relying on -c (not sure what -c does in detail).

ADD COMMENT
0
Entering edit mode

-c just outputs the count, But if i can pipe samtools outputs directly to flagstat that might be more valuable.

I will try samtools view -L ${my_bed} -b ${bam} | samtools flagstat -

ADD REPLY
0
Entering edit mode

That worked beautifully, thank you very much ATpoint

ADD REPLY

Login before adding your answer.

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