Skip to content

Commit e6f581e

Browse files
committed
update sam docu
1 parent e13c5c0 commit e6f581e

File tree

1 file changed

+89
-36
lines changed

1 file changed

+89
-36
lines changed

include/bio/format/sam_input_handler.hpp

Lines changed: 89 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,75 @@
3535
namespace bio
3636
{
3737

38+
/*!\brief Format input handler for the SAM format (bio::sam).
39+
* \ingroup format
40+
* \details
41+
*
42+
* ### Attention
43+
*
44+
* Most users should not perform I/O through input/output handlers but should instead use the respective
45+
* readers/writers. See the overview (TODO link) for more information.
46+
*
47+
* ### Options
48+
*
49+
* The following options are considered if the respective member variable is availabele in the object passed to
50+
* the constructor:
51+
*
52+
* | Member | Type | Default | Description |
53+
* |-----------------|---------|---------|------------------------------------------------------------------|
54+
* |`print_warnings` |`bool` | `false` | Whether to print non-critical warnings to seqan3::debug_stream |
55+
*
56+
*/
3857
template <>
3958
class format_input_handler<sam> : public format_input_handler_base<format_input_handler<sam>>
4059
{
4160
private:
42-
/* CRTP */
61+
/*!\name CRTP related entities
62+
* \{
63+
*/
64+
//!\brief The type of the CRTP base class.
4365
using base_t = format_input_handler_base<format_input_handler<sam>>;
66+
using base_t::parse_field;
67+
using base_t::parse_field_aux;
4468
using base_t::stream;
4569

70+
//!\brief Befriend the base class to enable CRTP.
4671
friend base_t;
72+
//!\}
4773

48-
//!\brief Default field handlers.
49-
using base_t::parse_field;
50-
using base_t::parse_field_aux;
74+
/*!\name Options
75+
* \{
76+
*/
77+
//!\brief Whether to print warnings or not.
78+
bool print_warnings = true;
79+
//!\}
80+
81+
//!\brief Throw a bio::format_error with an error message with current line number in diagnostic.
82+
[[noreturn]] void error(auto const &... messages) const
83+
{
84+
std::string message = "[B.I.O sam format error in line " + detail::to_string(line) + "] ";
85+
((message += detail::to_string(messages)), ...);
86+
87+
throw format_error{message};
88+
}
89+
90+
//!\brief Print a B.I.O warning message with current line number in diagnostic.
91+
/* [[noreturn]] compiler says this returns something...? */ void warning(auto const &... messages) const
92+
{
93+
if (print_warnings)
94+
{
95+
seqan3::debug_stream << "[B.I.O sam format warning in line " << line << "] ";
96+
(seqan3::debug_stream << ... << messages);
97+
seqan3::debug_stream << std::endl;
98+
}
99+
}
51100

52-
/* RAW RECORD HANDLING*/
101+
/*!\name Raw record handling
102+
* \{
103+
*/
104+
//!\brief The fields that this format supports [the base class accesses this type].
53105
using format_fields = decltype(map_io::default_field_ids);
106+
//!\brief Type of the raw record.
54107
using raw_record_type = bio::record<format_fields,
55108
seqan3::list_traits::repeat<format_fields::size, std::string_view>>;
56109

@@ -69,27 +122,8 @@ class format_input_handler<sam> : public format_input_handler_base<format_input_
69122
int32_t last_rname_idx = -1;
70123
//!\brief Current line number in file.
71124
size_t line = 0;
72-
//!\brief Whether to print print_warnings or not.
73-
bool print_warnings = true;
74-
75-
[[noreturn]] void error(auto const &... messages) const
76-
{
77-
std::string message = "[B.I.O sam format error in line " + detail::to_string(line) + "] ";
78-
((message += detail::to_string(messages)), ...);
79-
80-
throw format_error{message};
81-
}
82-
83-
/* [[noreturn]] compiler says this returns something...? */ void warning(auto const &... messages) const
84-
{
85-
if (print_warnings)
86-
{
87-
seqan3::debug_stream << "[B.I.O sam format warning in line " << line << "] ";
88-
(seqan3::debug_stream << ... << messages);
89-
seqan3::debug_stream << std::endl;
90-
}
91-
}
92125

126+
//!\brief Read the raw record [the base class invokes this function].
93127
void read_raw_record()
94128
{
95129
++line;
@@ -116,9 +150,12 @@ class format_input_handler<sam> : public format_input_handler_base<format_input_
116150
// SAM tags go from end of qual til end of line (possibly empty)
117151
get<field::tags>(raw_record) = std::string_view{end_qual, static_cast<size_t>(end_line - end_qual)};
118152
}
153+
//!\}
119154

120-
/* PARSED RECORD HANDLING */
121-
155+
/*!\name Parsed record handling
156+
* \brief This is mostly done via the defaults in the base class.
157+
* \{
158+
*/
122159
//!\brief Overload for parsing QNAME.
123160
template <typename parsed_field_t>
124161
void parse_field(vtag_t<field::qname> const & /**/, parsed_field_t & parsed_field)
@@ -264,18 +301,29 @@ class format_input_handler<sam> : public format_input_handler_base<format_input_
264301
{
265302
parsed_field = map_io::record_private_data{.header_ptr = &header};
266303
}
304+
//!\}
267305

268306
public:
269-
format_input_handler() = default;
270-
format_input_handler(format_input_handler const &) = delete;
271-
format_input_handler(format_input_handler &&) = default;
272-
format_input_handler & operator=(format_input_handler const &) = delete;
273-
format_input_handler & operator=(format_input_handler &&) = default;
274-
307+
/*!\name Constructors, destructor and assignment.
308+
* \{
309+
*/
310+
format_input_handler() = default; //!< Defaulted.
311+
format_input_handler(format_input_handler const &) = delete; //!< Deleted.
312+
format_input_handler(format_input_handler &&) = default; //!< Defaulted.
313+
~format_input_handler() = default; //!< Defaulted.
314+
format_input_handler & operator=(format_input_handler const &) = delete; //!< Deleted.
315+
format_input_handler & operator=(format_input_handler &&) = default; //!< Defaulted.
316+
317+
/*!\brief Construct with an options object.
318+
* \param[in,out] str The input stream.
319+
* \param[in] options An object with options for the input handler.
320+
* \details
321+
*
322+
* The options argument is typically bio::map_io::reader_options, but any object with a subset of similarly named
323+
* members is also accepted. See bio::format_input_handler<vcf> for the supported options and defaults.
324+
*/
275325
template <typename options_t>
276-
format_input_handler(std::istream & str, options_t const & options) :
277-
base_t{str},
278-
file_it{str, false /*no_init!*/}
326+
format_input_handler(std::istream & str, options_t const & options) : base_t{str}, file_it{str, false /*no_init!*/}
279327
{
280328
// extract options
281329
if constexpr (requires { (bool)options.print_warnings; })
@@ -296,6 +344,11 @@ class format_input_handler<sam> : public format_input_handler_base<format_input_
296344
header.read(header_string);
297345
}
298346

347+
//!\brief Construct with only an input stream.
348+
format_input_handler(std::istream & str) : format_input_handler{str, int{}} {}
349+
//!\}
350+
351+
//!\brief Return a reference to the header contained in the input handler.
299352
auto const & get_header() const { return header; }
300353
};
301354

0 commit comments

Comments
 (0)