-
Notifications
You must be signed in to change notification settings - Fork 594
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
TableReader and TableWriter take in a Path #5785
Conversation
Codecov Report
@@ Coverage Diff @@
## master #5785 +/- ##
===============================================
+ Coverage 87.003% 87.029% +0.027%
- Complexity 32091 32104 +13
===============================================
Files 1975 1972 -3
Lines 147184 147187 +3
Branches 16228 16201 -27
===============================================
+ Hits 128054 128096 +42
+ Misses 13225 13184 -41
- Partials 5905 5907 +2
|
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.
Just a few minor comments on the CNV code from me, I'll leave the rest up to another reviewer. Thanks for doing this!
try { | ||
final LineReader lineReader = new BufferedLineReader(Files.newInputStream(path)); | ||
return new SAMTextHeaderCodec().decode(lineReader, getSource()); | ||
} catch (IOException ex) { |
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.
We typically make the final explicit (probably for no practical reason other than style).
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.
Thank you for the compliment! I'm guessing you mean the IOException
variable? Done.
@@ -1,5 +1,6 @@ | |||
package org.broadinstitute.hellbender.utils.mcmc; | |||
|
|||
import java.nio.file.Path; |
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.
OK to delete this and ParameterWriter, I believe they are dead code.
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 compiler agrees with your assessment. Deleted!
Checks passed, most excellent! |
All subclasses do the same. This involves updating all callers to pass a Path instead of a File. Fixes #5747
Also, update the newly-written code to use Path instead of File. We're in a race of sorts, it seems.
967f4a2
to
e4f290c
Compare
Conflict resolved. @samuelklee if you don't mind my asking, could we please try to have a prompt review cycle? This change touches a lot of files, some of which are under active development (as evidenced by the fact we got a conflict already). We're in a race between people writing new code that uses |
Great, just spoke to @lbergelson @jamesemery and someone from engine team will try to get this turned around quick. Thanks again! |
A unit test with Jimfs, so it's fast but still checks that we're not converting the Path to a File along the way.
Great, thank you! I'm no longer adding code, you can have a look. |
It looks like the regression test failed due to some connectivity blip:
In the hope it's transient, could you please restart it? |
@jean-philippe-martin Restarted |
Thank you @droazen ! It passed this time, yay! |
@cmnbroad if you could please review this code (if you haven't started already)? I'd like to get it in before one of the many touched files gets modified (or more subclasses get created and follow the bad example of using a |
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.
Looks pretty good - a few minor changes requested.
...broadinstitute/hellbender/tools/copynumber/formats/collections/AbstractRecordCollection.java
Outdated
Show resolved
Hide resolved
@@ -186,16 +187,17 @@ public static void writeOrientationBiasSummaryTable(final List<Pair<String, Tran | |||
final Function<DataLine, T> dataLineToSummaryFunction) { | |||
Utils.nonNull(inputFile); | |||
IOUtils.canReadFile(inputFile); | |||
Path inputPath = IOUtils.fileToPath(inputFile); |
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.
final
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.
Good catch, done.
src/test/java/org/broadinstitute/hellbender/utils/hmm/HMMUnitTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/broadinstitute/hellbender/utils/tsv/TableReaderUnitTest.java
Outdated
Show resolved
Hide resolved
return testFile; | ||
} | ||
|
||
private Path createTestInputInMemory(final java.nio.file.FileSystem ramfs, final String... lines) throws IOException { |
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.
Rather than adding a new "create" method with a FileSystem
arg, add createTestInputOnPath
with a Path
arg, and have createTestInput
pass a Path
to that method. Then the jimfs test above can create the jimfs file directly and pass the pathto createTestInputOnPath
. All the jimfs code will be confined to that one test, and fillTestInput can go away:
private Path createTestInputInMemory(final java.nio.file.FileSystem ramfs, final String... lines) throws IOException { | |
private Path createTestInput(final String... lines) throws IOException { | |
final Path testFile = createTempPath("test", ".tab"); | |
return createTestInputOnPath(testFile, lines); | |
} | |
private Path createTestInputOnPath(Path testPath, final String... lines) throws IOException { | |
try (final PrintWriter testWriter = new PrintWriter(Files.newBufferedWriter(testPath));) { | |
for (final String line : lines) { | |
testWriter.println(line); | |
} | |
} | |
return testPath; | |
} |
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.
OK, done! I didn't merge your suggestion (because that would undo the try-with-resources I just put in), but I copied it by hand and you should see it match in spirit.
src/test/java/org/broadinstitute/hellbender/utils/tsv/TableWriterUnitTest.java
Outdated
Show resolved
Hide resolved
|
||
/** | ||
* Check that TableWriter can accept paths that have no corresponding File | ||
* on the local disk. |
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.
Nit perhaps, but can you update this comment as it seems misleading. The purpose of the test is to show that paths on installed NIO file system providers work; the fact that its using an in-memory file system with no on disk representation seems incidental.
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.
No problem. The intent was to say "check that this code doesn't try to convert the Path
back to a File
" (which you could do if the Path represented a file), I changed the text to be hopefully clearer.
Thank you @cmnbroad for the excellent review! I've applied all the changes, let's see how Travis likes them. |
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.
Thanks for taking this one on @jean-philippe-martin.
All subclasses do the same.
This involves updating all callers to pass a
Path
instead of aFile
.Added a test in
TableUtilsUnitTest
that writes a table to an in-memoryPath
to demonstrate we're not using files underneath (it works). Added a similar test inTableReaderUnitTest
that reads from an in-memoryPath
.Fixes #5747