Skip to content

Disallow tabix indices for non-BGZIP inputs - #1101

Open
lbergelson wants to merge 3 commits into
masterfrom
jamesemery-je_PatchGZippedIndexStreamBug
Open

Disallow tabix indices for non-BGZIP inputs#1101
lbergelson wants to merge 3 commits into
masterfrom
jamesemery-je_PatchGZippedIndexStreamBug

Conversation

@lbergelson

Copy link
Copy Markdown
Member

Description

rebased copy of #1079

*/
public WFIterator() throws IOException {
final InputStream inputStream = ParsingUtils.openInputStream(path, wrapper);
final InputStream inputStream = new BufferedInputStream(ParsingUtils.openInputStream(path, wrapper), 512000);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what's this magic number? can it be named as a constant?

Assert.assertEquals(featureReader.query("2", 190, 210).toList().size(), 1);
Function<SeekableByteChannel, SeekableByteChannel> indexWrapper,
boolean useTribbleReader) throws IOException, URISyntaxException {
if (index!=null) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

spaces

// Test for tabix index
if (methods.isTabix(featureResource, indexResource)) {
// Test for BGZF formatted file
if (methods.isTabix(featureResource, SeekableStreamFactory.getInstance().getBufferedStream(SeekableStreamFactory.getInstance().getStreamFor(featureResource, wrapper)), indexResource)) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

lets extract this stream creation and put it in the try () if possible

return hasBlockCompressedExtension(resourcePath) && ParsingUtils.resourceExists(indexPath);
boolean isBGZF = isBGZFFile(inputStream);
boolean hasIndex = ParsingUtils.resourceExists(indexPath);
if (hasIndex && !isBGZF && indexPath.endsWith(TabixUtils.STANDARD_INDEX_EXTENSION)) {

@lbergelson lbergelson Mar 20, 2018

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this seems wrong to throw in the isTabix method

Assert.assertEquals(count, 12218);
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

extra NL

@yfarjoun

Copy link
Copy Markdown
Contributor

could you use a non-compressed VCF input and compress it in the different ways you want as part of the tests?


public static boolean isTabix(String resourcePath, String indexPath) throws IOException {
if(indexPath == null){
try (SeekableStream inputStream = SeekableStreamFactory.getInstance().getStreamFor(resourcePath)) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

if this throws IOException it's better to just propagate it rather than suppress it to false I think.

@droazen droazen changed the title rebase https://github.com/samtools/htsjdk/pull/1079 Disallow tabix indices for non-BGZIP inputs Apr 17, 2018
@yfarjoun

yfarjoun commented Jul 2, 2018

Copy link
Copy Markdown
Contributor

bump

@yfarjoun

yfarjoun commented Jul 8, 2019

Copy link
Copy Markdown
Contributor

split out the buffered index part so that we can think harder about the exception throwing...

@lbergelson lbergelson self-assigned this Jul 29, 2019
public static boolean isTabix(String resourcePath, String indexPath) throws IOException {
if(indexPath == null){
try (SeekableStream inputStream = SeekableStreamFactory.getInstance().getStreamFor(resourcePath)) {
return isTabix(resourcePath, inputStream,indexPath);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
return isTabix(resourcePath, inputStream,indexPath);
return isTabix(resourcePath, inputStream, indexPath);

boolean isBGZF = isBGZFFile(inputStream);
boolean hasIndex = ParsingUtils.resourceExists(indexPath);
if (hasIndex && !isBGZF && indexPath.endsWith(TabixUtils.STANDARD_INDEX_EXTENSION)) {
throw new TribbleException(String.format("Detected Tabix index for file %s, but the file does not appear to be compressed in BGZF format", resourcePath));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How about you return false here and log a warning explaining the situation?

@yfarjoun

Copy link
Copy Markdown
Contributor

what's going on with this PR? it has conflicts and no responses to review comments.

@yfarjoun yfarjoun added the Waiting for revisions This PR has received comments from reviewers and is waiting for the Author to respond label Sep 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug tribble Waiting for revisions This PR has received comments from reviewers and is waiting for the Author to respond

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants