[Seqan-dev] appendTagValue() for BamTagsDict
Hi everyone,
I am currently trying to write out Bam files using seqan's BamFileOut. I stumbled across some strange behavior of appendTagValue()
When using the function three times in a row, length(tags) returns 2, which seems one to less to me. I enclosed a code example using the example from
http://docs.seqan.de/seqan/2.0.0/demos/bam_io/bam_tags_dict.cpp
I marked my changes. Did I miss something?
Furthermore, I wondered whether there is a function, which converts a BamTagsDict into a String, which I can directly use as an Entry in a Sam file.
Best Regards,
Jakob
PS: Output of the code snippet on my machine is:
3
AA -> "value1"
AB -> "value2"
AC -> 30
2
#include <iostream>
#include <seqan/stream.h>
#include <seqan/bam_io.h>
using namespace seqan;
int main()
{
CharString bamStr, samStr = "AA:Z:value1\tAB:Z:value2\tAC:i:30";
assignTagsSamToBam(bamStr, samStr);
BamTagsDict tags(bamStr);
BamTagsDict newTags; // NEW: added by Jakob Schulze
std::cout << length(tags) << std::endl; // #=> "3"
for (unsigned id = 0; id < length(tags); ++id)
{
std::cout << getTagKey(tags, id) << " -> ";
if (getTagType(tags, id) == 'i') // is 32 bit integer
{
__int32 x = 0;
bool res = extractTagValue(x, tags, id);
SEQAN_ASSERT_MSG(res, "Not a valid integer at pos %u!", id);
std::cout << x;
appendTagValue(newTags, getTagKey(tags, id), x); // NEW: added by Jakob Schulze
}
if (getTagType(tags, id) == 'Z') // is string
{
CharString str;
bool res = extractTagValue(str, tags, id);
SEQAN_ASSERT_MSG(res, "Not a valid string at pos %u!", id);
std::cout << '"' << str << '"';
appendTagValue(newTags, getTagKey(tags, id), str); // NEW: added by Jakob Schulze
}
std::cout << std::endl;
}
std::cout << length(newTags) << std::endl; // NEW: added by Jakob Schulze
return 0;
}