-
Notifications
You must be signed in to change notification settings - Fork 13
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
Do not allow unused trailing bytes in BAM records #71
Open
jakobnissen
wants to merge
1
commit into
BioJulia:develop
Choose a base branch
from
jakobnissen:padding
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ mutable struct Record <: XAMRecord | |
next_refid::Int32 | ||
next_pos::Int32 | ||
tlen::Int32 | ||
# variable length data | ||
# This vector never has unused bytes at the end | ||
data::Vector{UInt8} | ||
reader::Union{Reader, Nothing} | ||
|
||
|
@@ -41,7 +41,7 @@ function Base.convert(::Type{Record}, data::Vector{UInt8}) | |
record = Record() | ||
dst_pointer = Ptr{UInt8}(pointer_from_objref(record)) | ||
unsafe_copyto!(dst_pointer, pointer(data), FIXED_FIELDS_BYTES) | ||
dsize = data_size(record) | ||
dsize = record.block_size - FIXED_FIELDS_BYTES + sizeof(record.block_size) | ||
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 calculation occurs more than once. It deserves its own function, which may be separate from |
||
resize!(record.data, dsize) | ||
length(data) < dsize + FIXED_FIELDS_BYTES && throw(ArgumentError("data too short")) | ||
unsafe_copyto!(record.data, 1, data, FIXED_FIELDS_BYTES + 1, dsize) | ||
|
@@ -61,19 +61,19 @@ function Base.:(==)(a::Record, b::Record) | |
a.next_refid == b.next_refid && | ||
a.next_pos == b.next_pos && | ||
a.tlen == b.tlen && | ||
a.data[1:data_size(a)] == b.data[1:data_size(b)] | ||
a.data == b.data | ||
end | ||
|
||
function Base.copy(record::Record) | ||
copy = Record() | ||
GC.@preserve copy record begin | ||
dst_pointer = Ptr{UInt8}(pointer_from_objref(copy)) | ||
cp = Record() | ||
GC.@preserve cp record begin | ||
dst_pointer = Ptr{UInt8}(pointer_from_objref(cp)) | ||
src_pointer = Ptr{UInt8}(pointer_from_objref(record)) | ||
unsafe_copyto!(dst_pointer, src_pointer, FIXED_FIELDS_BYTES) | ||
end | ||
copy.data = record.data[1:data_size(record)] | ||
copy.reader = record.reader | ||
return copy | ||
cp.data = copy(record.data) | ||
cp.reader = record.reader | ||
return cp | ||
end | ||
|
||
function Base.empty!(record::Record) | ||
|
@@ -584,14 +584,7 @@ end | |
# ---------------- | ||
|
||
# Return the size of the `.data` field. | ||
function data_size(record::Record) | ||
if isfilled(record) | ||
return record.block_size - FIXED_FIELDS_BYTES + sizeof(record.block_size) | ||
end | ||
|
||
return 0 | ||
|
||
end | ||
data_size(record::Record) = isfilled(record) ? length(record.data) : 0 | ||
|
||
function checkfilled(record::Record) | ||
if !isfilled(record) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This comment may be confusing outside the context of the previous design, maybe
or something?
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 original comment intended to distinguish the fields that could vary in length from those that do not. From that standpoint, it does not need changing. If you'd like to add a comment specific to a field, perhaps it should go on the same line as the field.