Skip to content

Commit 9596b02

Browse files
src/utils/clean-hairpins.cpp: changed a variable from uint64_t to size_t because macOS gcc-14.2.0 was complaining
1 parent 5a2ee67 commit 9596b02

File tree

1 file changed

+42
-24
lines changed

1 file changed

+42
-24
lines changed

src/utils/clean-hairpins.cpp

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
#include <algorithm>
2222
#include <array>
23+
#include <cstddef> // std::size_t
24+
#include <cstdint> // std::uint32_t and std::uint64_t
2325
#include <fstream>
2426
#include <iomanip>
2527
#include <iostream>
@@ -45,7 +47,10 @@ using std::ofstream;
4547
using std::ostream;
4648
using std::ostringstream;
4749
using std::runtime_error;
50+
using std::size_t;
4851
using std::string;
52+
using std::uint32_t;
53+
using std::uint64_t;
4954
using std::vector;
5055

5156
using bamxx::bgzf_file;
@@ -93,22 +98,28 @@ operator>>(bgzf_file &s, FASTQRecord &r) {
9398

9499
err_code ec = err_code::none;
95100

96-
if (!getline(s, r.name)) return s;
101+
if (!getline(s, r.name))
102+
return s;
97103

98-
if (r.name.empty() || r.name[0] != '@') ec = err_code::bad_name;
104+
if (r.name.empty() || r.name[0] != '@')
105+
ec = err_code::bad_name;
99106

100107
const auto nm_end = r.name.find_first_of(" \t");
101108
const auto nm_sz = (nm_end == string::npos ? r.name.size() : nm_end) - 1;
102109
r.name.erase(copy_n(cbegin(r.name) + 1, nm_sz, begin(r.name)), cend(r.name));
103110

104-
if (!getline(s, r.seq)) ec = err_code::bad_seq;
111+
if (!getline(s, r.seq))
112+
ec = err_code::bad_seq;
105113

106114
string tmp;
107-
if (!getline(s, tmp)) ec = err_code::bad_plus;
115+
if (!getline(s, tmp))
116+
ec = err_code::bad_plus;
108117

109-
if (!getline(s, r.qual)) ec = err_code::bad_qual;
118+
if (!getline(s, r.qual))
119+
ec = err_code::bad_qual;
110120

111-
if (ec != err_code::none) throw error_msg[ec];
121+
if (ec != err_code::none)
122+
throw error_msg[ec];
112123

113124
return s;
114125
}
@@ -171,15 +182,13 @@ struct hp_summary {
171182
// sum_percent_match_bad over the total hairpin reads.
172183
double mean_percent_match_hairpin{};
173184

174-
auto
175-
assign_values() -> void {
185+
auto assign_values() -> void {
176186
mean_percent_match_non_hairpin =
177187
sum_percent_match_good / (n_reads - n_hairpin_reads);
178188
mean_percent_match_hairpin = sum_percent_match_bad / n_hairpin_reads;
179189
}
180190

181-
auto
182-
tostring() const -> string {
191+
auto tostring() const -> string {
183192
ostringstream oss;
184193
oss << "total_reads_pairs: " << n_reads << '\n'
185194
<< "good_reads_pairs: " << n_good_reads << '\n'
@@ -197,7 +206,8 @@ struct hp_summary {
197206
static void
198207
write_histogram(const string &hist_outfile, vector<double> hist) {
199208
ofstream hist_out(hist_outfile);
200-
if (!hist_out) throw runtime_error("failed to open file: " + hist_outfile);
209+
if (!hist_out)
210+
throw runtime_error("failed to open file: " + hist_outfile);
201211
const auto total = accumulate(cbegin(hist), cend(hist), 0.0);
202212
transform(cbegin(hist), cend(hist), begin(hist),
203213
[&total](const double t) { return t / total; });
@@ -213,7 +223,8 @@ static void
213223
write_statistics(const string &filename, hp_summary hps) {
214224
hps.assign_values();
215225
ofstream out(filename);
216-
if (!out) throw runtime_error("failed to open file: " + filename);
226+
if (!out)
227+
throw runtime_error("failed to open file: " + filename);
217228
out << hps.tostring();
218229
}
219230

@@ -226,17 +237,18 @@ fraction_good_bases(const FASTQRecord &a, const FASTQRecord &b) {
226237

227238
struct clean_hairpin {
228239
double cutoff{0.95};
229-
uint64_t n_reads_to_check{std::numeric_limits<size_t>::max()};
240+
// ADS: this was uint64_t but g++-14.2.0 on macOS had a problem
241+
size_t n_reads_to_check{std::numeric_limits<size_t>::max()};
230242
double min_good_base_percent{0.5};
231243
uint32_t min_read_length{32};
232244
uint32_t n_hist_bins{20};
233245
bool invert_output{false};
234246

235-
hp_summary
236-
analyze_reads(const string &outfile1, const string &outfile2, bgzf_file &in1,
237-
bgzf_file &in2, vector<double> &hist) const;
238-
hp_summary
239-
analyze_reads(bgzf_file &in1, bgzf_file &in2, vector<double> &hist) const;
247+
hp_summary analyze_reads(const string &outfile1, const string &outfile2,
248+
bgzf_file &in1, bgzf_file &in2,
249+
vector<double> &hist) const;
250+
hp_summary analyze_reads(bgzf_file &in1, bgzf_file &in2,
251+
vector<double> &hist) const;
240252
};
241253

242254
hp_summary
@@ -246,9 +258,11 @@ clean_hairpin::analyze_reads(const string &outfile1, const string &outfile2,
246258

247259
// output files for read1 and read2 with hairpins removed
248260
bgzf_file out1(outfile1, "w");
249-
if (!out1) throw runtime_error("cannot open output file: " + outfile1);
261+
if (!out1)
262+
throw runtime_error("cannot open output file: " + outfile1);
250263
bgzf_file out2(outfile2, "w");
251-
if (!out2) throw runtime_error("cannot open output file: " + outfile2);
264+
if (!out2)
265+
throw runtime_error("cannot open output file: " + outfile2);
252266

253267
hp_summary hps{cutoff};
254268
FASTQRecord r1, r2;
@@ -384,17 +398,21 @@ main_clean_hairpins(int argc, const char **argv) {
384398

385399
// Input: paired-end reads with end1 and end2
386400
bgzf_file in1(reads_file1, "r");
387-
if (!in1) throw runtime_error("cannot open input file: " + reads_file1);
401+
if (!in1)
402+
throw runtime_error("cannot open input file: " + reads_file1);
388403
bgzf_file in2(reads_file2, "r");
389-
if (!in2) throw runtime_error("cannot open input file: " + reads_file2);
404+
if (!in2)
405+
throw runtime_error("cannot open input file: " + reads_file2);
390406

391407
const hp_summary hps =
392408
write_reads ? ch.analyze_reads(outfile1, outfile2, in1, in2, hist)
393409
: ch.analyze_reads(in1, in2, hist);
394410

395-
if (!stat_outfile.empty()) write_statistics(stat_outfile, hps);
411+
if (!stat_outfile.empty())
412+
write_statistics(stat_outfile, hps);
396413

397-
if (!hist_outfile.empty()) write_histogram(hist_outfile, hist);
414+
if (!hist_outfile.empty())
415+
write_histogram(hist_outfile, hist);
398416
}
399417
catch (const std::exception &e) {
400418
cerr << e.what() << endl;

0 commit comments

Comments
 (0)