• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MikkelSchubert / adapterremoval / #101

18 Apr 2025 12:19PM UTC coverage: 67.186% (+1.8%) from 65.404%
#101

push

travis-ci

web-flow
add meta-data class for read serialization (#127)

This simplifies passing of additional information (to be added) that
influences how reads are serialized.

The read_type enum is further more expanded, allowing the file_type
to be derived from the read_type enum by the meta data class.

Test cases were added for the serializers

472 of 531 new or added lines in 8 files covered. (88.89%)

2 existing lines in 1 file now uncovered.

9697 of 14433 relevant lines covered (67.19%)

3063.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.0
/src/serializer.hpp
1
// SPDX-License-Identifier: GPL-3.0-or-later
2
// SPDX-FileCopyrightText: 2024 Mikkel Schubert <mikkelsch@gmail.com>
3
#pragma once
4

5
#include "commontypes.hpp"   // for string_vec, read_type, read_file
6
#include "sequence_sets.hpp" // for sample
7
#include <cstddef>           // for size_t
8
#include <iosfwd>            // for ostream
9

10
namespace adapterremoval {
11

12
class buffer;
13
class fastq;
14
class read_group;
15
enum class output_format;
16

17
/** Class for recording meta-information about reads for serialization */
18
class read_meta
19
{
20
public:
21
  /** Creates read meta-data for the specified read type */
22
  constexpr explicit read_meta(read_type type)
141✔
23
    : m_type(type)
141✔
24
  {
25
  }
141✔
26

27
  /** Returns the file type associated with the read type */
28
  [[nodiscard]] read_file get_file() const noexcept;
29

30
  /** Overwrites the current barcode */
NEW
31
  constexpr auto& barcode(size_t v) noexcept
×
32
  {
NEW
33
    m_barcode = v;
×
NEW
34
    return *this;
×
35
  }
36

37
  /** Creates debug representation of read meta data */
38
  friend std::ostream& operator<<(std::ostream& os, const read_meta& value);
39

40
private:
41
  friend class serializer;
42

43
  read_type m_type{};
44
  //! The barcode for this sample; 0 is also used if not demultiplexing
45
  size_t m_barcode{};
46
};
47

48
class serializer
340✔
49
{
50
public:
51
  explicit serializer(output_format format);
52

53
  /** Set the sample; used to write headers/records for SAM/BAM */
54
  void set_sample(const sample& s) { m_sample = s; }
38✔
55

56
  /** Set the mate separator; used to trim mate information for SAM/BAM */
57
  void set_mate_separator(char value) { m_mate_separator = value; }
6✔
58

59
  /** In demultiplexing only mode, barcodes must always be recorded */
60
  void set_demultiplexing_only(bool value) { m_demultiplexing_only = value; }
22✔
61

62
  void header(buffer& buf, const string_vec& args) const;
63
  void record(buffer& buf, const fastq& record, read_meta meta) const;
64

65
private:
66
  /** Write record to buffer in in FASTQ format */
67
  void fastq_record(buffer& buf,
68
                    const fastq& record,
69
                    const read_meta& meta,
70
                    const sample_sequences& sequences) const;
71

72
  /** Write header to buffer in in SAM format */
73
  static void sam_header(buffer& buf, const string_vec& args, const sample& s);
74
  void sam_record(buffer& buf,
75
                  const fastq& record,
76
                  const read_meta& meta,
77
                  const sample_sequences& sequences) const;
78

79
  /** Write header to buffer in in BAM format (uncompressed) */
80
  static void bam_header(buffer& buf, const string_vec& args, const sample& s);
81
  void bam_record(buffer& buf,
82
                  const fastq& record,
83
                  const read_meta& meta,
84
                  const sample_sequences& sequences) const;
85

86
  //! User specified output format
87
  output_format m_format = output_format::fastq;
88
  //! Sample information to be added to SAM/BAM records
89
  sample m_sample{};
90
  //! Mate separator in processed reads
91
  char m_mate_separator = '\0';
92
  //! Indicates if output has only been demultiplexed but not trimmed
93
  bool m_demultiplexing_only = false;
94
};
95

96
/** Creates debug representation of read meta data */
97
std::ostream&
98
operator<<(std::ostream& os, const read_file& value);
99

100
} // namespace adapterremoval
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc