Skip to content
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

Merged
merged 2 commits into from
Dec 10, 2019

Conversation

smehringer
Copy link
Member

Fixes #1345

*/
enum class sam_flag : uint16_t
{
paired = 0x1, //!< The aligned read is paired (paired-end sequencing).
Copy link
Member

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.

@smehringer smehringer force-pushed the io_misc branch 2 times, most recently from 5793ede to bc87dc4 Compare December 3, 2019 09:47
@codecov
Copy link

codecov bot commented Dec 3, 2019

Codecov Report

Merging #1390 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
include/seqan3/io/alignment_file/input.hpp 100% <ø> (ø) ⬆️
include/seqan3/io/alignment_file/format_bam.hpp 95.72% <ø> (ø) ⬆️
.../seqan3/io/alignment_file/input_format_concept.hpp 100% <ø> (ø) ⬆️
...seqan3/io/alignment_file/output_format_concept.hpp 100% <ø> (ø) ⬆️
include/seqan3/io/alignment_file/format_sam.hpp 98.39% <100%> (+0.01%) ⬆️
include/seqan3/io/alignment_file/output.hpp 100% <100%> (ø) ⬆️
include/seqan3/io/alignment_file/misc.hpp 100% <100%> (ø)
include/seqan3/argument_parser/validators.hpp 88.69% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6eba644...399896e. Read the comment docs.

Copy link
Contributor

@joshuak94 joshuak94 left a 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)

@smehringer
Copy link
Member Author

Since silly combinations are not formalized I would not do any checks by default. We might consider implementing a free function like validate_sam_flags that checks for common mistakes but this will not be part of this PR

@joshuak94 joshuak94 self-requested a review December 3, 2019 11:54
Copy link
Contributor

@joshuak94 joshuak94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Copy link
Contributor

@rrahn rrahn left a 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 💅

include/seqan3/io/alignment_file/format_bam.hpp Outdated Show resolved Hide resolved
@@ -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,
Copy link
Contributor

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here if applicable.

Copy link
Member Author

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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some left over?

Copy link
Member Author

@smehringer smehringer Dec 5, 2019

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>
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch 🙈

@rrahn
Copy link
Contributor

rrahn commented Dec 3, 2019

snippet tests are failing as well.

@smehringer
Copy link
Member Author

Note that I additionally added a debug_stream test for sam_flags since I added an overload.
I also updated the changelog. I need to clean the commit history before merging

@smehringer smehringer requested a review from rrahn December 5, 2019 14:41
Copy link
Contributor

@rrahn rrahn left a 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).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 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.

Copy link
Member Author

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..

Copy link
Member Author

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
Copy link
Contributor

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?

Copy link
Member Author

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))
{
Copy link
Contributor

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(debug_stream_test, sam_flags)
{
std::ostringstream o;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::ostringstream o;
std::ostringstream o{};

@smehringer smehringer requested a review from rrahn December 6, 2019 13:57
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 😄

Copy link
Contributor

@rrahn rrahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Equivalent to Seqan2 BamFlags operations
4 participants