11 #ifndef ALGORITHMS_SORT_H
12 #define ALGORITHMS_SORT_H
25 namespace Algorithms {
42 template<
typename ElemType>
43 static inline bool sort_helper(
const Sort::Order& order,
const ElemType& lhs,
const ElemType& rhs) {
47 default : BT_ASSERT_UNREACHABLE;
53 typedef std::binary_function<BamAlignment, BamAlignment, bool> AlignmentSortBase;
71 struct ByName :
public AlignmentSortBase {
80 return sort_helper(m_order, lhs.
Name, rhs.
Name);
84 static inline bool UsesCharData(
void) {
return true; }
118 if ( lhs.
RefID == -1 )
return false;
119 if ( rhs.
RefID == -1 )
return true;
126 return sort_helper(m_order, lhs.
RefID, rhs.
RefID);
130 static inline bool UsesCharData(
void) {
return false; }
154 struct ByTag :
public AlignmentSortBase {
169 if ( !lhs.
GetTag(m_tag, lhsTagValue) )
return false;
170 if ( !rhs.
GetTag(m_tag, rhsTagValue) )
return true;
173 return sort_helper(m_order, lhsTagValue, rhsTagValue);
177 static inline bool UsesCharData(
void) {
return true; }
181 const std::string m_tag;
204 static inline bool UsesCharData(
void) {
return false; }
220 template<
typename Compare>
222 const Compare& comp = Compare())
224 std::sort(data.begin(), data.end(), comp);
242 template<
typename Compare>
243 static inline std::vector<BamAlignment>
SortAlignments(
const std::vector<BamAlignment>& input,
244 const Compare& comp = Compare())
246 std::vector<BamAlignment> output(input);
247 SortAlignments(output, comp);
271 template<
typename Compare>
274 const Compare& comp = Compare())
277 if ( !reader.
IsOpen() )
return std::vector<BamAlignment>();
278 if ( !reader.
SetRegion(region) )
return std::vector<BamAlignment>();
282 std::vector<BamAlignment> results;
284 results.push_back(al);
287 SortAlignments(results, comp);
311 template<
typename Compare>
314 const Compare& comp = Compare())
317 if ( !reader.
HasOpenReaders() )
return std::vector<BamAlignment>();
318 if ( !reader.
SetRegion(region) )
return std::vector<BamAlignment>();
322 std::vector<BamAlignment> results;
324 results.push_back(al);
327 SortAlignments(results, comp);
335 #endif // ALGORITHMS_SORT_H
#define API_EXPORT
Definition: api_global.h:18