Using samtools to read a bam file
1
0
Entering edit mode
2.5 years ago
Caitlin ▴ 100

Hi all.

I am trying to extract some information (please see below) from a bam file using samtools. Given my lack of experience, I am struggling.

1.) Total reads aligned on the forward strand 2.) Total reads aligned on the reverse strand 3.) Number of read pairs where the pairs are pointing towards each other 4.) Number of read pairs where the pairs pointing in the same direction (this is the opposite of proper pairs) 5.) Number of primary alignments (not SECONDARY) that are on the forward strand

Any help would be greatly appreciated.

Thank you.

bioimformatics samtools bam • 2.3k views
ADD COMMENT
2
Entering edit mode

You can use the samtools stats command to extract some of this information (version samtools-1.13). More information about this command can be found on the manual page. Hope this helps!

ADD REPLY
0
Entering edit mode

Thank you Chris. Unfortunately, the only version of samtools I have access to is version 1.9 I ran samtools stats on the bam file, but I could not locate any of the information I needed.

ADD REPLY
1
Entering edit mode

Interesting, I just ran samtools (v1.9) on a BAM file and I do see some of this information. For example, are the 1st fragments, last fragments, and inward oriented pairs counts not what you are looking for? These outputs can be found in the SN section of the output.

ADD REPLY
0
Entering edit mode

Thanks Chris. I'll look again.

1st fragments = Total reads aligned on the forward strand last fragments = Total reads aligned on the reverse strand inward oriented pairs = Number of read pairs where the pairs are pointing towards each other

??

I was able to upgrade samtools to 1.12.0 which should, hopefully, be of some use.

ADD REPLY
0
Entering edit mode

Yes exactly.

ADD REPLY
0
Entering edit mode

Is there a field for the last two questions? Number of read pairs where the pairs pointing in the same direction (this is the opposite of proper pairs) and Number of primary alignments (not SECONDARY) that are on the forward strand?

ADD REPLY
0
Entering edit mode

Hi Chris.

I thought I would include the link to the file I am using.

http://data.biostarhandbook.com/bam/demo.bam

Does this help? If you could run the command and compare answers with me that would be ideal.

Thank you Chris.

ADD REPLY
1
Entering edit mode
2.5 years ago

Why don't the binary flags give you exactly this information?

ADD COMMENT
0
Entering edit mode

The flag field only distinguishes "properly paired" or not. The definition of that is up to the aligner.

It's not even that obvious either. Some old mate pair libraries has large inserts with reads pointing away from each other, where the enrichment for circularised templates worked, or short inserts with the pairs pointing towards one another (where the enrichment failed). Both can be mapped in a consistent manner. I doubt any aligners coped in setting "properly paired" for both portions though!

ADD REPLY
0
Entering edit mode

The direction fields should work, even if for some reason the properly paired designation is wrong. And why should it be wrong for huge numbers of reads? OP hasn't indicated that he is doing anything exotic.

ADD REPLY
0
Entering edit mode

Hi.

If you're referring to me, I'm a female.

ADD REPLY

Login before adding your answer.

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