wrap both path and index #785

Merged
merged 4 commits into from Jan 20, 2017

Conversation

Projects
None yet
3 participants
Contributor

jean-philippe-martin commented Jan 11, 2017 edited

Description

Extend optional wrapping to the index.

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)

jean-philippe-martin added some commits Dec 15, 2016

@jean-philippe-martin jean-philippe-martin Add optional wrapper for the underlying SeekableByteChannel
This allows users to provide their own buffering or prefetching, without
them having to change htsjdk.
8bb3e56
@jean-philippe-martin jean-philippe-martin Index wrapper code
6693de6

codecov-io commented Jan 12, 2017 edited

Current coverage is 63.869% (diff: 71.429%)

Merging #785 into master will decrease coverage by 0.013%

@@             master       #785   diff @@
==========================================
  Files           523        523          
  Lines         31643      31640     -3   
  Methods           0          0          
  Messages          0          0          
  Branches       6766       6766          
==========================================
- Hits          20214      20208     -6   
- Misses         9293       9295     +2   
- Partials       2136       2137     +1   

Sunburst

Diff Coverage File Path
••• 33% src/main/java/htsjdk/samtools/SamInputResource.java
•••••••••• 100% src/main/java/htsjdk/samtools/SamReaderFactory.java

Powered by Codecov. Last update 5a9d819...031cee9

jean-philippe-martin referenced this pull request in broadinstitute/gatk Jan 13, 2017

Merged

Add cloud prefetching to GATK #2331

droazen self-assigned this Jan 13, 2017

@droazen

Review complete -- minor comments only, we can merge after they're addressed. Back to @jean-philippe-martin

@@ -82,9 +82,15 @@
abstract public SamReader open(final File file);
public SamReader open(final Path path) {
- final SamInputResource r = SamInputResource.of(path, getPathWrapper());
+ return open(path, getPathWrapper(), Function.identity());
@droazen

droazen Jan 13, 2017

Contributor

It seems like we should use the wrapper returned by getPathWrapper() as the default for both the bam and its index, instead of just the bam?

@jean-philippe-martin

jean-philippe-martin Jan 18, 2017

Contributor

Actually since we've now moved to passing the wrappers explicitly to open, I suggest we remove setPathWrapper. The open call without wrappers will not apply any wrapper, behaving like the other methods that take optional wrapper arguments.

+ return open(path, getPathWrapper(), Function.identity());
+ }
+
+ public SamReader open(final Path path,
@droazen

droazen Jan 13, 2017

Contributor

Add javadoc for both overloads of open() touched in this PR.

+
+ public SamReader open(final Path path,
+ Function<SeekableByteChannel, SeekableByteChannel> pathWrapper,
+ Function<SeekableByteChannel, SeekableByteChannel> indexWrapper) {
@droazen

droazen Jan 13, 2017 edited

Contributor

Is there a use case for having different wrappers for the bam vs. the index? If not, should we just have a single wrapper argument to this constructor that is applied to both (assuming it's not problematic to share wrappers)?

@jean-philippe-martin

jean-philippe-martin Jan 18, 2017

Contributor

It's not problematic to share wrappers (they have no state). Those files are accessed differently, so it would be a great coincidence if the best caching&prefetching for one were also the best for the other.

final Path indexMaybe = SamFiles.findIndex(path);
- if (indexMaybe != null) r.index(indexMaybe);
+ if (indexMaybe != null) r.index(indexMaybe, indexWrapper);
return open(r);
}
@droazen

droazen Jan 13, 2017 edited

Contributor

Is it possible to add a simple unit test for this method that verifies that the provided wrappers are applied (perhaps using a dummy wrapper of some kind)?

@jean-philippe-martin

jean-philippe-martin Jan 19, 2017

Contributor

One way would be to copy the xor wrapper from GATK and check that we can read an XOR'd index.

@jean-philippe-martin

jean-philippe-martin Jan 19, 2017

Contributor

Actually that wouldn't work because the factory only uses the wrappers for things that are not files. Instead I'm doing something simpler and directly calling "asUnbufferedSeekableStream" and checking that the wrapper was accessed.

@jean-philippe-martin jean-philippe-martin Add tests and javadoc
Tested this version with GATK's ReadsDataSourceUnitTest, and it passes.
496dcbf
Contributor

jean-philippe-martin commented Jan 19, 2017

@droazen the code is ready! (Mysteriously, github isn't letting me assign the bug back to you. Perhaps something needs to be done to grant me bug-assigner permissions?)

+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.function.Function;
+import junit.framework.Assert;
@droazen

droazen Jan 20, 2017

Contributor

Should be org.testng.Assert

Contributor

droazen commented Jan 20, 2017

@jean-philippe-martin Looks good, just one import in the tests needs fixing, then I'll hit merge!

@jean-philippe-martin jean-philippe-martin Fix import
031cee9

@droazen droazen merged commit 19bd848 into samtools:master Jan 20, 2017

3 of 4 checks passed

codecov/changes 1 file has unexpected coverage changes not visible in diff.
Details
codecov/patch 71.429% of diff hit (target 63.881%)
Details
codecov/project Absolute coverage decreased by -0.013% but relative coverage increased by +7.547% compared to 5a9d819
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

jean-philippe-martin deleted the jean-philippe-martin:jp_wrap_index branch Jan 25, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment