-
Notifications
You must be signed in to change notification settings - Fork 242
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
CRAM: Immutable Block #1231
CRAM: Immutable Block #1231
Conversation
@@ -169,21 +168,13 @@ private static Slice buildSlice(final List<CramCompressionRecord> records, | |||
writer.writeCramCompressionRecords(records, slice.alignmentStart); | |||
|
|||
bitOutputStream.close(); | |||
slice.coreBlock = Block.buildNewCore(bitBAOS.toByteArray()); | |||
slice.coreBlock = Block.buildNewCoreBlock(bitBAOS.toByteArray()); |
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.
renamed for consistency with other static methods
switch (method) { | ||
case RAW: | ||
return compressedContent; | ||
case GZIP: |
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's an opportunity for refactoring the compression classes here. Leaving alone for this PR.
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.
Yeah, definitely should do that in a subsequent round. Especially since ExternalCompressor
already has compress
methods for each compression type, and the compress/decompress implementations should live together. Maybe BlockCompressionMethod
should just have compress/uncompress methods directly, and this method and ExternalCompressor
can go away.
@@ -1,323 +0,0 @@ | |||
/** |
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.
Moved to htsjdk.samtools.cram.structure.block.Block
* limitations under the License. | ||
* **************************************************************************** | ||
*/ | ||
package htsjdk.samtools.cram.structure.block; |
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.
moved from package htsjdk.samtools.cram.structure
@@ -0,0 +1,234 @@ | |||
/** |
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.
Block is now the abstract base class for the 2 concrete implementations RawBlock
and CompressibleBlock
* @param rawContent the uncompressed content of the block | ||
* @return a new file header {@link RawBlock} object | ||
*/ | ||
public static RawBlock buildNewFileHeaderBlock(final byte[] rawContent) { |
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.
alternate implementation: FileHeaderBlock
, CoreBlock
, etc classes
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 was kind of thinking the same thing, but are there any other differences in their behavior (besides the raw/compressed) type of block and the content type) - would there be other useful methods with different implementations ?
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.
If we do keep these, maybe the subclass constructors should be protected so this is basically the block factory and is the only way to create blocks ?
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 found a way to make this work well (including the static factory) and I'll be committing in a moment.
src/main/java/htsjdk/samtools/cram/structure/block/CompressibleBlock.java
Outdated
Show resolved
Hide resolved
src/main/java/htsjdk/samtools/cram/structure/block/CompressibleBlock.java
Outdated
Show resolved
Hide resolved
src/main/java/htsjdk/samtools/cram/structure/block/RawBlock.java
Outdated
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## master #1231 +/- ##
===============================================
+ Coverage 69.323% 69.378% +0.055%
- Complexity 8105 8107 +2
===============================================
Files 543 544 +1
Lines 32480 32437 -43
Branches 5501 5496 -5
===============================================
- Hits 22516 22504 -12
+ Misses 7755 7732 -23
+ Partials 2209 2201 -8
|
final byte[] compressedContent) { | ||
super(type); | ||
|
||
if (type == BlockContentType.EXTERNAL && contentId == Block.NO_CONTENT_ID) { |
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 check is causing many test failures - I'm investigating.
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.
Removed this check and opened #1232
31ed5a8
to
8095ea2
Compare
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.
A few stream of consciousness questions and comments since - see what you think.
switch (method) { | ||
case RAW: | ||
return compressedContent; | ||
case GZIP: |
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.
Yeah, definitely should do that in a subsequent round. Especially since ExternalCompressor
already has compress
methods for each compression type, and the compress/decompress implementations should live together. Maybe BlockCompressionMethod
should just have compress/uncompress methods directly, and this method and ExternalCompressor
can go away.
* @param rawContent the uncompressed content of the block | ||
* @return a new file header {@link RawBlock} object | ||
*/ | ||
public static RawBlock buildNewFileHeaderBlock(final byte[] rawContent) { |
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 was kind of thinking the same thing, but are there any other differences in their behavior (besides the raw/compressed) type of block and the content type) - would there be other useful methods with different implementations ?
* @param rawContent the uncompressed content of the block | ||
* @return a new file header {@link RawBlock} object | ||
*/ | ||
public static RawBlock buildNewFileHeaderBlock(final byte[] rawContent) { |
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.
If we do keep these, maybe the subclass constructors should be protected so this is basically the block factory and is the only way to create blocks ?
src/main/java/htsjdk/samtools/cram/structure/block/RawBlock.java
Outdated
Show resolved
Hide resolved
src/main/java/htsjdk/samtools/cram/structure/block/CompressibleBlock.java
Outdated
Show resolved
Hide resolved
@jmthibault79 Was just looking at this again - is it ready for review (wasn't sure if you were still making changes) ? |
@cmnbroad ready for re-review now, after the subclasses commit |
@jmthibault79 I still feel like we don't have the What do you think about this proposal: go back to just Then in subsequent PRs, we can create classes that model things like |
f59abd0
to
8f9e6af
Compare
I see your point about the hierarchy. Here's another attempt, with |
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.
@jmthibault79 I think the hierarchy is a lot better now, but I still have some suggestions for potential changes. Hopefully they make sense - if not let me know what you think since I don't want to hold this up indefinitely.
…nMethod/contentType
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.
Mostly there now, a few more minor comments and this should be good to merge.
src/main/java/htsjdk/samtools/cram/structure/CompressionHeader.java
Outdated
Show resolved
Hide resolved
src/main/java/htsjdk/samtools/cram/structure/block/ExternalBlock.java
Outdated
Show resolved
Hide resolved
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.
A couple more suggestions, for either this PR or for the next one, since we've beat this one to a pulp. @lbergelson let us know if you also want to review this.
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.
👍
Description
Refactoring CRAM code for future maintainability
Checklist