X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Ftoolkit%2Fbamtools_count.cpp;h=dfd1fa6bcfa7c42ff84702e224396296cbee76d8;hb=038f0e1dda24b2d6765cc8c878b7dbdc5f922ed6;hp=c17b25776df476a1317cef2218b8693202a27b47;hpb=86e92576cd16354f09f6cbda6e6784d2d71d9399;p=bamtools.git diff --git a/src/toolkit/bamtools_count.cpp b/src/toolkit/bamtools_count.cpp index c17b257..dfd1fa6 100644 --- a/src/toolkit/bamtools_count.cpp +++ b/src/toolkit/bamtools_count.cpp @@ -10,6 +10,7 @@ #include "bamtools_count.h" +#include #include #include #include @@ -62,6 +63,26 @@ struct CountTool::CountToolPrivate { CountTool::CountSettings* m_settings; }; +static +void printAlignments(const vector& alignments) { + + vector::const_iterator alIter = alignments.begin(); + vector::const_iterator alEnd = alignments.end(); + for ( ; alIter != alEnd; ++alIter ) { + const BamAlignment& a = (*alIter); + + cerr << a.Name + << "\t" << a.RefID << ":" << a.Position; + + int aqValue; + bool hasTag = a.GetTag("Aq", aqValue); + cerr << "\tAq="; + if ( hasTag ) cerr << aqValue; + else cerr << "?"; + cerr << endl; + } +} + bool CountTool::CountToolPrivate::Run(void) { // if no '-in' args supplied, default to stdin @@ -81,8 +102,70 @@ bool CountTool::CountToolPrivate::Run(void) { // if no region specified, count entire file if ( !m_settings->HasRegion ) { - while ( reader.GetNextAlignmentCore(al) ) + + + vector alignments; + while ( reader.GetNextAlignment(al) ) { ++alignmentCount; + + if ( alignments.size() < 100 ) + alignments.push_back(al); + } + + cerr << endl + << "------------------------------" << endl + << "Unsorted Alignments" << endl + << "------------------------------" << endl + << endl; + std::stable_sort(alignments.begin(), alignments.end(), Algorithms::Unsorted()); + printAlignments(alignments); + cerr << "------------------------------" << endl + << endl; + + cerr << endl + << "------------------------------" << endl + << "Sorted Alignments (by name)" << endl + << "------------------------------" << endl + << endl; + std::sort(alignments.begin(), alignments.end(), Algorithms::SortByName<>()); + printAlignments(alignments); + cerr << endl + << "------------------------------" << endl + << endl; + + cerr << endl + << "------------------------------" << endl + << "Sorted Alignments (by tag Aq)" << endl + << "------------------------------" << endl + << endl; + std::sort(alignments.begin(), alignments.end(), Algorithms::SortByTag("Aq")); + printAlignments(alignments); + cerr << endl + << "------------------------------" << endl + << endl; + + cerr << endl + << "------------------------------" << endl + << "Sorted Alignments (by tag Aq) desc" << endl + << "------------------------------" << endl + << endl; + std::sort(alignments.begin(), alignments.end(), Algorithms::SortByTag("Aq")); + printAlignments(alignments); + cerr << endl + << "------------------------------" << endl + << endl; + + + + +// // ######################################## +// // original +// // ######################################## +// +// while ( reader.GetNextAlignmentCore(al) ) +// ++alignmentCount; +// +// //######################################### } // otherwise attempt to use region as constraint @@ -98,16 +181,26 @@ bool CountTool::CountToolPrivate::Run(void) { // if index data available for all BAM files, we can use SetRegion if ( reader.IsIndexLoaded() ) { - // attempt to set region on reader - if ( !reader.SetRegion(region.LeftRefID, region.LeftPosition, region.RightRefID, region.RightPosition) ) { - cerr << "bamtools count ERROR: set region failed. Check that REGION describes a valid range" << endl; - reader.Close(); - return false; - } + vector alignments; + + alignments = Algorithms::SortReaderRegion(reader, region, Algorithms::SortByName<>() ); + printAlignments(alignments); + + cerr << "################################" << endl; + + alignments = Algorithms::SortReaderRegion(reader, region, Algorithms::SortByTag("Aq")); + printAlignments(alignments); + +// // attempt to set region on reader +// if ( !reader.SetRegion(region.LeftRefID, region.LeftPosition, region.RightRefID, region.RightPosition) ) { +// cerr << "bamtools count ERROR: set region failed. Check that REGION describes a valid range" << endl; +// reader.Close(); +// return false; +// } - // everything checks out, just iterate through specified region, counting alignments - while ( reader.GetNextAlignmentCore(al) ) - ++alignmentCount; +// // everything checks out, just iterate through specified region, counting alignments +// while ( reader.GetNextAlignmentCore(al) ) +// ++alignmentCount; } // no index data available, we have to iterate through until we