Skip to content

Commit bae9001

Browse files
chromosome_utils.cpp: Adding includes, constexpr for constants and updating a long-deprecated function interface for adjust_region_size
1 parent 604c0c7 commit bae9001

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

chromosome_utils.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,19 @@
2222

2323
#include "chromosome_utils.hpp"
2424

25+
#include <utility>
26+
#include <cctype>
27+
#include <vector>
28+
#include <string>
29+
#include <unordered_map>
30+
#include <stdexcept>
31+
2532
using std::vector;
2633
using std::string;
2734
using std::unordered_map;
2835
using std::runtime_error;
36+
using std::size;
37+
using std::toupper;
2938

3039
static const char *digits = "0987654321";
3140
static const char *whitespace = " \t";
@@ -61,26 +70,24 @@ parse_region_name(string region_name,
6170
end = static_cast<size_t>(atoi(end_string.c_str()));
6271
}
6372

64-
6573
static size_t
6674
adjust_start_pos(const size_t orig_start, const string &chrom_name) {
67-
static const double LINE_WIDTH = 50.0; // ADS: dangerous; often this is 80
75+
static constexpr double line_width = 50.0; // ADS: dangerous; often
76+
// this is 80
6877
const size_t name_offset = chrom_name.length() + 2; // For the '>' and '\n';
6978
const size_t preceding_newlines =
70-
static_cast<size_t>(std::floor(orig_start / LINE_WIDTH));
79+
static_cast<size_t>(std::floor(orig_start / line_width));
7180
return orig_start + preceding_newlines + name_offset;
7281
}
7382

74-
7583
static size_t
76-
adjust_region_size(const size_t orig_start,
77-
const string &chrom_name, // ADS: remove this soon
78-
const size_t orig_size) {
79-
static const double LINE_WIDTH = 50.0; // ADS: dangerous; often this is 80
84+
adjust_region_size(const size_t orig_start, const size_t orig_size) {
85+
static constexpr double line_width = 50.0; // ADS: dangerous; often
86+
// this is 80
8087
const size_t preceding_newlines_start =
81-
static_cast<size_t>(std::floor(orig_start / LINE_WIDTH));
88+
static_cast<size_t>(std::floor(orig_start / line_width));
8289
const size_t preceding_newlines_end =
83-
static_cast<size_t>(std::floor((orig_start + orig_size) / LINE_WIDTH));
90+
static_cast<size_t>(std::floor((orig_start + orig_size) / line_width));
8491
return (orig_size + (preceding_newlines_end - preceding_newlines_start));
8592
}
8693

@@ -100,8 +107,7 @@ extract_regions_chrom_fasta_impl(const string &chrom_name,
100107
const auto orig_region_size = orig_end_pos - orig_start_pos;
101108

102109
const auto start_pos = adjust_start_pos(orig_start_pos, chrom_name);
103-
const auto region_size =
104-
adjust_region_size(orig_start_pos, chrom_name, orig_region_size);
110+
const auto region_size = adjust_region_size(orig_start_pos, orig_region_size);
105111
assert(start_pos >= 0);
106112

107113
in.seekg(start_pos);
@@ -111,8 +117,8 @@ extract_regions_chrom_fasta_impl(const string &chrom_name,
111117
buffer.erase(remove(begin(buffer), end(buffer), '\n'));
112118
transform(cbegin(buffer), cend(buffer), begin(buffer),
113119
[](const char x) {return toupper(x);});
114-
sequences.push_back(move(buffer));
115-
assert(i.get_width() == sequences.back().size());
120+
sequences.push_back(std::move(buffer));
121+
assert(i.get_width() == size(sequences.back()));
116122
}
117123
}
118124

0 commit comments

Comments
 (0)