This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How can I drop the MAPQ info of my sam/bam file?

For example, the first alignment in my SAM file currently looks like

08b20551-b31c-4170-a04c-40a34ee8b71f    0   chr20   4699371 60  272H123M637H    *   0   0   CCTCAGGGCGGTGGTGGCTGGGGGCAGCCTCATGGTGGTGGCTGGGGGCAGCCTCATGGTGGTGGCTGGGGGCAGCCCCATGGTGGTGGCTGGGGACAGCCTCATGGTGGTGGCTGGGGTCAA &'$'()+2220/,+.203:=?65<?BDDCF:B@>69;AF?FLA=?CB>=83/0-@@?=>@A52.;AA@CGA45=DFHG@?A?;<9A:A>=:=8<=@=B56B:@@BCHFHG?4@<::=98=:79 ms:i:1920   AS:i:1920   nn:i:0  tp:A:P  cm:i:158    s1:i:929    s2:i:0  de:f:0.0148 rl:i:0  HP:i:2  PC:i:30 PS:i:4688888

I would like to delete the MAPQ (aka qual) component. Expected:

08b20551-b31c-4170-a04c-40a34ee8b71f    0   chr20   4699371 60  272H123M637H    *   0   0   CCTCAGGGCGGTGGTGGCTGGGGGCAGCCTCATGGTGGTGGCTGGGGGCAGCCTCATGGTGGTGGCTGGGGGCAGCCCCATGGTGGTGGCTGGGGACAGCCTCATGGTGGTGGCTGGGGTCAA ms:i:1920   AS:i:1920   nn:i:0  tp:A:P  cm:i:158    s1:i:929    s2:i:0  de:f:0.0148 rl:i:0  HP:i:2  PC:i:30 PS:i:4688888

How may I do this?

bam

drop the MAPQ info

You will break SAM format if you do that. Why not ignore it if you are not interested in it? Or did you mean to replace the current value?

Ah, I see. A batch of my samples has * for the MAPQ field, but this file has the full MAPQ info. I need to have the formats to match for downstream analysis.

So yes, replacing with * would work. Even better, actually.

How can I do that?

. MAPQ: MAPping Quality. It equals −10 log10 Pr{mapping position is wrong}, rounded to the nearest integer. A value 255 indicates that the mapping quality is not available.

You have 60 in your example above for MAPQ field number 5. * is for RNEXT field.

See SAM format spec.

1 answer

Looks like you don't want to replace the mapping quality (MAPQ), but the base call quality (QUAL) instead. Mapping quality is 60 in your example.

Ah you're right, my bad!

I found a suitable solution:

cat in.sam | awk -v OFS='\t' '$11="*"' > out.sam

Not particularly elegant because it affects the header lines as well, but good enough for what I am currently doing...

Log in to answer this question.