Commit 32ae269d authored by Haowen Zhang's avatar Haowen Zhang Committed by Li Song
Browse files

Make static functions free.

parent b2952bf0
Loading
Loading
Loading
Loading
+56 −63
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
#include "cxxopts.hpp"
#include "ksw.h"
#include "mmcache.hpp"
#include "utils.h"

namespace chromap {
template <typename MappingRecord>
@@ -394,8 +395,7 @@ uint32_t Chromap<PairedEndMappingWithBarcode>::CallPeaks(
      }
    }
  }
  std::cerr << "Built pileup in " << Chromap<>::GetRealTime() - real_start_time
            << "s.\n";
  std::cerr << "Built pileup in " << GetRealTime() - real_start_time << "s.\n";
  real_start_time = GetRealTime();
  // Call and save peaks
  tree_extras_on_diff_ref_seqs_.clear();
@@ -430,7 +430,7 @@ uint32_t Chromap<PairedEndMappingWithBarcode>::CallPeaks(
    BuildAugmentedTreeForPeaks(ri);
  }
  std::cerr << "Call peaks and built peak augmented tree in "
            << Chromap<>::GetRealTime() - real_start_time << "s.\n";
            << GetRealTime() - real_start_time << "s.\n";
  // Output feature matrix
  return peak_count;
}
@@ -482,7 +482,7 @@ void Chromap<PairedEndMappingWithBarcode>::OutputFeatureMatrix(
    }
  }
  std::cerr << "Index and output barcodes in "
            << Chromap<>::GetRealTime() - real_start_time << "s.\n";
            << GetRealTime() - real_start_time << "s.\n";
  real_start_time = GetRealTime();
  // Second pass to generate matrix
  khash_t(kmatrix) *matrix = kh_init(kmatrix);
@@ -520,8 +520,8 @@ void Chromap<PairedEndMappingWithBarcode>::OutputFeatureMatrix(
      }
    }
  }
  std::cerr << "Generate feature matrix in "
            << Chromap<>::GetRealTime() - real_start_time << "s.\n";
  std::cerr << "Generate feature matrix in " << GetRealTime() - real_start_time
            << "s.\n";
  // Output matrix
  real_start_time = GetRealTime();
  feature_barcode_matrix_writer_.WriteMatrixOutputHead(
@@ -541,8 +541,8 @@ void Chromap<PairedEndMappingWithBarcode>::OutputFeatureMatrix(
        (uint32_t)feature_matrix[i].first,
        (uint32_t)(feature_matrix[i].first >> 32), feature_matrix[i].second);
  }
  std::cerr << "Output feature matrix in "
            << Chromap<>::GetRealTime() - real_start_time << "s.\n";
  std::cerr << "Output feature matrix in " << GetRealTime() - real_start_time
            << "s.\n";
}

template <typename MappingRecord>
@@ -711,7 +711,7 @@ uint32_t Chromap<MappingRecord>::LoadPairedEndReadsWithBarcodes(
    } else if (no_more_read1 && no_more_read2 && no_more_barcode) {
      break;
    } else {
      Chromap<>::ExitWithMessage("Numbers of reads and barcodes don't match!");
      ExitWithMessage("Numbers of reads and barcodes don't match!");
    }
    ++num_loaded_pairs;
  }
