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

Test ContainerIO.calculateSliceOffsetsAndSizes() and fix the slice size calculation #1326

Merged
merged 1 commit into from
Mar 19, 2019

Conversation

jmthibault79
Copy link
Contributor

@jmthibault79 jmthibault79 commented Mar 14, 2019

Description

Problem:
calculateSliceOffsetsAndSizes() was calculating Slice.size incorrectly.

Impact:
Slices created via ContainerIO.readContainer() would produce incorrect sliceByteSize values for their CRAI entries.

Checklist

  • Code compiles correctly
  • New tests covering changes and new functionality
  • All tests passing
  • Extended the README / documentation, if necessary
  • Is not backward compatible (breaks binary or source compatibility)

}
final Slice lastSlice = container.slices[container.slices.length - 1];
lastSlice.offset = container.landmarks[container.landmarks.length - 1];
lastSlice.size = container.containerByteSize - lastSlice.offset;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was the error

@codecov-io
Copy link

codecov-io commented Mar 14, 2019

Codecov Report

Merging #1326 into master will increase coverage by 0.018%.
The diff coverage is 91.304%.

@@               Coverage Diff               @@
##              master     #1326       +/-   ##
===============================================
+ Coverage     67.804%   67.822%   +0.018%     
- Complexity      8252      8253        +1     
===============================================
  Files            562       562               
  Lines          33641     33644        +3     
  Branches        5639      5640        +1     
===============================================
+ Hits           22810     22818        +8     
+ Misses          8658      8654        -4     
+ Partials        2173      2172        -1
Impacted Files Coverage Δ Complexity Δ
...va/htsjdk/samtools/cram/structure/ContainerIO.java 62.5% <100%> (+0.772%) 12 <0> (-1) ⬇️
...java/htsjdk/samtools/cram/structure/Container.java 90.476% <90%> (-0.149%) 22 <2> (+2)

Copy link
Collaborator

@cmnbroad cmnbroad left a comment

Choose a reason for hiding this comment

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

Good catch - thx. A few comments/questions.

for (int i = 0; i < container.slices.length - 1; i++) {
static void calculateSliceOffsetsAndSizes(final Container container) {
if (container.slices.length == 0) {
return;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is a legitimate case where this can happen ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

What happens if this is called with a container with a slice with an unmapped reference context ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Q1: Yes - if this is the BAM File Header container.

Q2: none of these values relate to alignment, so there should be no difference there.

// the container's header size = 9000
// Slice[0].offset = 9000
// Slice[0].size = 109000 - 9000 = 100000
// Slice[1].offset = 109000
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you.

// this Container consists of:
// a header of size 1234 bytes
// a Slice of size 789 bytes
// a Slice of size 5555 bytes
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs to also have a test for the most common case we expect to see, which is a Container with a single, single-reference slice. And also a test with an unmapped reference context slice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add one for single slice.

Not sure about changing Ref Context because it's irrelevant to this test.

Copy link
Collaborator

@cmnbroad cmnbroad left a comment

Choose a reason for hiding this comment

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

One comment on using better names for the tests, otherwise looks good now.

@cmnbroad cmnbroad assigned jmthibault79 and unassigned cmnbroad Mar 18, 2019
…ze calculation

move ContainerIO.calculateSliceOffsetsAndSizes() to
- Container.populateSlicesAndIndexingParameters()
@jmthibault79 jmthibault79 merged commit a82d8ba into master Mar 19, 2019
@jmthibault79 jmthibault79 deleted the jt_slice_size_fix branch March 19, 2019 14:46
jmthibault79 added a commit that referenced this pull request Apr 1, 2019
- added comments clarifying the real situation
- see samtools/hts-specs#396
- see samtools/hts-specs#398
jmthibault79 added a commit that referenced this pull request Apr 3, 2019
* Revert #1326 because it was correct before
- added comments clarifying the real situation
- see samtools/hts-specs#396
- see samtools/hts-specs#398
- comments and rename CRAIEntry.sliceByteOffset
- blockCount comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants