Skip to content

Commit 4501b6e

Browse files
adding tostring() to sam record, used in abismal for parallel writing of sam lines
1 parent 23c6c50 commit 4501b6e

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

sam_record.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ using std::istream;
3333
using std::ostream;
3434
using std::begin;
3535
using std::end;
36+
using std::ostringstream;
3637

3738
// ADS: this is for debugging purposes
3839
string
3940
format_sam_flags(const uint16_t the_flags) {
40-
std::ostringstream oss;
41+
ostringstream oss;
4142
using samflags::check;
4243
oss << "read_paired: " << check(the_flags, samflags::read_paired) << '\n'
4344
<< "read_pair_mapped: "
@@ -72,6 +73,25 @@ format_sam_flags(const uint16_t the_flags) {
7273
// return regex_match(qual, regex("[!-~]+"));
7374
// }
7475

76+
string
77+
sam_rec::tostring() const {
78+
ostringstream oss;
79+
oss << qname << '\t'
80+
<< flags << '\t'
81+
<< rname << '\t'
82+
<< pos << '\t'
83+
<< static_cast<unsigned>(mapq) << '\t'
84+
<< cigar << '\t'
85+
<< rnext << '\t'
86+
<< pnext << '\t'
87+
<< tlen << '\t'
88+
<< seq << '\t'
89+
<< qual;
90+
91+
for (auto it(begin(tags)); it != end(tags); ++it)
92+
oss << '\t' << *it;
93+
return oss.str() + "\n";
94+
}
7595

7696
ostream &
7797
operator<<(std::ostream &the_stream, const sam_rec &r) {
@@ -88,7 +108,7 @@ operator<<(std::ostream &the_stream, const sam_rec &r) {
88108
<< r.qual;
89109

90110
for (auto it(begin(r.tags)); it != end(r.tags); ++it)
91-
the_stream << '\t' << *it;
111+
the_stream << '\t' << *it;
92112
return the_stream;
93113
}
94114

sam_record.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class sam_rec {
117117
seq(_seq),
118118
qual(_qual) {}
119119
void add_tag(const std::string &the_tag) {tags.push_back(the_tag);}
120+
std::string tostring() const;
120121
};
121122

122123
inline bool

0 commit comments

Comments
 (0)