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+
2532using std::vector;
2633using std::string;
2734using std::unordered_map;
2835using std::runtime_error;
36+ using std::size;
37+ using std::toupper;
2938
3039static const char *digits = " 0987654321" ;
3140static 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-
6573static size_t
6674adjust_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-
7583static 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