-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE] Add filedate to VCF file #30
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,9 @@ | |
|
||
#pragma once | ||
|
||
#include <chrono> | ||
#include <ctime> | ||
#include <iomanip> | ||
#include <map> | ||
#include <regex> | ||
#include <string> | ||
|
@@ -163,6 +166,7 @@ class header | |
* \{ | ||
*/ | ||
std::string file_format = "VCFv4.3"; //!< The file format version. | ||
std::string file_date = transTime(); //!< The file date. | ||
std::vector<filter_t> filters; //!< Header lines describing FILTER fields. | ||
std::vector<info_t> infos; //!< Header lines describing INFO fields. | ||
std::vector<format_t> formats; //!< Header lines describing FORMAT fields. | ||
|
@@ -214,6 +218,19 @@ class header | |
/*!\name Update, reset and inspect | ||
* \{ | ||
*/ | ||
/*! \brief Gets the current time and transforms it in a nice readable way for the vcf header line fileDate. | ||
* | ||
* \returns a time string in the format: YYYY-MM-DD HH:MM:SS. | ||
*/ | ||
std::string transTime() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function seems a little bit out-of-place here, because it is a generic "make a nice date"-function and not specific I am also not sure what the name implies? 🏳️⚧️ 🕐 ? 😉 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh that was just a name copy of some funktions I found in the wild wild web.. 🙈 If we ceep the function, we can of course rename it to transformTime for example. |
||
{ | ||
std::stringstream text_stream; | ||
const std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now(); | ||
const std::time_t rawtime = std::chrono::system_clock::to_time_t(now); | ||
text_stream << std::put_time(std::localtime(&rawtime), "%F %T"); | ||
std::string time_string = text_stream.str(); | ||
return time_string; | ||
} | ||
/*!\brief Add missing IDX fields to header entries and ensure that everything has proper hash-entries. | ||
* | ||
* \details | ||
|
@@ -478,6 +495,9 @@ class header | |
// file format | ||
((raw_data += "##fileformat=") += file_format) += "\n"; | ||
|
||
// file date | ||
((raw_data += "##fileDate=") += file_date) += "\n"; | ||
|
||
// filters | ||
for (auto const & filter : filters) | ||
{ | ||
|
@@ -611,6 +631,10 @@ class header | |
{ | ||
throw format_error{"File has two lines that begin with \"##fileformat\"."}; | ||
} | ||
else if (l.starts_with("##fileDate=")) | ||
{ | ||
parse_file_date_line(l.substr(11)); | ||
} | ||
else if (l.starts_with("##INFO=")) | ||
{ | ||
parse_info_or_format_line(strip_angular_brackets(l.substr(7)), true); | ||
|
@@ -641,6 +665,12 @@ class header | |
} | ||
} | ||
|
||
//!\brief Parse an INFO or FORMAT line. | ||
void parse_file_date_line(std::string_view const l) | ||
{ | ||
file_date = static_cast<std::string>(l); | ||
} | ||
|
||
//!\brief Parse an INFO or FORMAT line. | ||
void parse_info_or_format_line(std::string_view const l, bool const is_info) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having file_date as an extra member seems like a good thing! However, I am not sure if I want it to be set automatically, because this results in output not being reproducible by default, which is really annoying when you are checking whether output has changed or not.
Related to this question is also whether BIO should add a line that says that the file was created with BIO. On the one hand, I would like this (advertising for the library); on the other hand, I am often annoyed by bcftools adding so many of those lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So another solution would be to add a field which will be set by the user, e.g. the transTime() function would move to iGenVar. Would also be fine for me.
To your related question, I understand the desire to promote the library, but the important question should be whether it helps the user. At first I thought no, because why do I need to know who created it, since I am interested in the results from the tool itself. But then I thought if I don't understand a VCF line or there are errors in it (something like that) I might want to contact BIO instead of the tool creator that just uses the library. Hmm...