Commit 881b28a1 authored by Li's avatar Li
Browse files

Fix an issue of unsigned underflow issue in binary search.

parent d5bdd97c
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -610,7 +610,7 @@ void Chromap<MappingRecord>::MapPairedEndReads() {
          for (uint32_t pair_index = 0; pair_index < num_loaded_pairs; ++pair_index) {
            read_batch1.PrepareNegativeSequenceAt(pair_index);
            read_batch2.PrepareNegativeSequenceAt(pair_index);
            //std::cerr << read_batch1.GetSequenceNameAt(pair_index);
            //std::cerr << read_batch1.GetSequenceNameAt(pair_index)<<"\n";
            if (trim_adapters_) {
              TrimAdapterForPairedEndRead(pair_index, &read_batch1, &read_batch2);
            }
@@ -654,7 +654,6 @@ void Chromap<MappingRecord>::MapPairedEndReads() {
                mm_history2[pair_index].negative_candidates = negative_candidates2;
                mm_history2[pair_index].repetitive_seed_length = repetitive_seed_length2;
              }
		
              if (current_num_candidates1 + current_num_candidates2 == 1) {
	          if (current_num_candidates1 == 1) {
	             positive_hits2.clear();
@@ -667,13 +666,13 @@ void Chromap<MappingRecord>::MapPairedEndReads() {
		     repetitive_seed_length1 = 0;
		  }
		  if (positive_candidates1.size() == 1) 
		  	index.GenerateCandidatesFromRepetiveReadWithMateInfo(error_threshold_, minimizers2, &repetitive_seed_length2, &negative_hits2, &negative_candidates2, &positive_candidates1, -1, 2 * max_insert_size_) ;
		  	index.GenerateCandidatesFromRepetitiveReadWithMateInfo(error_threshold_, minimizers2, &repetitive_seed_length2, &negative_hits2, &negative_candidates2, &positive_candidates1, -1, 2 * max_insert_size_) ;
	          else if (negative_candidates1.size() == 1)
		  	index.GenerateCandidatesFromRepetiveReadWithMateInfo(error_threshold_, minimizers2, &repetitive_seed_length2, &positive_hits2, &positive_candidates2, &negative_candidates1, 1, 2 * max_insert_size_) ;
		  	index.GenerateCandidatesFromRepetitiveReadWithMateInfo(error_threshold_, minimizers2, &repetitive_seed_length2, &positive_hits2, &positive_candidates2, &negative_candidates1, 1, 2 * max_insert_size_) ;
		  else if (positive_candidates2.size() == 1) 
		  	index.GenerateCandidatesFromRepetiveReadWithMateInfo(error_threshold_, minimizers1, &repetitive_seed_length1, &negative_hits1, &negative_candidates1, &positive_candidates2, -1, 2 * max_insert_size_) ;
		  	index.GenerateCandidatesFromRepetitiveReadWithMateInfo(error_threshold_, minimizers1, &repetitive_seed_length1, &negative_hits1, &negative_candidates1, &positive_candidates2, -1, 2 * max_insert_size_) ;
	          else if (negative_candidates2.size() == 1)
		  	index.GenerateCandidatesFromRepetiveReadWithMateInfo(error_threshold_, minimizers1, &repetitive_seed_length1, &positive_hits1, &positive_candidates1, &negative_candidates2, 1, 2 * max_insert_size_) ;
		  	index.GenerateCandidatesFromRepetitiveReadWithMateInfo(error_threshold_, minimizers1, &repetitive_seed_length1, &positive_hits1, &positive_candidates1, &negative_candidates2, 1, 2 * max_insert_size_) ;
		  current_num_candidates1 = positive_candidates1.size() + negative_candidates1.size();
		  current_num_candidates2 = positive_candidates2.size() + negative_candidates2.size();
	      }
+4 −4
Original line number Diff line number Diff line
@@ -354,7 +354,7 @@ void Index::CollectCandidates(int max_seed_frequency, const std::vector<std::pai
  }
}

void Index::GenerateCandidatesFromRepetiveReadWithMateInfo(int error_threshold, const std::vector<std::pair<uint64_t, uint64_t> > &minimizers, uint32_t *repetitive_seed_length, std::vector<uint64_t> *hits, std::vector<Candidate> *candidates, std::vector<Candidate> *mate_candidates, int direction, unsigned int range) // directoin: +1: positive; -1: negative
void Index::GenerateCandidatesFromRepetitiveReadWithMateInfo(int error_threshold, const std::vector<std::pair<uint64_t, uint64_t> > &minimizers, uint32_t *repetitive_seed_length, std::vector<uint64_t> *hits, std::vector<Candidate> *candidates, std::vector<Candidate> *mate_candidates, int direction, unsigned int range) // directoin: +1: positive; -1: negative
{
  uint32_t num_minimizers = minimizers.size();
  hits->reserve(max_seed_frequencies_[0]);
@@ -389,8 +389,8 @@ void Index::GenerateCandidatesFromRepetiveReadWithMateInfo(int error_threshold,
      uint32_t offset = value >> 32;
      uint32_t num_occurrences = value;
      // use binary search to locate the coordinate near mate position
      uint32_t l = 0, m = 0, r = num_occurrences - 1;
      uint64_t boundary = (mate_candidates->at(0).position < range) ? 0 : mate_candidates->at(0).position - range ;
      int32_t l = 0, m = 0, r = num_occurrences - 1;
      uint64_t boundary = (mate_candidates->at(0).position < range) ? 0 : (mate_candidates->at(0).position - range) ;
      while (l <= r) {
        m = (l + r) / 2;
        uint64_t value = (occurrence_table_[offset + m])>>1;
+1 −1
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ class Index {
  void Load();
  void GenerateCandidatesOnOneDirection(int error_threshold, std::vector<uint64_t> *hits, std::vector<Candidate> *candidates);
  void GenerateCandidates(int error_threshold, const std::vector<std::pair<uint64_t, uint64_t> > &minimizers, uint32_t *repetitive_seed_length, std::vector<uint64_t> *positive_hits, std::vector<uint64_t> *negative_hits, std::vector<Candidate> *positive_candidates, std::vector<Candidate> *negative_candidates);
  void GenerateCandidatesFromRepetiveReadWithMateInfo(int error_threshold, const std::vector<std::pair<uint64_t, uint64_t> > &minimizers, uint32_t *repetitive_seed_length, std::vector<uint64_t> *hits, std::vector<Candidate> *candidates, std::vector<Candidate> *mate_candidates, int direction, unsigned int range);
  void GenerateCandidatesFromRepetitiveReadWithMateInfo(int error_threshold, const std::vector<std::pair<uint64_t, uint64_t> > &minimizers, uint32_t *repetitive_seed_length, std::vector<uint64_t> *hits, std::vector<Candidate> *candidates, std::vector<Candidate> *mate_candidates, int direction, unsigned int range);
  void CollectCandidates(int max_seed_frequency, const std::vector<std::pair<uint64_t, uint64_t> > &minimizers, uint32_t *repetitive_seed_length, std::vector<uint64_t> *positive_hits, std::vector<uint64_t> *negative_hits);
  inline static uint64_t Hash64(uint64_t key, const uint64_t mask) {
    key = (~key + (key << 21)) & mask; // key = (key << 21) - key - 1;