-
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 implementation reports validation errors at container granularity #1091
Changes from 2 commits
410011b
92c7ccd
c672c65
cba9220
cb13b65
c77ba65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package htsjdk.samtools; | ||
|
||
import htsjdk.HtsjdkTest; | ||
import htsjdk.samtools.cram.ref.ReferenceSource; | ||
import htsjdk.samtools.seekablestream.SeekableStream; | ||
import org.junit.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.File; | ||
|
||
|
||
/** | ||
* This test serve for verifying CRAMIterator records validation using strict validation strategy | ||
* | ||
* @author [email protected], EPAM Systems, Inc. | ||
**/ | ||
|
||
public class CRAMIteratorTest extends HtsjdkTest { | ||
|
||
@Test(description = "This test checks that records validation is deferred until they are retrieved") | ||
public void notThrowOnOpeningContainerWithInvalidRecords() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe rename this to "noValidationFailureOnContainerOpen". |
||
final File refFile = new File("src/test/resources/htsjdk/samtools/cram/ce.fa"); | ||
final File cramFileWithInvalidRecs = new File("src/test/resources/htsjdk/samtools/cram/ce#containsInvalidRecords.3.0.cram"); | ||
final ReferenceSource source = new ReferenceSource(refFile); | ||
final SAMRecordIterator cramIteratorOverInvalidRecords = | ||
getCramFileIterator(cramFileWithInvalidRecs, source, ValidationStringency.STRICT); | ||
|
||
Assert.assertTrue(cramIteratorOverInvalidRecords.hasNext()); | ||
cramIteratorOverInvalidRecords.close(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SAMRecordIterator is closable, so you should be able to use try-with-resources here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cmnbroad Hello! Thank you for review, requested changes are done |
||
} | ||
SathemBite marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@Test(expectedExceptions = SAMException.class) | ||
public void throwOnRecordValidationFailure() { | ||
final File refFile = new File("src/test/resources/htsjdk/samtools/cram/ce.fa"); | ||
final File cramFileWithInvalidRecs = new File("src/test/resources/htsjdk/samtools/cram/ce#containsInvalidRecords.3.0.cram"); | ||
final ReferenceSource source = new ReferenceSource(refFile); | ||
final SAMRecordIterator cramIteratorOverInvalidRecords = | ||
getCramFileIterator(cramFileWithInvalidRecs, source, ValidationStringency.STRICT); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most of the code up to this point is duplicated in both test methods. Can you factor that out (maybe into |
||
try{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. try-with-resources |
||
while (cramIteratorOverInvalidRecords.hasNext()) { | ||
cramIteratorOverInvalidRecords.next(); | ||
} | ||
} finally { | ||
cramIteratorOverInvalidRecords.close(); | ||
} | ||
} | ||
|
||
private SAMRecordIterator getCramFileIterator(File cramFile, | ||
ReferenceSource source, | ||
ValidationStringency valStringency) { | ||
|
||
final CRAMFileReader cramFileReader = new CRAMFileReader(cramFile, (SeekableStream) null, source); | ||
cramFileReader.setValidationStringency(valStringency); | ||
return cramFileReader.getIterator(); | ||
} | ||
} |
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.
Since
samRecordIndex
is a class not a local variable, can you add a comment to the declaration saying that it is only used when Validation Stringency is not SILENT, and otherwise it isn't valid. (this was always true even before this PR, but it would be good to make that clear).