@@ -90,6 +90,18 @@ pato::output_writer_t::create(const pato::options_t &opts) {
90
90
return pato::output_writer_t {output_file, summary_file, opts};
91
91
}
92
92
93
+ pato::output_writer_t::output_writer_t (std::FILE *output_file_,
94
+ std::FILE *summary_file_,
95
+ const options_t &opts_)
96
+ : output_file{output_file_,
97
+ [this ](std::FILE *f) -> void {
98
+ if (opts.output_format != output_format_t ::summary) {
99
+ std::fclose (f);
100
+ }
101
+ }},
102
+ summary_file{summary_file_, [](std::FILE *f) -> void { std::fclose (f); }},
103
+ opts{opts_} {}
104
+
93
105
void pato::output_writer_t::print_motifs (const pato::motif_vector_t &motifs,
94
106
const pato::name_vector_t &names) {
95
107
if (opts.output_format == output_format_t ::summary || motifs.empty ()) {
@@ -101,25 +113,26 @@ void pato::output_writer_t::print_motifs(const pato::motif_vector_t &motifs,
101
113
102
114
for (const auto &m : motifs) {
103
115
if (opts.output_format == output_format_t ::bed) {
104
- std::fprintf (
105
- output_file, " %s\t %lu\t %lu\t %u\t %c\t %.2g\t %s\t %.2g\t %d\t %s\t -\n " ,
106
- seqan::toCString (names[seqan::getSequenceNo (m)]),
107
- seqan::beginPosition (m), seqan::endPosition (m), seqan::score (m),
108
- seqan::getMotif (m),
109
- 1.0 - static_cast <double >(seqan::score (m)) /
110
- (seqan::endPosition (m) - seqan::beginPosition (m)),
111
- seqan::toCString (seqan::errorString (m)), seqan::guanineRate (m),
112
- seqan::duplicates (m),
113
- seqan::toCString (opts.pretty_output ? seqan::prettyString (m)
114
- : seqan::outputString (m)));
116
+ std::fprintf (output_file.get (),
117
+ " %s\t %lu\t %lu\t %u\t %c\t %.2g\t %s\t %.2g\t %d\t %s\t -\n " ,
118
+ seqan::toCString (names[seqan::getSequenceNo (m)]),
119
+ seqan::beginPosition (m), seqan::endPosition (m),
120
+ seqan::score (m), seqan::getMotif (m),
121
+ 1.0 - static_cast <double >(seqan::score (m)) /
122
+ (seqan::endPosition (m) - seqan::beginPosition (m)),
123
+ seqan::toCString (seqan::errorString (m)),
124
+ seqan::guanineRate (m), seqan::duplicates (m),
125
+ seqan::toCString (opts.pretty_output
126
+ ? seqan::prettyString (m)
127
+ : seqan::outputString (m)));
115
128
} else {
116
129
if (last_sequence_id != seqan::getSequenceNo (m)) {
117
130
counter = 1 ;
118
131
last_sequence_id = seqan::getSequenceNo (m);
119
132
}
120
133
121
134
std::fprintf (
122
- output_file, " >%s_%u\t %lu-%lu %c\t %u\t %s\t %g\t %d\t -\n %s\n " ,
135
+ output_file. get () , " >%s_%u\t %lu-%lu %c\t %u\t %s\t %g\t %d\t -\n %s\n " ,
123
136
seqan::toCString (names[seqan::getSequenceNo (m)]), counter++,
124
137
seqan::beginPosition (m), seqan::endPosition (m), seqan::getMotif (m),
125
138
seqan::score (m), seqan::toCString (seqan::errorString (m)),
@@ -317,21 +330,21 @@ void pato::output_writer_t::print_motifs_summary(
317
330
const pato::name_vector_t &names) {
318
331
for (const auto &potential : potentials) {
319
332
if (seqan::hasCount (potential)) {
320
- std::fprintf (summary_file, " %s\t %u\t %.3g" ,
333
+ std::fprintf (summary_file. get () , " %s\t %u\t %.3g" ,
321
334
seqan::toCString (names[seqan::getKey (potential)]),
322
335
seqan::getCounts (potential),
323
336
seqan::getCounts (potential) / seqan::getNorm (potential));
324
337
if (opts.run_mode == run_mode_t ::tfo_search) {
325
338
std::fprintf (
326
- summary_file, " \t %u\t %.3g\t %u\t %.3g\t %u\t %.3g\t " ,
339
+ summary_file. get () , " \t %u\t %.3g\t %u\t %.3g\t %u\t %.3g\t " ,
327
340
seqan::getCount (potential, ' R' ),
328
341
seqan::getCount (potential, ' R' ) / seqan::getNorm (potential),
329
342
seqan::getCount (potential, ' Y' ),
330
343
seqan::getCount (potential, ' Y' ) / seqan::getNorm (potential),
331
344
seqan::getCount (potential, ' M' ),
332
345
seqan::getCount (potential, ' M' ) / seqan::getNorm (potential));
333
346
}
334
- std::fprintf (summary_file, " \n " );
347
+ std::fprintf (summary_file. get () , " \n " );
335
348
}
336
349
}
337
350
}
@@ -362,7 +375,7 @@ void pato::output_writer_t::print_triplexes(
362
375
auto tts_seq_id = match.ttsSeqNo ;
363
376
364
377
std::fprintf (
365
- output_file,
378
+ output_file. get () ,
366
379
" %s\t %lu\t %lu\t %s\t %lu\t %lu\t %u\t %.2g\t %s\t %c\t %c\t %c\t %.2g" ,
367
380
seqan::toCString (tfo_names[tfo_seq_id]), match.oBegin , match.oEnd ,
368
381
seqan::toCString (tts_names[tts_seq_id]), match.dBegin , match.dEnd ,
@@ -373,11 +386,11 @@ void pato::output_writer_t::print_triplexes(
373
386
match.motif , match.strand , match.parallel ? ' P' : ' A' ,
374
387
static_cast <double >(match.guanines ) / (match.dEnd - match.dBegin ));
375
388
if (opts.output_format == output_format_t ::triplex) {
376
- std::fprintf (output_file, " %s" ,
389
+ std::fprintf (output_file. get () , " %s" ,
377
390
seqan::toCString (triplex_alignment_string (match, tfo_motifs,
378
391
tts_motifs)));
379
392
}
380
- std::fprintf (output_file, " \n " );
393
+ std::fprintf (output_file. get () , " \n " );
381
394
#if defined(_OPENMP)
382
395
}
383
396
#endif
@@ -391,7 +404,7 @@ void pato::output_writer_t::print_triplex_summary(
391
404
for (const auto &potential_entry : potentials) {
392
405
const auto &potential = potential_entry.second ;
393
406
if (seqan::hasCount (potential)) {
394
- std::fprintf (summary_file,
407
+ std::fprintf (summary_file. get () ,
395
408
" %s\t %s\t %u\t %.3g\t %u\t %.3g\t %u\t %.3g\t %u\t %.3g\t\n " ,
396
409
seqan::toCString (tts_names[seqan::getKey (potential).second ]),
397
410
seqan::toCString (tfo_names[seqan::getKey (potential).first ]),
@@ -406,10 +419,3 @@ void pato::output_writer_t::print_triplex_summary(
406
419
}
407
420
}
408
421
}
409
-
410
- void pato::output_writer_t::destroy () {
411
- if (opts.output_format != pato::output_format_t ::summary) {
412
- std::fclose (output_file);
413
- }
414
- std::fclose (summary_file);
415
- }
0 commit comments