<p>Bam files contain a MAPQ field that informs on whether an alignment is unique or not. With STAR, a MAPQ value of 255 means the read is mapped uniquely and a score lower than 255 means not unique.</p>
<p>You can use samtools on a bam file to count or output the uniquely or multimapped reads by filtering for the MAPQ as described here: <a href="https://groups.google.com/forum/#!topic/rna-star/ipHc9FrgaPU" rel="nofollow noreferrer">https://groups.google.com/forum/#!topic/rna-star/ipHc9FrgaPU</a></p>
<p>For example, count uniquely mapped reads:
<code>samtools view -c -q 255 myBamFile.bam</code><br />
Output uniquely mapped reads:
<code>samtools view -q 255 myBamFile.bam</code></p>
<p>There are differences between STAR and BWA MAPQ output though. see here for details: <a href="https://sequencing.qcfail.com/articles/mapq-values-are-really-useful-but-their-implementation-is-a-mess/" rel="nofollow noreferrer">https://sequencing.qcfail.com/articles/mapq-values-are-really-useful-but-their-implementation-is-a-mess/</a></p>

CC BY-SA 4.0
2022-02-20T03:03:23.467Z
2022-02-20T03:14:18.773Z
2022-02-20T03:14:18.773Z
Robert ietswaart
<p>I want to find and compare the results from STAR and BWA- MEM mapped. I have 150bp paired end reads in sorted.bam files in each case and i want to find in each case uniquely mapped reads, number of reads mapped to multiple loci and number of unmappped reads.</p>
<p>Especially for uniquely mapped reads i tried different solutions from biostars and this <a href="https://bioinformatics.stackexchange.com/questions/508/obtaining-uniquely-mapped-reads-from-bwa-mem-alignment">Obtaining uniquely mapped reads from BWA mem alignment</a> but i dont know what to trust,</p>
<p>Could you please suggest the best way to find mapping results from bam paired end files ?</p>

CC BY-SA 4.0
2022-02-14T14:22:29.687Z
Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
Community
CC BY-SA 4.0
2022-02-14T14:28:28.687Z
It would be helpful to describe the genome and a bit of project background regarding what you have already tried. Biostars is a different site to Stackexchange.
M__
CC BY-SA 4.0
2022-02-14T15:08:09.557Z
I have paired end mapped reads from human in sorted bam files and i want to find the unique mapped , the multimapped and the unmapped reads from BWA and from STAR. I already have the .bam files from each mapper. i Tried samtools flagstat and the solution above but i am not sure if this is correct especially for unique reads
user3683485
<linux><bwa><star>
Compare mapped reads from BWA -MEM and STAR from .bam files
# Compare mapped reads from BWA -MEM and STAR from .bam files

(Asked by: username_0 on 2022-02-14)

I want to find and compare the results from STAR and BWA- MEM mapped. I have 150bp paired end reads in sorted.bam files in each case and i want to find in each case uniquely mapped reads, number of reads mapped to multiple loci and number of unmappped reads.

Especially for uniquely mapped reads i tried different solutions from biostars and this [Obtaining uniquely mapped reads from BWA mem alignment](https://bioinformatics.stackexchange.com/questions/508/obtaining-uniquely-mapped-reads-from-bwa-mem-alignment) but i dont know what to trust,

Could you please suggest the best way to find mapping results from bam paired end files ?

**Tags:** linux, bwa, star
> **Comments:**
> **username_1**: Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.  
> **username_2**: It would be helpful to describe the genome and a bit of project background regarding what you have already tried. Biostars is a different site to Stackexchange.  
> **username_0**: I have paired end mapped reads from human in sorted bam files and i want to find the unique mapped , the multimapped and the unmapped reads from BWA and from STAR. I already have the .bam files from each mapper. i Tried samtools flagstat and the solution above but i am not sure if this is correct especially for unique reads  

---

## 1 answers

### Answer by username_3 on 2022-02-20. Score: 2

Bam files contain a MAPQ field that informs on whether an alignment is unique or not. With STAR, a MAPQ value of 255 means the read is mapped uniquely and a score lower than 255 means not unique.

You can use samtools on a bam file to count or output the uniquely or multimapped reads by filtering for the MAPQ as described here: <https://groups.google.com/forum/#!topic/rna-star/ipHc9FrgaPU>

For example, count uniquely mapped reads:
`samtools view -c -q 255 myBamFile.bam`  
Output uniquely mapped reads:
`samtools view -q 255 myBamFile.bam`

There are differences between STAR and BWA MAPQ output though. see here for details: <https://sequencing.qcfail.com/articles/mapq-values-are-really-useful-but-their-implementation-is-a-mess/>


---

