42
42
#include < utility> // std::swap
43
43
#include < vector>
44
44
45
- using std::cerr;
46
- using std::endl;
47
- using std::max;
48
45
using std::min;
49
46
using std::mt19937;
50
47
using std::priority_queue;
@@ -520,6 +517,13 @@ load_coverage_counts_GR(const string &input_file_name, const uint64_t seed,
520
517
#ifdef HAVE_HTSLIB
521
518
// Deal with SAM/BAM format only if we have htslib
522
519
520
+ static inline void
521
+ reset_bam_rec (bamxx::bam_rec &b) {
522
+ if (b.b )
523
+ bam_destroy1 (b.b );
524
+ b.b = nullptr ;
525
+ }
526
+
523
527
static inline bool
524
528
not_mapped (const bamxx::bam_rec &aln) {
525
529
return get_tid (aln) == -1 ;
@@ -540,6 +544,9 @@ struct aln_pos {
540
544
bool operator <(const aln_pos &rhs) const {
541
545
return tid < rhs.tid || (tid == rhs.tid && pos < rhs.pos );
542
546
}
547
+ bool operator >(const aln_pos &rhs) const {
548
+ return tid > rhs.tid || (tid == rhs.tid && pos > rhs.pos );
549
+ }
543
550
bool operator !=(const aln_pos &rhs) const {
544
551
// ADS: ordered to check pos first
545
552
return pos != rhs.pos || tid != rhs.tid ;
@@ -704,8 +711,8 @@ split_genomic_interval(const genomic_interval &gi, mt19937 &generator,
704
711
705
712
template <class T , class U >
706
713
static inline bool
707
- can_pop (const T &pq, const U &u , const hts_pos_t max_dist) {
708
- return pq.top ().tid != u .tid || pq.top ().pos + max_dist < u .pos ;
714
+ can_pop (const T &pq, const U &last , const hts_pos_t max_dist) {
715
+ return pq.top ().tid != last .tid || pq.top ().pos + max_dist < last .pos ;
709
716
}
710
717
711
718
template <class T >
@@ -757,7 +764,7 @@ load_coverage_counts_BAM(const uint32_t n_threads, const string &inputfile,
757
764
size_t current_count = 1 ;
758
765
759
766
// initialize prioirty queue to reorder the split reads
760
- priority_queue<aln_pos> pq;
767
+ priority_queue<aln_pos, vector<aln_pos>, std::greater<aln_pos> > pq;
761
768
vector<aln_pos> parts; // reuse allocated space
762
769
aln_pos prev_part;
763
770
genomic_interval prev;
@@ -787,7 +794,7 @@ load_coverage_counts_BAM(const uint32_t n_threads, const string &inputfile,
787
794
788
795
// add split intervals to the priority queue
789
796
const auto last = parts.back (); // keep a copy for test below
790
- for (auto & &i : parts)
797
+ for (const auto &i : parts)
791
798
pq.push (i);
792
799
793
800
// remove genomic interval parts from the priority queue
@@ -798,6 +805,7 @@ load_coverage_counts_BAM(const uint32_t n_threads, const string &inputfile,
798
805
update_coverage_hist (curr_part, prev_part, coverage_hist, current_count);
799
806
prev_part = curr_part;
800
807
}
808
+ reset_bam_rec (aln);
801
809
prev = curr;
802
810
++n_reads;
803
811
}
0 commit comments