Skip to content

Commit 42fa364

Browse files
author
Daniel Cooke
committed
Dynamically open and close temp BCFs as needed
Helps avoid having too many open files
1 parent 29fde14 commit 42fa364

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/core/octopus.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,13 @@ void log_finish_info(const GenomeCallingComponents& components, const utils::Tim
244244

245245
void write_calls(std::deque<VcfRecord>&& calls, VcfWriter& out)
246246
{
247+
if (calls.empty()) return;
247248
static auto debug_log = get_debug_log();
248249
if (debug_log) stream(*debug_log) << "Writing " << calls.size() << " calls to output";
250+
const bool was_closed {!out.is_open()};
251+
if (was_closed) out.open();
249252
write(calls, out);
253+
if (was_closed) out.close();
250254
calls.clear();
251255
calls.shrink_to_fit();
252256
}
@@ -456,17 +460,15 @@ auto create_unique_temp_output_file_path(const GenomicRegion& region,
456460
return result;
457461
}
458462

459-
VcfWriter create_unique_temp_output_file(const GenomicRegion& region,
460-
const GenomeCallingComponents& components)
463+
VcfWriter create_unique_temp_output_file(const GenomicRegion& region, const GenomeCallingComponents& components)
461464
{
462465
auto path = create_unique_temp_output_file_path(region, components);
463466
const auto call_types = get_call_types(components, {region.contig_name()});
464467
auto header = make_vcf_header(components.samples(), region.contig_name(), components.reference(), call_types, "octopus-internal");
465468
return VcfWriter {std::move(path), std::move(header)};
466469
}
467470

468-
VcfWriter create_unique_temp_output_file(const GenomicRegion::ContigName& contig,
469-
const GenomeCallingComponents& components)
471+
VcfWriter create_unique_temp_output_file(const GenomicRegion::ContigName& contig, const GenomeCallingComponents& components)
470472
{
471473
return create_unique_temp_output_file(components.reference().contig_region(contig), components);
472474
}
@@ -481,7 +483,9 @@ TempVcfWriterMap make_temp_vcf_writers(const GenomeCallingComponents& components
481483
TempVcfWriterMap result {};
482484
result.reserve(components.contigs().size());
483485
for (const auto& contig : components.contigs()) {
484-
result.emplace(contig, create_unique_temp_output_file(contig, components));
486+
auto contig_writer = create_unique_temp_output_file(contig, components);
487+
contig_writer.close();
488+
result.emplace(contig, std::move(contig_writer));
485489
}
486490
return result;
487491
}
@@ -1106,7 +1110,7 @@ auto extract_writers(TempVcfWriterMap&& vcfs)
11061110

11071111
auto extract_as_readers(TempVcfWriterMap&& vcfs)
11081112
{
1109-
return writers_to_readers(extract_writers(std::move(vcfs)));
1113+
return writers_to_readers(extract_writers(std::move(vcfs)), false);
11101114
}
11111115

11121116
void merge(TempVcfWriterMap&& temp_vcf_writers, GenomeCallingComponents& components)

0 commit comments

Comments
 (0)