How to extract all - strand mapped reads location of reference genome using BAM file?
0
0
Entering edit mode
7.7 years ago
BioGeek ▴ 170

How to extract all - strand mapped reads location of reference genome using BAM file and save in a tab file?

BAM SAM NGS Reads • 2.6k views
ADD COMMENT
0
Entering edit mode

What exactly would you like in the "tab" file? The answer to this, btw, is to write a little script with pysam (or perhaps jvarkit).

ADD REPLY
0
Entering edit mode

Can you please give me some hints, to achieve it. I want to print the followings Scaffold \tStart \tEnd \tStrand

ADD REPLY
0
Entering edit mode

Something along the following lines is a start for you:

#!/usr/bin/env python
import sys
import pysam

bam = pysam.AlignmentFile(sys.argv[1])
output = open("output.tab", "w")
for read in bam.fetch():
    # Do whatever filtering you want
    # ...
    if not read.is_reverse:
        continue
    output.write("{}\t{}\t{}\t-\n".format(bam.get_reference_name(read.get_tid()), read.pos, read.reference_end()))
output.close()
bam.close()
ADD REPLY

Login before adding your answer.

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