- writer->Open(outputFilenameStream.str(), m_header, m_references);
- writer->SaveAlignment(al);
-
- // store in map
- outputFiles.insert( make_pair(currentValue, writer) );
-
- // reset stream
- outputFilenameStream.str("");
- } else ++alignmentsIgnored;
-
- // iterate through remaining alignments
- while ( m_reader.GetNextAlignment(al) ) {
-
- // skip if this alignment doesn't have TAG
- if ( !al.GetTag(tag, currentValue) ) { ++alignmentsIgnored; continue; }
-
- // look up tag value in map
- writerIter = outputFiles.find(currentValue);
-
- // if no writer associated with this value
- if ( writerIter == outputFiles.end() ) {
-
- // open new BamWriter
- writer = new BamWriter;
- outputFilenameStream << m_outputFilenameStub << ".TAG_" << tag << "_" << currentValue << ".bam";
- writer->Open(outputFilenameStream.str(), m_header, m_references);
-
- // store in map
- outputFiles.insert( make_pair(currentValue, writer) );
-
- // reset stream
- outputFilenameStream.str("");
- }
-
- // else grab corresponding writer
- else writer = (*writerIter).second;
-
- // store alignment in proper BAM output file
- if ( writer )
- writer->SaveAlignment(al);
- }
-
- // clean up BamWriters
- map<uint32_t, BamWriter*>::iterator writerEnd = outputFiles.end();
- for ( writerIter = outputFiles.begin(); writerIter != writerEnd; ++writerIter ) {
- BamWriter* writer = (*writerIter).second;
- if (writer == 0 ) continue;
- writer->Close();
- delete writer;
- writer = 0;
- }
-
- // return success
- return true;
-}
-
-bool SplitTool::SplitToolPrivate::SplitTag_Real(BamAlignment& al) {
-
- // set up splitting data structure
- map<float, BamWriter*> outputFiles;
- map<float, BamWriter*>::iterator writerIter;
-
- // local variables
- const string tag = m_settings->TagToSplit;
- BamWriter* writer;
- stringstream outputFilenameStream("");
- float currentValue;
-
- // retrieve first alignment tag value
- if ( al.GetTag(tag, currentValue) ) {
-
- // open new BamWriter, save first alignment