pezmaster31/bamtools — Issue #20: Cannot extract tags
Author: tobiasmarschall
Created: 2011-10-16 21:15:44+00:00
State: open

Hi,

I'm trying to extract tags from a BAM file:

```cpp
#include
#include

using namespace std;

int main() {
BamTools::BamReader bam_reader;
if (!bam_reader.Open("test.bam")) {
cerr << "Error opening BAM file" << endl;
return 1;
}
BamTools::BamAlignment read_aln;
while ( bam_reader.GetNextAlignment(read_aln) ) {
cout << "Current read: " << read_aln.Name << endl;
uint32_t x0;
if (read_aln.GetTag("X0", x0)) {
cout << "X0: " << x0 << endl;
}
string md;
if (read_aln.GetTag("MD", md)) {
cout << "MD: " << md << endl;
}
}
return 0;
}
```

The [BAM file](http://homepages.cwi.nl/~tm/files/test.bam "Sample BAM file") I've used for testing looks like this (after running through samtools view):

```
@SQ	SN:1	LN:249250621
@PG	ID:bwa	PN:bwa	VN:0.5.9-r16
EAS51:1:1:1121:15866	99	1	220659190	60	101M	=	220659392	303	GAAACCCCGCGTAATGAACAAGCTACTGAGAGCCCAGAGAGGTGCTCCTCCTCTCAGGCATGTTCAATCTTCAGGATTCAGAAATTGTTCTGAGTAGAAGT	EEEB=FFFDFFFFDF=C?BDEDEEBE=EDBBB:C=B:@?5B,@CAEE=BEEDBEE@-=D@:???@=?BBE@B@-5?BBBBB=:@DD@@@BB@?@@A@=5=@XT:A:U	NM:i:0	SM:i:37	AM:i:37	X0:i:1	X1:i:0	XM:i:0	XO:i:0	XG:i:0	MD:Z:101	AS:i:0
EAS51:1:1:1121:15866	147	1	220659392	60	101M	=	220659190	-303	CCAGGACAGGAAGGGCCTGTCCANCTTAATTTACAGGGCCATGCAGCAGAATAATCATGGGTCATTCTTTTAAAATGGGGCTTCCATGTTTCGAAAGGAAA	5?2@=?-@?B?9?@?72&-0)58#?>@DE@D?B5@BB5@BB5:-CB?B@BA@BBB=E=EBE?A>@55CEADAEEEEXT:A:U	NM:i:3	SM:i:37	AM:i:37	X0:i:1	X1:i:0	XM:i:3	XO:i:0	XG:i:0	MD:Z:2G15T4T77	AS:i:31
```

The output:

```
Current read: EAS51:1:1:1121:15866
Current read: EAS51:1:1:1121:15866
```

That is, no tags have been found and printed. Am I doing something wrong or is this bug?

Regards,
Tobias