@@ -727,7 +727,7 @@ uint32_t Chromap<MappingRecord>::LoadPairedEndReadsWithBarcodes(
template <typename MappingRecord>
void Chromap<MappingRecord>::ComputeBarcodeAbundance(
    uint64_t max_num_sample_barcodes) {
  double real_start_time = Chromap<>::GetRealTime();
  double real_start_time = GetRealTime();
  SequenceBatch barcode_batch(read_batch_size_);
  for (size_t read_file_index = 0; read_file_index < read_file1_paths_.size();
       ++read_file_index) {
@@ -755,7 +755,7 @@ void Chromap<MappingRecord>::ComputeBarcodeAbundance(
          num_sample_barcodes_ * 20 < num_loaded_barcodes) {
        // Since num_loaded_pairs is a constant, this if is actuaclly only
        // effective in the first iteration
        Chromap<>::ExitWithMessage(
        ExitWithMessage(
            "Less than 5\% barcodes can be found or corrected based on the "
            "barcode whitelist.\nPlease check whether the barcode whitelist "
            "matches the data, e.g. length, reverse-complement. If this is a "
@@ -775,13 +775,13 @@ void Chromap<MappingRecord>::ComputeBarcodeAbundance(
  }

  std::cerr << "Compute barcode abundance using " << num_sample_barcodes_
            << " in " << Chromap<>::GetRealTime() - real_start_time << "s.\n";
            << " in " << GetRealTime() - real_start_time << "s.\n";
}

template <typename MappingRecord>
void Chromap<MappingRecord>::UpdateBarcodeAbundance(
    uint32_t num_loaded_barcodes, const SequenceBatch &barcode_batch) {
  double real_start_time = Chromap<>::GetRealTime();
  double real_start_time = GetRealTime();
  for (uint32_t barcode_index = 0; barcode_index < num_loaded_barcodes;
       ++barcode_index) {
    uint32_t barcode_length = barcode_batch.GetSequenceLengthAt(barcode_index);
@@ -798,7 +798,7 @@ void Chromap<MappingRecord>::UpdateBarcodeAbundance(
    }
  }
  std::cerr << "Update barcode abundance using " << num_sample_barcodes_
            << " in " << Chromap<>::GetRealTime() - real_start_time << "s.\n";
            << " in " << GetRealTime() - real_start_time << "s.\n";
}

template <typename MappingRecord>
@@ -829,7 +829,7 @@ void Chromap<MappingRecord>::PostProcessingInLowMemory(
    return;
  }

  double sort_and_dedupe_start_time = Chromap<>::GetRealTime();
  double sort_and_dedupe_start_time = GetRealTime();

  // Calculate block size and initialize
  uint64_t max_mem_size = 10 * ((uint64_t)1 << 30);
@@ -1041,12 +1041,10 @@ void Chromap<MappingRecord>::PostProcessingInLowMemory(

  if (remove_pcr_duplicates_) {
    std::cerr << "Sorted, deduped and outputed mappings in "
              << Chromap<>::GetRealTime() - sort_and_dedupe_start_time
              << "s.\n";
              << GetRealTime() - sort_and_dedupe_start_time << "s.\n";
  } else {
    std::cerr << "Sorted and outputed mappings in "
              << Chromap<>::GetRealTime() - sort_and_dedupe_start_time
              << "s.\n";
              << GetRealTime() - sort_and_dedupe_start_time << "s.\n";
  }
  std::cerr << "# uni-mappings: " << num_uni_mappings
            << ", # multi-mappings: " << num_multi_mappings
@@ -1102,7 +1100,7 @@ void Chromap<MappingRecord>::GenerateCustomizedRidRank(
  }

  if (k > ref_size) {
    chromap::Chromap<>::ExitWithMessage(
    chromap::ExitWithMessage(
        "Unknown chromsome names found in chromosome order file");
  }

@@ -1126,7 +1124,7 @@ void Chromap<MappingRecord>::RerankCandidatesRid(

template <typename MappingRecord>
void Chromap<MappingRecord>::MapPairedEndReads() {
  double real_start_time = Chromap<>::GetRealTime();
  double real_start_time = GetRealTime();

  // Load reference
  SequenceBatch reference;
@@ -1222,7 +1220,7 @@ void Chromap<MappingRecord>::MapPairedEndReads() {
    thread_num_candidates, thread_num_mappings, thread_num_mapped_reads, \
    thread_num_uniquely_mapped_reads, thread_num_barcode_in_whitelist,   \
    thread_num_corrected_barcode)
  double real_start_mapping_time = Chromap<>::GetRealTime();
  double real_start_mapping_time = GetRealTime();
  for (size_t read_file_index = 0; read_file_index < read_file1_paths_.size();
       ++read_file_index) {
    // Set read batches to the current read files.
@@ -1289,7 +1287,7 @@ void Chromap<MappingRecord>::MapPairedEndReads() {
      std::mt19937 generator(11);
#pragma omp single
      {
        double real_batch_start_time = Chromap<>::GetRealTime();
        double real_batch_start_time = GetRealTime();
        while (num_loaded_pairs > 0) {
          num_reads_ += num_loaded_pairs;
          num_reads_ += num_loaded_pairs;
@@ -1551,9 +1549,8 @@ void Chromap<MappingRecord>::MapPairedEndReads() {
          }

          std::cerr << "Mapped " << num_loaded_pairs << " read pairs in "
                    << Chromap<>::GetRealTime() - real_batch_start_time
                    << "s.\n";
          real_batch_start_time = Chromap<>::GetRealTime();
                    << GetRealTime() - real_batch_start_time << "s.\n";
          real_batch_start_time = GetRealTime();

          // Swap to next batch
          num_loaded_pairs = num_loaded_pairs_for_loading;
@@ -1605,8 +1602,8 @@ void Chromap<MappingRecord>::MapPairedEndReads() {
    }
  }  // end of for read_file_index

  std::cerr << "Mapped all reads in "
            << Chromap<>::GetRealTime() - real_start_mapping_time << "s.\n";
  std::cerr << "Mapped all reads in " << GetRealTime() - real_start_mapping_time
            << "s.\n";

  delete[] mm_history1;
  delete[] mm_history2;
@@ -1668,8 +1665,7 @@ void Chromap<MappingRecord>::MapPairedEndReads() {

  reference.FinalizeLoading();

  std::cerr << "Total time: " << Chromap<>::GetRealTime() - real_start_time
            << "s.\n";
  std::cerr << "Total time: " << GetRealTime() - real_start_time << "s.\n";
}

template <typename MappingRecord>
@@ -2575,7 +2571,7 @@ void Chromap<MappingRecord>::ApplyTn5ShiftOnPairedEndMapping(

template <typename MappingRecord>
void Chromap<MappingRecord>::MapSingleEndReads() {
  double real_start_time = Chromap<>::GetRealTime();
  double real_start_time = GetRealTime();

  SequenceBatch reference;
  reference.InitializeLoading(reference_file_path_);
@@ -2637,7 +2633,7 @@ void Chromap<MappingRecord>::MapSingleEndReads() {
    thread_num_candidates, thread_num_mappings, thread_num_mapped_reads, \
    thread_num_uniquely_mapped_reads, thread_num_barcode_in_whitelist,   \
    thread_num_corrected_barcode)
  double real_start_mapping_time = Chromap<>::GetRealTime();
  double real_start_mapping_time = GetRealTime();
  for (size_t read_file_index = 0; read_file_index < read_file1_paths_.size();
       ++read_file_index) {
    read_batch_for_loading.InitializeLoading(
@@ -2698,7 +2694,7 @@ void Chromap<MappingRecord>::MapSingleEndReads() {
#pragma omp single
      {
        while (num_loaded_reads > 0) {
          double real_batch_start_time = Chromap<>::GetRealTime();
          double real_batch_start_time = GetRealTime();
          num_reads_ += num_loaded_reads;
#pragma omp task
          {
@@ -2823,8 +2819,7 @@ void Chromap<MappingRecord>::MapSingleEndReads() {
                num_reference_sequences,
                &mappings_on_diff_ref_seqs_for_diff_threads_for_saving);
          }
          std::cerr << "Mapped in "
                    << Chromap<>::GetRealTime() - real_batch_start_time
          std::cerr << "Mapped in " << GetRealTime() - real_batch_start_time
                    << "s.\n";
        }
      }  // end of openmp single
@@ -2843,8 +2838,8 @@ void Chromap<MappingRecord>::MapSingleEndReads() {
    }
  }

  std::cerr << "Mapped all reads in "
            << Chromap<>::GetRealTime() - real_start_mapping_time << "s.\n";
  std::cerr << "Mapped all reads in " << GetRealTime() - real_start_mapping_time
            << "s.\n";

  delete[] mm_history;

@@ -2889,8 +2884,7 @@ void Chromap<MappingRecord>::MapSingleEndReads() {

  output_tools_.FinalizeMappingOutput();
  reference.FinalizeLoading();
  std::cerr << "Total time: " << Chromap<>::GetRealTime() - real_start_time
            << "s.\n";
  std::cerr << "Total time: " << GetRealTime() - real_start_time << "s.\n";
}

template <typename MappingRecord>
@@ -3486,7 +3480,7 @@ void Chromap<MappingRecord>::ApplyTn5ShiftOnSingleEndMapping(
template <typename MappingRecord>
uint32_t Chromap<MappingRecord>::LoadSingleEndReadsWithBarcodes(
    SequenceBatch *read_batch, SequenceBatch *barcode_batch) {
  double real_start_time = Chromap<>::GetRealTime();
  double real_start_time = GetRealTime();
  uint32_t num_loaded_reads = 0;
  while (num_loaded_reads < read_batch_size_) {
    bool no_more_read = read_batch->LoadOneSequenceAndSaveAt(num_loaded_reads);
@@ -3508,13 +3502,13 @@ uint32_t Chromap<MappingRecord>::LoadSingleEndReadsWithBarcodes(
    } else if (no_more_read && no_more_barcode) {
      break;
    } else {
      Chromap<>::ExitWithMessage("Numbers of reads and barcodes don't match!");
      ExitWithMessage("Numbers of reads and barcodes don't match!");
    }
    ++num_loaded_reads;
  }
  if (num_loaded_reads > 0) {
    std::cerr << "Loaded " << num_loaded_reads << " reads in "
              << Chromap<>::GetRealTime() - real_start_time << "s.\n";
              << GetRealTime() - real_start_time << "s.\n";
  } else {
    std::cerr << "No more reads.\n";
  }
@@ -3581,7 +3575,7 @@ template <typename MappingRecord>
void Chromap<MappingRecord>::RemovePCRDuplicate(
    uint32_t num_reference_sequences) {
  uint32_t num_mappings = 0;
  double real_dedupe_start_time = Chromap<>::GetRealTime();
  double real_dedupe_start_time = GetRealTime();
  for (uint32_t ri = 0; ri < num_reference_sequences; ++ri) {
    // double real_start_time = Chromap<>::GetRealTime();
    // radix_sort_with_barcode(mappings_on_diff_ref_seqs_[ri].data(),
@@ -3595,7 +3589,7 @@ void Chromap<MappingRecord>::RemovePCRDuplicate(
    // real_start_time << "s.\n";
  }
  std::cerr << "Sorted " << num_mappings << " elements in "
            << Chromap<>::GetRealTime() - real_dedupe_start_time << "s.\n";
            << GetRealTime() - real_dedupe_start_time << "s.\n";
  num_mappings = 0;
  for (uint32_t ri = 0; ri < num_reference_sequences; ++ri) {
    if (mappings_on_diff_ref_seqs_[ri].size() != 0) {
@@ -3630,7 +3624,7 @@ void Chromap<MappingRecord>::RemovePCRDuplicate(
    }
  }
  std::cerr << num_mappings << " mappings left after dedupe in "
            << Chromap<>::GetRealTime() - real_dedupe_start_time << "s.\n";
            << GetRealTime() - real_dedupe_start_time << "s.\n";
}

template <typename MappingRecord>
@@ -3747,7 +3741,7 @@ uint32_t Chromap<MappingRecord>::GetNumOverlappedMappings(
template <typename MappingRecord>
void Chromap<MappingRecord>::AllocateMultiMappings(
    uint32_t num_reference_sequences) {
  double real_start_time = Chromap<>::GetRealTime();
  double real_start_time = GetRealTime();
  std::vector<std::vector<MappingRecord>> &mappings =
      remove_pcr_duplicates_ ? deduped_mappings_on_diff_ref_seqs_
                             : mappings_on_diff_ref_seqs_;
@@ -3850,8 +3844,8 @@ void Chromap<MappingRecord>::AllocateMultiMappings(
    }
  }
  std::cerr << "Allocated " << num_allocated_multi_mappings
            << " multi-mappings in "
            << Chromap<>::GetRealTime() - real_start_time << "s.\n";
            << " multi-mappings in " << GetRealTime() - real_start_time
            << "s.\n";
  std::cerr << "# multi-mappings that have no uni-mapping overlaps: "
            << num_multi_mappings_without_overlapping_unique_mappings << ".\n";
}
@@ -5806,8 +5800,8 @@ void ChromapDriver::ParseArgsAndRun(int argc, char *argv[]) {
      mapping_parameters.low_memory_mode = true;
      mapping_parameters.mapping_output_format = MAPPINGFORMAT_PAIRS;
    } else {
      chromap::Chromap<>::ExitWithMessage("Unrecognized preset parameters " +
                                          read_type + "\n");
      chromap::ExitWithMessage("Unrecognized preset parameters " + read_type +
                               "\n");
    }
  }
  // Optional parameters
@@ -5957,13 +5951,13 @@ void ChromapDriver::ParseArgsAndRun(int argc, char *argv[]) {
    if (result.count("r")) {
      index_parameters.reference_file_path = result["ref"].as<std::string>();
    } else {
      chromap::Chromap<>::ExitWithMessage("No reference specified!");
      chromap::ExitWithMessage("No reference specified!");
    }
    if (result.count("o")) {
      index_parameters.index_output_file_path =
          result["output"].as<std::string>();
    } else {
      chromap::Chromap<>::ExitWithMessage("No output file specified!");
      chromap::ExitWithMessage("No output file specified!");
    }
    std::cerr << "Build index for the reference.\n";
    std::cerr << "Kmer length: " << index_parameters.kmer_size
@@ -5979,24 +5973,24 @@ void ChromapDriver::ParseArgsAndRun(int argc, char *argv[]) {
    if (result.count("r")) {
      mapping_parameters.reference_file_path = result["ref"].as<std::string>();
    } else {
      chromap::Chromap<>::ExitWithMessage("No reference specified!");
      chromap::ExitWithMessage("No reference specified!");
    }
    if (result.count("o")) {
      mapping_parameters.mapping_output_file_path =
          result["output"].as<std::string>();
    } else {
      chromap::Chromap<>::ExitWithMessage("No output file specified!");
      chromap::ExitWithMessage("No output file specified!");
    }
    if (result.count("x")) {
      mapping_parameters.index_file_path = result["index"].as<std::string>();
    } else {
      chromap::Chromap<>::ExitWithMessage("No index file specified!");
      chromap::ExitWithMessage("No index file specified!");
    }
    if (result.count("1")) {
      mapping_parameters.read_file1_paths =
          result["read1"].as<std::vector<std::string>>();
    } else {
      chromap::Chromap<>::ExitWithMessage("No read file specified!");
      chromap::ExitWithMessage("No read file specified!");
    }
    if (result.count("2")) {
      mapping_parameters.read_file2_paths =
@@ -6015,7 +6009,7 @@ void ChromapDriver::ParseArgsAndRun(int argc, char *argv[]) {

    if (result.count("barcode-whitelist")) {
      if (mapping_parameters.is_bulk_data) {
        chromap::Chromap<>::ExitWithMessage(
        chromap::ExitWithMessage(
            "No barcode file specified but the barcode whitelist file is "
            "given!");
      }
@@ -6027,7 +6021,7 @@ void ChromapDriver::ParseArgsAndRun(int argc, char *argv[]) {
      mapping_parameters.matrix_output_prefix =
          result["matrix-output-prefix"].as<std::string>();
      if (mapping_parameters.is_bulk_data) {
        chromap::Chromap<>::ExitWithMessage(
        chromap::ExitWithMessage(
            "No barcode file specified but asked to output matrix files!");
      }
    }
@@ -6163,7 +6157,7 @@ void ChromapDriver::ParseArgsAndRun(int argc, char *argv[]) {
        std::cerr << "Output mappings in pairs format.\n";
        break;
      default:
        chromap::Chromap<>::ExitWithMessage("Unknown mapping output format!");
        chromap::ExitWithMessage("Unknown mapping output format!");
        break;
    }

@@ -6215,8 +6209,7 @@ void ChromapDriver::ParseArgsAndRun(int argc, char *argv[]) {
          break;
        }
        case MAPPINGFORMAT_PAIRS:
          chromap::Chromap<>::ExitWithMessage(
              "No support for single-end HiC yet!");
          chromap::ExitWithMessage("No support for single-end HiC yet!");
          break;
        case MAPPINGFORMAT_BED:
        case MAPPINGFORMAT_TAGALIGN:
@@ -6231,7 +6224,7 @@ void ChromapDriver::ParseArgsAndRun(int argc, char *argv[]) {
          }
          break;
        default:
          chromap::Chromap<>::ExitWithMessage("Unknown mapping output format!");
          chromap::ExitWithMessage("Unknown mapping output format!");
          break;
      }
    } else {
@@ -6268,7 +6261,7 @@ void ChromapDriver::ParseArgsAndRun(int argc, char *argv[]) {
          }
          break;
        default:
          chromap::Chromap<>::ExitWithMessage("Unknown mapping output format!");
          chromap::ExitWithMessage("Unknown mapping output format!");
          break;
      }
    }
+0 −17
Original line number Diff line number Diff line
@@ -521,23 +521,6 @@ class Chromap {
  void RerankCandidatesRid(std::vector<Candidate> &candidates);
  void ParseReadFormat(const std::string &read_format);

  inline static double GetRealTime() {
    struct timeval tp;
    struct timezone tzp;
    gettimeofday(&tp, &tzp);
    return tp.tv_sec + tp.tv_usec * 1e-6;
  }
  inline static double GetCPUTime() {
    struct rusage r;
    getrusage(RUSAGE_SELF, &r);
    return r.ru_utime.tv_sec + r.ru_stime.tv_sec +
           1e-6 * (r.ru_utime.tv_usec + r.ru_stime.tv_usec);
  }
  inline static void ExitWithMessage(const std::string &message) {
    std::cerr << message << std::endl;
    exit(-1);
  }

 private:
  // Parameters
  int kmer_size_;
+11 −11
Original line number Diff line number Diff line
@@ -6,12 +6,13 @@
#include <iostream>

#include "chromap.h"
#include "utils.h"

namespace chromap {

void Index::Statistics(uint32_t num_sequences,
                       const SequenceBatch &reference) const {
  double real_start_time = Chromap<>::GetRealTime();
  double real_start_time = GetRealTime();
  int n = 0, n1 = 0;
  uint32_t i;
  uint64_t sum = 0, len = 0;
@@ -34,8 +35,8 @@ void Index::Statistics(uint32_t num_sequences,
  fprintf(stderr,
          "[M::%s::%.3f] distinct minimizers: %d (%.2f%% are singletons); "
          "average occurrences: %.3lf; average spacing: %.3lf\n",
          __func__, Chromap<>::GetRealTime() - real_start_time, n,
          100.0 * n1 / n, (double)sum / n, (double)len / sum);
          __func__, GetRealTime() - real_start_time, n, 100.0 * n1 / n,
          (double)sum / n, (double)len / sum);
}

// always reserve space for minimizers in other functions
@@ -163,7 +164,7 @@ void Index::GenerateMinimizerSketch(
}

void Index::Construct(uint32_t num_sequences, const SequenceBatch &reference) {
  double real_start_time = Chromap<>::GetRealTime();
  double real_start_time = GetRealTime();
  // tmp_table stores (minimizer, position)
  std::vector<std::pair<uint64_t, uint64_t> > tmp_table;
  tmp_table.reserve(reference.GetNumBases() / window_size_ * 2);
@@ -230,8 +231,8 @@ void Index::Construct(uint32_t num_sequences, const SequenceBatch &reference) {
            << ", # buckets: " << kh_n_buckets(lookup_table_)
            << ", occurrence table size: " << occurrence_table_.size()
            << ", # singletons: " << num_singletons << ".\n";
  std::cerr << "Built index successfully in "
            << Chromap<>::GetRealTime() - real_start_time << "s.\n";
  std::cerr << "Built index successfully in " << GetRealTime() - real_start_time
            << "s.\n";
}

void Index::CheckIndex(uint32_t num_sequences,
@@ -269,7 +270,7 @@ void Index::CheckIndex(uint32_t num_sequences,
}

void Index::Save() const {
  double real_start_time = Chromap<>::GetRealTime();
  double real_start_time = GetRealTime();
  FILE *index_file = fopen(index_file_path_.c_str(), "wb");
  assert(index_file != NULL);
  uint64_t num_bytes = 0;
@@ -299,12 +300,11 @@ void Index::Save() const {
  fclose(index_file);
  // std::cerr << "Index size: " << num_bytes / (1024.0 * 1024 * 1024) << "GB,
  // saved in " << Chromap<>::GetRealTime() - real_start_time << "s.\n";
  std::cerr << "Saved in " << Chromap<>::GetRealTime() - real_start_time
            << "s.\n";
  std::cerr << "Saved in " << GetRealTime() - real_start_time << "s.\n";
}

void Index::Load() {
  double real_start_time = Chromap<>::GetRealTime();
  double real_start_time = GetRealTime();
  FILE *index_file = fopen(index_file_path_.c_str(), "rb");
  assert(index_file != NULL);
  int err = 0;
@@ -331,7 +331,7 @@ void Index::Load() {
  std::cerr << "Lookup table size: " << kh_size(lookup_table_)
            << ", occurrence table size: " << occurrence_table_.size() << ".\n";
  std::cerr << "Loaded index successfully in "
            << Chromap<>::GetRealTime() - real_start_time << "s.\n";
            << GetRealTime() - real_start_time << "s.\n";
}

// Return the number of repetitive seeds.
+9 −9
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
#include <tuple>

#include "chromap.h"
#include "utils.h"

namespace chromap {
constexpr uint8_t SequenceBatch::char_to_uint8_table_[256];
@@ -12,14 +13,13 @@ void SequenceBatch::InitializeLoading(const std::string &sequence_file_path) {
  sequence_file_path_ = sequence_file_path;
  sequence_file_ = gzopen(sequence_file_path_.c_str(), "r");
  if (sequence_file_ == NULL) {
    Chromap<>::ExitWithMessage("Cannot find sequence file" +
                               sequence_file_path);
    ExitWithMessage("Cannot find sequence file" + sequence_file_path);
  }
  sequence_kseq_ = kseq_init(sequence_file_);
}

uint32_t SequenceBatch::LoadBatch() {
  double real_start_time = Chromap<>::GetRealTime();
  double real_start_time = GetRealTime();
  uint32_t num_sequences = 0;
  num_bases_ = 0;
  for (uint32_t sequence_index = 0; sequence_index < max_num_sequences_;
@@ -44,7 +44,7 @@ uint32_t SequenceBatch::LoadBatch() {
      num_bases_ += length;
    } else {
      if (length != -1) {
        Chromap<>::ExitWithMessage(
        ExitWithMessage(
            "Didn't reach the end of sequence file, which might be corrupted!");
      }
      // make sure to reach the end of file rather than meet an error
@@ -53,7 +53,7 @@ uint32_t SequenceBatch::LoadBatch() {
  }
  if (num_sequences != 0) {
    std::cerr << "Loaded sequence batch successfully in "
              << Chromap<>::GetRealTime() - real_start_time << "s, ";
              << GetRealTime() - real_start_time << "s, ";
    std::cerr << "number of sequences: " << num_sequences << ", ";
    std::cerr << "number of bases: " << num_bases_ << ".\n";
  } else {
@@ -83,7 +83,7 @@ bool SequenceBatch::LoadOneSequenceAndSaveAt(uint32_t sequence_index) {
    }
  } else {
    if (length != -1) {
      Chromap<>::ExitWithMessage(
      ExitWithMessage(
          "Didn't reach the end of sequence file, which might be corrupted!");
    }
    // make sure to reach the end of file rather than meet an error
@@ -93,7 +93,7 @@ bool SequenceBatch::LoadOneSequenceAndSaveAt(uint32_t sequence_index) {
}

uint32_t SequenceBatch::LoadAllSequences() {
  double real_start_time = Chromap<>::GetRealTime();
  double real_start_time = GetRealTime();
  sequence_batch_.reserve(200);
  uint32_t num_sequences = 0;
  num_bases_ = 0;
@@ -118,7 +118,7 @@ uint32_t SequenceBatch::LoadAllSequences() {
      num_bases_ += length;
    } else {
      if (length != -1) {
        Chromap<>::ExitWithMessage(
        ExitWithMessage(
            "Didn't reach the end of sequence file, which might be corrupted!");
      }
      // make sure to reach the end of file rather than meet an error
@@ -127,7 +127,7 @@ uint32_t SequenceBatch::LoadAllSequences() {
    length = kseq_read(sequence_kseq_);
  }
  std::cerr << "Loaded all sequences successfully in "
            << Chromap<>::GetRealTime() - real_start_time << "s, ";
            << GetRealTime() - real_start_time << "s, ";
  std::cerr << "number of sequences: " << num_sequences << ", ";
  std::cerr << "number of bases: " << num_bases_ << ".\n";
  return num_sequences;

src/utils.h

0 → 100644
+27 −0
Original line number Diff line number Diff line
#ifndef UTILS_H_
#define UTILS_H_

namespace chromap {

inline static double GetRealTime() {
  struct timeval tp;
  struct timezone tzp;
  gettimeofday(&tp, &tzp);
  return tp.tv_sec + tp.tv_usec * 1e-6;
}

inline static double GetCPUTime() {
  struct rusage r;
  getrusage(RUSAGE_SELF, &r);
  return r.ru_utime.tv_sec + r.ru_stime.tv_sec +
         1e-6 * (r.ru_utime.tv_usec + r.ru_stime.tv_usec);
}

inline static void ExitWithMessage(const std::string &message) {
  std::cerr << message << std::endl;
  exit(-1);
}

}  // namespace chromap

#endif  // UTILS_H_