Increase the fifth column ( MAPQ) value in Sam file
1
0
Entering edit mode
7.4 years ago
madhu.9124 ▴ 60

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 • 2.6k views
ADD COMMENT
1
Entering edit mode
7.4 years ago
novice ★ 1.1k

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.

ADD COMMENT
0
Entering edit mode

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

ADD REPLY
1
Entering edit mode

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

ADD REPLY
1
Entering edit mode

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).

ADD REPLY
0
Entering edit mode

Good points! andthisistextfulfillsthesmartcharacterrequirement

ADD REPLY
0
Entering edit mode

thanks a lot, it works.

ADD REPLY

Login before adding your answer.

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