Skip to content

Commit 9ed0ce4

Browse files
adding general function to write program headers from argc and argv
1 parent 1e9dffd commit 9ed0ce4

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

sam_record.hpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,30 @@ void
149149
inflate_with_cigar(const sam_rec &sr, std::string &to_inflate,
150150
const char inflation_symbol = 'N');
151151

152+
// assumes program name is at argv[0]
153+
template<typename T>
154+
void
155+
write_pg_line(const int argc, const char **argv,
156+
const std::string program_name,
157+
const std::string program_version, T &out) {
158+
out << "@PG\t";
159+
160+
// empty program, should never happen
161+
if (argc == 0) {
162+
out << '\n';
163+
}
164+
else {
165+
if (!program_name.empty())
166+
out << "ID:" << program_name << '\t';
167+
if (!program_version.empty())
168+
out << "VN:" << program_version << '\t';
169+
170+
std::ostringstream the_command;
171+
copy(argv, argv + argc, std::ostream_iterator<const char*>(the_command, " "));
172+
out << "CL:\"" << the_command.str() << "\"" << std::endl;
173+
}
174+
}
175+
152176
template<typename T>
153177
static void
154178
write_sam_header(const std::vector<std::string> &chrom_names,

0 commit comments

Comments
 (0)