SeqAn3
3.4.0
The Modern C++ library for sequence analysis.
Toggle main menu visibility
Loading...
Searching...
No Matches
misc_output.hpp
Go to the documentation of this file.
1
// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
2
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
3
// SPDX-License-Identifier: BSD-3-Clause
4
9
10
#pragma once
11
12
#include <
filesystem
>
13
#include <
functional
>
14
#include <
iostream
>
15
#include <
string
>
16
#include <
tuple
>
17
18
#include <seqan3/contrib/stream/bgzf.hpp>
19
#include <seqan3/contrib/stream/bgzf_ostream.hpp>
20
#include <seqan3/contrib/stream/bz2_ostream.hpp>
21
#include <seqan3/contrib/stream/gz_ostream.hpp>
22
#include <
seqan3/io/exception.hpp
>
23
#include <
seqan3/utility/concept.hpp
>
24
25
namespace
seqan3::detail
26
{
27
35
template
<builtin_
char
acter
char
_t>
36
inline
auto
make_secondary_ostream(std::basic_ostream<char_t> & primary_stream, std::filesystem::path & filename)
37
-> std::unique_ptr<std::basic_ostream<char_t>, std::function<void(std::basic_ostream<char_t> *)>>
38
{
39
// don't assume ownership
40
constexpr
auto
stream_deleter_noop = [](std::basic_ostream<char_t> *) {};
41
// assume ownership
42
[[maybe_unused]]
constexpr
auto
stream_deleter_default = [](std::basic_ostream<char_t> * ptr)
43
{
44
delete
ptr;
45
};
46
47
std::string extension = filename.extension().string();
48
49
if
(extension ==
".gz"
)
50
{
51
#if SEQAN3_HAS_ZLIB
52
filename.replace_extension(
""
);
53
return
{
new
contrib::basic_gz_ostream<char_t>{primary_stream}, stream_deleter_default};
54
#else
55
throw
file_open_error{
"Trying to write a gzipped file, but no ZLIB available."
};
56
#endif
// SEQAN3_HAS_ZLIB
57
}
58
else
if
((extension ==
".bgzf"
) || (extension ==
".bam"
))
59
{
60
#if SEQAN3_HAS_ZLIB
61
if
(extension !=
".bam"
)
// remove extension except for bam
62
filename.replace_extension(
""
);
63
64
return
{
new
contrib::basic_bgzf_ostream<char_t>{primary_stream}, stream_deleter_default};
65
#else
66
throw
file_open_error{
"Trying to write a bgzf'ed file, but no ZLIB available."
};
67
#endif
// SEQAN3_HAS_ZLIB
68
}
69
else
if
(extension ==
".bz2"
)
70
{
71
#if SEQAN3_HAS_BZIP2
72
filename.replace_extension(
""
);
73
return
{
new
contrib::basic_bz2_ostream<char_t>{primary_stream}, stream_deleter_default};
74
#else
75
throw
file_open_error{
"Trying to write a bzipped file, but no libbz2 available."
};
76
#endif
// SEQAN3_HAS_BZIP2
77
}
78
else
if
(extension ==
".zst"
)
79
{
80
throw
file_open_error{
"Trying to write a zst'ed file, but SeqAn does not yet support this."
};
81
}
82
83
return
{&primary_stream, stream_deleter_noop};
84
}
85
86
}
// namespace seqan3::detail
filesystem
functional
exception.hpp
Provides exceptions used in the I/O module.
iostream
string
tuple
concept.hpp
Provides concepts that do not have equivalents in C++20.
Hide me
Version:
seqan3
io
detail
misc_output.hpp
Generated on
for SeqAn3 by
1.17.0