RNAME changes to UNMAPPED when writing to BAM instead of SAM

13 views
Skip to first unread message

Will Rowe

unread,
Nov 24, 2017, 5:09:28 AM11/24/17
to biogo-user
Hi there,

I have a program that is writing alignments to a SAM file fine. The records pass the IsValidRecord func and the resulting SAM file is valid (according to BamUtil). My problem is that when I change from using the SAM writer to the BAM writer, the RNAME field of each record changes to unmapped (*). The rest of each record remains unchanged.

Sorry if I'm missing something obvious but I can't work out why it is doing this and would appreciate some guidance.

Cheers,

Will

Dan Kortschak

unread,
Nov 24, 2017, 3:20:11 PM11/24/17
to Will Rowe, biogo-user
Can you post a minimal reproducer (with a minimal data set that I can
investigate)?

Dan

Will Rowe

unread,
Nov 24, 2017, 4:44:15 PM11/24/17
to biogo-user
My code is sending alignments over a channel to a function that is writing the SAM/BAM file. I've attached one example that uses SAM writer and one the uses BAM writer.

The output of the SAM version:
go run sam-write.go | samtools view -h
@SQ SN:testReference LN:100
testRead 0 testReference 2 30 4M * 1 4 ACTG LLLL

The output of the BAM version:
go run bam-write.go | samtools view -h
@SQ SN:testReference LN:100
testRead 0 * 2 30 4M * 1 4 ACTG LLLL

I'm fairly new to Go, hopefully this is the information you will need? Thank you for your help.

Will
sam-write.go
bam-write.go

Dan Kortschak

unread,
Nov 24, 2017, 5:55:55 PM11/24/17
to Will Rowe, biogo-user
It's not clear to me what you are trying to do here with the chan, it
really isn't necessary (the Writers are non-blocking within reason).

However, the cause of the problem is that you are treating the
reference as a text object, and this is not consistent with how BAM
work. The sam.Record holds a pointer to the sam.Reference. You create a
bam.Writer that knows about the reference created in the main func, but
then create another sam.Reference in Align - these have the same
characteristics, but are not the same reference.

I suspect that if this were written more naturally, you would not have
made this mistake.

Dan

Will Rowe

unread,
Nov 25, 2017, 2:58:13 AM11/25/17
to biogo-user
Thanks for the explanation - I understand now. Thanks again for taking the time to help me out.

Will
Reply all
Reply to author
Forward
0 new messages