-
Notifications
You must be signed in to change notification settings - Fork 82
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 seqan3::sam_flag enum and adapt alignment io. #1390
Conversation
*/ | ||
enum class sam_flag : uint16_t | ||
{ | ||
paired = 0x1, //!< The aligned read is paired (paired-end sequencing). |
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.
Maybe add none
with value zero so it can be initialised and reset without passing {0}
which is not very expressive for an enum.
5793ede
to
bc87dc4
Compare
Codecov Report
@@ Coverage Diff @@
## master #1390 +/- ##
==========================================
+ Coverage 97.53% 97.53% +<.01%
==========================================
Files 228 229 +1
Lines 8731 8735 +4
==========================================
+ Hits 8516 8520 +4
Misses 215 215
Continue to review full report at Codecov.
|
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.
Do you think it would be necessary to implement any sort of checks for legal combinations, or is that better left to the user to not do anything silly. (i.e. 0x40 and 0x80 don't make sense to both be set)
Since silly combinations are not formalized I would not do any checks by default. We might consider implementing a free function like |
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.
Looks good!
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.
looks good. Only minor stuff 💅
@@ -633,7 +651,7 @@ inline void format_sam::write_alignment_record(stream_type & stream, | |||
std::optional<int32_t> ref_offset, | |||
align_type && align, | |||
std::vector<cigar> const & cigar_vector, | |||
uint16_t flag, | |||
sam_flag flag, |
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.
is the flag being modified within the method? If not please mark it const.
@@ -633,7 +651,7 @@ inline void format_sam::write_alignment_record(stream_type & stream, | |||
std::optional<int32_t> ref_offset, | |||
align_type && align, | |||
std::vector<cigar> const & cigar_vector, | |||
uint16_t flag, | |||
sam_flag flag, | |||
uint8_t mapq, |
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.
same here if applicable.
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.
I also changed this in format_bam
@@ -15,7 +15,7 @@ | |||
#include <seqan3/io/alignment_file/input.hpp> | |||
#include <seqan3/io/alignment_file/output.hpp> | |||
#include <seqan3/range/views/take.hpp> | |||
#include <seqan3/test/pretty_printing.hpp> | |||
// #include <seqan3/test/pretty_printing.hpp> |
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.
Some left over?
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.
yes, thanks
#include <iostream> | ||
#include <sstream> | ||
|
||
#include <seqan3/core/type_list/type_list.hpp> |
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.
why do you need type_list?
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.
Good catch 🙈
snippet tests are failing as well. |
Note that I additionally added a debug_stream test for sam_flags since I added an overload. |
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.
some minor stuff left 💅
CHANGELOG.md
Outdated
@@ -58,6 +58,10 @@ If possible, provide tooling that performs the changes, e.g. a shell-script. | |||
* **The `type_list` header has moved:** | |||
If you included `<seqan3/core/type_list.hpp>` you need to change the path to `<seqan3/core/type_list/type_list.hpp>`. | |||
|
|||
#### I/O | |||
|
|||
* The `field::FLAG` of SAM/BAM input and output is not an enum instead of a simple integer (see seqan3::sam_flag). |
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.
* The `field::FLAG` of SAM/BAM input and output is not an enum instead of a simple integer (see seqan3::sam_flag). | |
* The `field::FLAG` of SAM/BAM input and output is now an enum instead of a simple integer (see seqan3::sam_flag). |
This is an API change. Can you please document how this will affect people and how to fix possible compiler errors.
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.
I don't really know what to say here...?
You cannot use integers anymore when writing but you need to static_cast your integers into the respective enum value?
And when you read, well you need to change all your types from integer to sam_flags wherever you use them..
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.
@rrahn ?
@@ -394,7 +395,7 @@ inline void format_bam::read_alignment_record(stream_type & stream, | |||
ref_id = core.refID; // field::REF_ID | |||
} | |||
|
|||
flag = core.flag; // field::FLAG | |||
flag = sam_flag{static_cast<uint16_t>(core.flag)}; // field::FLAG |
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.
why is core.flag not already an uin16_t?
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.
Because I copied the core structure from seqan2 aand I did not know that using bit fields is obsolete if you use the correct integers...
{ | ||
// Check if a certain flag value (bit) is set: | ||
if (static_cast<bool>(seqan3::get<seqan3::field::FLAG>(rec) & seqan3::sam_flag::unmapped)) | ||
{ |
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.
you could remove the braces
test/unit/core/debug_stream_test.cpp
Outdated
|
||
TEST(debug_stream_test, sam_flags) | ||
{ | ||
std::ostringstream o; |
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.
std::ostringstream o; | |
std::ostringstream o{}; |
@@ -395,7 +395,7 @@ inline void format_bam::read_alignment_record(stream_type & stream, | |||
ref_id = core.refID; // field::REF_ID | |||
} | |||
|
|||
flag = sam_flag{static_cast<uint16_t>(core.flag)}; // field::FLAG | |||
flag = core.flag; // field::FLAG |
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.
👍 😄
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.
lgtm
Fixes #1345