11#ifndef ALGORITHMS_SORT_H
12#define ALGORITHMS_SORT_H
45 template <
typename ElemType>
46 static bool sort_helper(
const Sort::Order& order,
const ElemType& lhs,
const ElemType& rhs)
50 std::less<ElemType> comp;
51 return comp(lhs, rhs);
54 std::greater<ElemType> comp;
55 return comp(lhs, rhs);
58 BT_ASSERT_UNREACHABLE;
64 typedef std::binary_function<BamAlignment, BamAlignment, bool> AlignmentSortBase;
82 struct ByName :
public AlignmentSortBase
93 return sort_helper(m_order, lhs.
Name, rhs.
Name);
97 static bool UsesCharData()
136 if (lhs.
RefID == -1) {
139 if (rhs.
RefID == -1) {
149 return sort_helper(m_order, lhs.
RefID, rhs.
RefID);
153 static bool UsesCharData()
179 template <
typename T>
180 struct ByTag :
public AlignmentSortBase
196 if (!lhs.
GetTag(m_tag, lhsTagValue)) {
199 if (!rhs.
GetTag(m_tag, rhsTagValue)) {
204 return sort_helper(m_order, lhsTagValue, rhsTagValue);
208 static bool UsesCharData()
215 const std::string m_tag;
240 static bool UsesCharData()
259 template <
typename Compare>
260 static void SortAlignments(std::vector<BamAlignment>& data,
const Compare& comp = Compare())
262 std::sort(data.begin(), data.end(), comp);
280 template <
typename Compare>
281 static std::vector<BamAlignment>
SortAlignments(
const std::vector<BamAlignment>& input,
282 const Compare& comp = Compare())
284 std::vector<BamAlignment> output(input);
285 SortAlignments(output, comp);
309 template <
typename Compare>
311 const Compare& comp = Compare())
315 return std::vector<BamAlignment>();
318 return std::vector<BamAlignment>();
323 std::vector<BamAlignment> results;
325 results.push_back(al);
329 SortAlignments(results, comp);
353 template <
typename Compare>
356 const Compare& comp = Compare())
360 return std::vector<BamAlignment>();
363 return std::vector<BamAlignment>();
368 std::vector<BamAlignment> results;
370 results.push_back(al);
374 SortAlignments(results, comp);