Merge Bam File Samtools By Chr End Start Instead Of Chr Start End
1
0
Entering edit mode
11.7 years ago
dfernan ▴ 760

Hi,

Is there any short way to merge a bam file using samtools or a tool alike to merge bam files by chr end start instead of chr start end?

Here is an example, regular samtools sort would do:

1 566293 566329 B0A02ABXX110608:3:2205:13569:150321 0 + 1 566293 566327 D0D8NACXX111121:2:1201:9085:119187 0 -

but it should be,

1 566293 566327 B0A02ABXX110608:3:2205:13569:150321 0 + 1 566293 566329 D0D8NACXX111121:2:1201:9085:119187 0 -

Any help would be greatly appreciated.

Thank you very much!

bam samtools • 1.8k views
ADD COMMENT
0
Entering edit mode

Is this a bam/sam format?

ADD REPLY
0
Entering edit mode

bam format. thanks.

ADD REPLY
0
Entering edit mode
11.7 years ago
matted 7.8k

Three ideas, depending on your goals and time requirements:

  • Reverse the sequences in your FASTQ files before alignment using e.g. fastx or seqtk.

  • Write a bit of code to effectively reverse the reads in your existing BAM files so that default samtools sort works as you'd like. It might be tricky to not break the alignment information that will be used downstream. If you don't need that, you could just overwrite the start coordinate with the end coordinate and then run samtools sort.

  • Hack samtools. From my quick reading, you need to change the comparator function bam1_lt in bam_sort.c. The code is pretty bit-twiddly, but I think you need to change a->core.pos to a->core.pos+a->core.l_qseq, and think about whether that handles strandedness correctly.

I'm curious about what you're trying to achieve though, since this modification (or at least the last one) will probably break downstream processing that assumes the original sort order (e.g. samtools mpileup).

ADD COMMENT
0
Entering edit mode

thanks a lot! It's just that I am running a software that takes as an input a bam file sorted that way so I was wondering if there was a quick solution to the problem, but it seems to be not that easy...

ADD REPLY

Login before adding your answer.

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