This is a test version of Biostars. For the public version, visit https://www.biostars.org.
converting a bam to bed file

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 answer

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

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

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

Log in to answer this question.