This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Increase the fifth column ( MAPQ) value in Sam file

Hi,

I have a sam file and I want to increase the value present in the fifth column of the sam file ( MAPQ). This is done to test the BBMap application. Kindly help.

Thanks

sam mapq sequencing alignment

1 answer

Hi madhu.9124,

Such tasks are typically done using awk or perl. Here's one solution: cat alignment.sam | awk -v OFS='\t' '$5 += 7'

This will increase MAPQ (field 5) by 7.

thanks you, it works but after incrementing the values, I want to save the changes to the same same file.

You can use awk -i inplace -v OFS='\t' '$5 += 7' alignment.sam, but it's good practice to keep your original files.

This is what I would do:

cat alignment.sam | awk -v OFS='\t' '$5 += 7' > alignment_mapqincreasedbyseven.sam

Just a couple of things... You should print the sam header as it is, without incrementing the 5th column. I.e. with something like if($0 ~ "^@") {print $0} else {...}. Also you should check that incrementing the MAPQ doesn't make it out of bound, i.e. no more than 254 (255 meaning not available).

Good points! andthisistextfulfillsthesmartcharacterrequirement

thanks a lot, it works.

Log in to answer this question.