This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Extract information of mapped reads bam files

Hi all, I have a bam files from RRBS data and want to extract these information from them, anyone know how I can get these output (an example is below)?

Thanks in advance,

 Output
  20000 reads; of these:
  20000 (100.00%) were unpaired; of these:
  1247 (6.24%) aligned 0 times
  18739 (93.69%) aligned exactly 1 time
  14 (0.07%) aligned >1 times
  93.77% overall alignment rate
mapped bam alignment

2 answers

You can use samtools for this. Please check out in this link.

samtools flagstat RRBS_data.bam

No tool produces the exact same stats that you'd get when running the aligner (the output looks to be generated by bowtie )

But there are alternative tools designed to produce stats, for example bamstats

https://github.com/guigolab/bamstats

an output could look like this:

{
    "general": {
        "protocol": "SingleEnd",
        "reads": {
            "total": 101567,
            "unmapped": 7119,
            "mapped": {
                "0": 94448
            },
            "mappings": {
                "ratio": 1,
                "count": 94448
            }
        },
        "pairs": {}
    }
}

Log in to answer this question.