converting a bam to bed file
1
0
Entering edit mode
2.8 years ago
erl1977 ▴ 60

Hi all, I have a bam file that has many supplemental alignments within it (the XA tag). These are single-end reads that were mapped with a bwa all/samse pipeline. I'm trying to convert the bam file to a bed file in which each supplemental mapping is also printed out to the bed file as a unique line. So, for example, I have a file with a entry of:

SEQ_20  0       chr1    184669033       0       16M     *       0       0       AAAAAAAAAAAAACAT        IIIIIIIIIIIIIIII        XT:A:R  NM:i:0  X0:i:3274       XM:i:0  XO:i:0  XG:i:0  MD:Z:16 XA:Z:chr3,-59868032

I'm using bedtools bamtobed and get this:

chr1    184669032       184669048       SEQ_20  0       +

But, I'm trying to also have it print out the secondary alignment from the XA tag to get something like:

chr1    184669032       184669048       SEQ_20  0       +
chr3    59868032       59868048       SEQ_20  0       1

I can't seem to find a good way of doing this, and I haven't been able to find a program to do it.

Thanks

alignments bed bam supplemental • 1.7k views
ADD COMMENT
0
Entering edit mode
2.8 years ago

using bioalcidaejdk: http://lindenb.github.io/jvarkit/BioAlcidaeJdk.html

java -jar ${JVARKIT_DIST}/bioalcidaejdk.jar  -e 'stream().filter(R->!R.getReadUnmappedFlag()).forEach(R->{println(R.getContig()+"\t"+(R.getStart()-1)+"\t"+R.getEnd()+"\t"+R.getReadName()+"\t"+R.getMappingQuality()+"\t"+(R. getReadNegativeStrandFlag()?"-":"+"));for(SAMRecord R2: htsjdk.samtools.SAMUtils.getOtherCanonicalAlignments(R)){println(R2.getContig()+"\t"+(R2.getStart()-1)+"\t"+R2.getEnd()+"\t"+R2.getReadName()+"\t"+R2.getMappingQuality()+"\t"+(R2.getReadNegativeStrandFlag()?"-":"+"));} });' in.bam
ADD COMMENT
0
Entering edit mode

Thanks for this. I tried it, but it gives the same output as bedtools bamtobed. I'm going to try playing around with it, see if I can get it to work

ADD REPLY
0
Entering edit mode

Thanks for this. I tried it, but it gives the same output as bedtools bamtobed

I think it's because your bam uses the old XA attribute. (not 'SA')

https://samtools.github.io/hts-specs/SAMtags.pdf

SA Z Other canonical alignments in a chimeric alignment

ADD REPLY
0
Entering edit mode

I tried manually changing the XA tag to SA, but still didn't work. I'll try to figure something out manually or remap with another program. Thanks for your help

ADD REPLY

Login before adding your answer.

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