Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Fix IndexFactory.writeIndex for tabix indexes #683
Conversation
coveralls
commented
Aug 12, 2016
yfarjoun
and 1 other
commented on an outdated diff
Aug 23, 2016
| @@ -292,7 +294,9 @@ public static LinearIndex createLinearIndex(final File inputFile, final FeatureC | ||
| public static void writeIndex(final Index idx, final File idxFile) throws IOException { | ||
| LittleEndianOutputStream stream = null; | ||
| try { | ||
| - stream = new LittleEndianOutputStream(new BufferedOutputStream(new FileOutputStream(idxFile))); | ||
| + final OutputStream underlyingStream = (idx instanceof TabixIndex) ? | ||
| + new BlockCompressedOutputStream(idxFile) : new FileOutputStream(idxFile); |
yfarjoun
Contributor
|
|
@yfarjoun, I don't know how to do tests for checking this... |
coveralls
commented
Aug 24, 2016
yfarjoun
commented on an outdated diff
Sep 1, 2016
yfarjoun
commented on an outdated diff
Sep 1, 2016
|
couldn't you test that you can write to a file (and an index is created) and write to a stream (and no exception is thrown)? |
coveralls
commented
Sep 1, 2016
|
@yfarjoun, I added a test to assert that |
|
I also squashed the commits. I think that now that the writing to the file is inside the index, the method |
coveralls
commented
Sep 1, 2016
coveralls
commented
Sep 1, 2016
|
Can you have a look to this, @yfarjoun? It is important for other PR that I'm preparing... |
yfarjoun
was assigned
by droazen
Sep 13, 2016
magicDGS
changed the title from
Fix #430 to Fix IndexFactory.writeIndex for tabix indexes
Sep 13, 2016
|
Could you have a look, @yfarjoun? Thanks in advance! |
| - new LittleEndianOutputStream(new BufferedOutputStream(new FileOutputStream(Tribble.indexFile(featureFile)))); | ||
| - write(idxStream); | ||
| - idxStream.close(); | ||
| + new LittleEndianOutputStream(new BufferedOutputStream(new FileOutputStream(idxFile))); |
magicDGS
Sep 15, 2016
Contributor
It comes from the previous version, but I've just put everything in a single line.
|
@lbergelson could you take a look? we originally reviewed this together. |
coveralls
commented
Sep 15, 2016
lbergelson
requested changes
Sep 15, 2016
| @@ -343,13 +343,19 @@ public void write(final LittleEndianOutputStream stream) throws IOException { | ||
| } | ||
| @Override | ||
| + public void write(final File idxFile) throws IOException { |
lbergelson
Sep 15, 2016
Contributor
@magicDGS Sorry, I didn't notice this before, but this would probably be cleaner as a try-with-resources instead of a try/finally, could you change it?
| @@ -290,16 +287,7 @@ public static LinearIndex createLinearIndex(final File inputFile, final FeatureC | ||
| * @throws IOException | ||
| */ | ||
| public static void writeIndex(final Index idx, final File idxFile) throws IOException { |
lbergelson
Sep 15, 2016
Contributor
I agree that this should be deprecated since it's now unnecessary.
| @@ -201,6 +201,7 @@ public TabixFormat getFormatSpec() { | ||
| * | ||
| * @param tabixFile Where to write the index. | ||
| */ | ||
| + @Override | ||
| public void write(final File tabixFile) { |
lbergelson
Sep 15, 2016
•
Contributor
This seems like it should also be a a try-with-resources. It's weird that that this actually throws a TribbleException and the other writes throw IOException. It seems strangely inconsistent. We can either widen them all to throw IOException or narrow to TribbleException. I think I would lean toward everything throws IOException since that would be the least work. It would be a breaking change for people who are already calling write on a tabix index though. @yfarjoun what's your opinion?
| @@ -112,4 +117,45 @@ public void testCreateTabixIndexOnBlockCompressed() { | ||
| "Tabix indexed (bgzipped) VCF does not contain sequence: " + samSequenceRecord.getSequenceName()); | ||
| } | ||
| } | ||
| + | ||
| + @Test | ||
| + public void testWriteIndex() throws Exception { |
lbergelson
Sep 15, 2016
Contributor
Since this test is in indexFactory.writeIndex() it should probably be testing indexFactory.writeIndex()...
Test for write on the index files themselves should live in TabixIndexTest and LinearIndexTest respectively.
Either way (or both might be the best at the risk of redundantly testing things), TabixIndexTest.readWriteTest provides a good model for how the test might be made. Instead of repeating the code for the different cases you can write a test function that takes a dataprovider with several inputs. It might be a pain though for linear indexes since I don't see a read or equals method on them.
magicDGS
Sep 16, 2016
Contributor
I changed exactly the same method (with a data provider instead) to IndexTest, because I think that it could live in that package (it is testing the interface method for different implementations).
I added a check for the sequence names and properties loaded and written, and a test bed file too.
| + @Test | ||
| + public void testWriteIndex() throws Exception { | ||
| + // temp directory for this test | ||
| + final File tempDir = IOUtil.createTempDir("writeIndex", null); |
lbergelson
Sep 15, 2016
Contributor
I think the standard in htsjdk is to use File output = File.createTempFile() to get your output file, and then call output.deleteOnExit() to make sure it's cleaned up afterwards.
| + final TabixIndex tabixIndexVcfGz = | ||
| + IndexFactory | ||
| + .createTabixIndex(inputFileVcfGz, new VCFCodec(), TabixFormat.VCF, null); | ||
| + // wirte to a file |
|
Addressed comments, @lbergelson. I changed the method to throw Now that I'm looking at the tribble package, I that an issue should be open to review exceptions thrown by the classes. It will be useful for distinguish them. For instance, when I implemented |
|
Tests are failing for FTP issues, @yfarjoun and @lbergelson... |
|
@magicDGS I restarted the tests. I hate those ftp tests. This gets my approval. This is a breaking change with the changes to the exceptions, but I think it's a positive one to make them more consistent. Lets hear what @yfarjoun thinks before merging though. I agree with you that the current state of exceptions is pretty random. It would be good to do an overhaul of them. |
|
a strange test is failing again. otherwise |
|
Oh yeah, that one. #578 strikes again. Restarted. |
coveralls
commented
Sep 16, 2016
lbergelson
merged commit fbba536
into
samtools:master
Sep 16, 2016
magicDGS
deleted the
magicDGS:dgs_issue_430 branch
Sep 17, 2016
|
Thanks for review and accept this change, @yfarjoun and @lbergelson. I also opened an issue to have a look to the exceptions thrown in the package. |
magicDGS commentedAug 12, 2016
No description provided.