SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
seqan3::sam_file_input_options< sequence_legal_alphabet > Struct Template Reference

The options type defines various option members that influence the behaviour of all or some formats. More...

#include <seqan3/io/sam_file/input_options.hpp>

+ Inheritance diagram for seqan3::sam_file_input_options< sequence_legal_alphabet >:

Public Attributes

std::ostreamstream_warnings_to {std::addressof(std::cerr)}
 The stream to write warnings to. Defaults to std::cerr.
 

Detailed Description

template<typename sequence_legal_alphabet>
struct seqan3::sam_file_input_options< sequence_legal_alphabet >

The options type defines various option members that influence the behaviour of all or some formats.

Remarks
For a complete overview, take a look at SAM File

Member Data Documentation

◆ stream_warnings_to

template<typename sequence_legal_alphabet >
std::ostream* seqan3::sam_file_input_options< sequence_legal_alphabet >::stream_warnings_to {std::addressof(std::cerr)}

The stream to write warnings to. Defaults to std::cerr.

Example

// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <sstream>
// A helper struct to create a temporary file and remove it when it goes out of scope.
struct temporary_file
{
temporary_file()
{
std::ofstream file{path}; // Create file
}
temporary_file(temporary_file const &) = delete;
temporary_file & operator=(temporary_file const &) = delete;
temporary_file(temporary_file &&) = delete;
temporary_file & operator=(temporary_file &&) = delete;
~temporary_file()
{
}
std::string read_content() const
{
std::ifstream file{path};
}
};
static constexpr auto sam_file_raw = R"(@HD VN:1.6 pb:5.0.0 ot:ter
@SQ SN:ref LN:34
)";
static auto get_sam_file_input()
{
}
void defaults_to_cerr()
{
auto fin = get_sam_file_input();
auto it = fin.begin();
}
void redirect_to_cout()
{
auto fin = get_sam_file_input();
fin.options.stream_warnings_to = std::addressof(std::cout); // Equivalent to `= &std::cout;`
auto it = fin.begin();
}
void redirect_to_file()
{
temporary_file tmp_file{};
auto fin = get_sam_file_input();
{ // Inner scope to close file before reading
std::ofstream warning_file{tmp_file.path};
fin.options.stream_warnings_to = std::addressof(warning_file); // Equivalent to `= &warning_file;`
auto it = fin.begin();
}
std::cout << "File content:\n" << tmp_file.read_content();
}
void silence_warnings()
{
auto fin = get_sam_file_input();
fin.options.stream_warnings_to = nullptr;
auto it = fin.begin();
}
void filter()
{
auto fin = get_sam_file_input();
fin.options.stream_warnings_to = std::addressof(stream); // Equivalent to `= &stream;`
auto it = fin.begin();
for (std::string line{}; std::getline(stream, line);)
{
// If "pb" is not found in the warning, print it to cerr.
if (line.find("pb") == std::string::npos) // C++23: `!line.contains("pb")`
std::cerr << line << '\n';
}
}
void print_section(std::string_view const section)
{
std::cout << "### " << section << " ###\n";
std::cerr << "### " << section << " ###\n";
}
int main()
{
print_section("defaults_to_cerr");
defaults_to_cerr();
print_section("redirect_to_cout");
redirect_to_cout();
print_section("redirect_to_file");
redirect_to_file();
print_section("silence_warnings");
silence_warnings();
print_section("filter");
filter();
}
T addressof(T... args)
The SAM format (tag).
Definition format_sam.hpp:105
A class for reading SAM files, both SAM and its binary representation BAM are supported.
Definition sam_file/input.hpp:239
T getline(T... args)
T remove(T... args)
Provides seqan3::sam_file_input and corresponding traits classes.
T temp_directory_path(T... args)

Output to std::cerr:

### defaults_to_cerr ###
Unsupported tag found in SAM header @HD: "pb:5.0.0"
Unsupported tag found in SAM header @HD: "ot:ter"
### redirect_to_cout ###
### redirect_to_file ###
### silence_warnings ###
### filter ###
Unsupported tag found in SAM header @HD: "ot:ter"

Output to std::cout:

### defaults_to_cerr ###
### redirect_to_cout ###
Unsupported tag found in SAM header @HD: "pb:5.0.0"
Unsupported tag found in SAM header @HD: "ot:ter"
### redirect_to_file ###
File content:
Unsupported tag found in SAM header @HD: "pb:5.0.0"
Unsupported tag found in SAM header @HD: "ot:ter"
### silence_warnings ###
### filter ###

This entity is experimental and subject to change in the future. Experimental since version 3.4.


The documentation for this struct was generated from the following file:
Hide me