Search in sources :

Example 16 with SeekableByteChannel

use of java.nio.channels.SeekableByteChannel in project gatk by broadinstitute.

the class SeekableByteChannelPrefetcherTest method testPartialBuffers.

@Test
public void testPartialBuffers() throws Exception {
    SeekableByteChannel chan1 = Files.newByteChannel(Paths.get(input));
    SeekableByteChannel chan2 = new SeekableByteChannelPrefetcher(Files.newByteChannel(Paths.get(input)), 1024);
    // get a partial buffer
    testSeeking(chan1, chan2, (int) chan1.size() - 127);
    // make sure normal reads can use the full buffer
    for (int i = 0; i < 2; i++) {
        testSeeking(chan1, chan2, i * 1024);
    }
    // get a partial buffer, replacing one of the full ones
    testSeeking(chan1, chan2, (int) chan1.size() - 127);
    // make sure the buffers are still OK
    for (int i = 0; i < 2; i++) {
        testSeeking(chan1, chan2, i * 1024);
    }
}
Also used : SeekableByteChannel(java.nio.channels.SeekableByteChannel) Test(org.testng.annotations.Test)

Example 17 with SeekableByteChannel

use of java.nio.channels.SeekableByteChannel in project gatk by broadinstitute.

the class SeekableByteChannelPrefetcherTest method testDoubleWrapping.

@Test(expectedExceptions = IllegalArgumentException.class)
public void testDoubleWrapping() throws Exception {
    SeekableByteChannel chan1 = new SeekableByteChannelPrefetcher(Files.newByteChannel(Paths.get(input)), 1024);
    new SeekableByteChannelPrefetcher(chan1, 1024);
}
Also used : SeekableByteChannel(java.nio.channels.SeekableByteChannel) Test(org.testng.annotations.Test)

Example 18 with SeekableByteChannel

use of java.nio.channels.SeekableByteChannel in project gatk by broadinstitute.

the class SeekableByteChannelPrefetcherTest method testEOF.

@Test
public void testEOF() throws Exception {
    SeekableByteChannel chan1 = Files.newByteChannel(Paths.get(input));
    SeekableByteChannel chan2 = new SeekableByteChannelPrefetcher(Files.newByteChannel(Paths.get(input)), 1024);
    // read the final 128 bytes, exactly.
    testSeeking(chan1, chan2, (int) chan1.size() - 128);
    // read truncated because we're asking for beyond EOF
    testSeeking(chan1, chan2, (int) chan1.size() - 64);
    // read starting past EOF
    testSeeking(chan1, chan2, (int) chan1.size() + 128);
    // read more than a whole block past EOF
    testSeeking(chan1, chan2, (int) chan1.size() + 1024 * 2);
}
Also used : SeekableByteChannel(java.nio.channels.SeekableByteChannel) Test(org.testng.annotations.Test)

Example 19 with SeekableByteChannel

use of java.nio.channels.SeekableByteChannel in project gatk by broadinstitute.

the class SeekableByteChannelPrefetcherTest method testSeek.

@Test
public void testSeek() throws Exception {
    SeekableByteChannel chan1 = Files.newByteChannel(Paths.get(input));
    SeekableByteChannel chan2 = new SeekableByteChannelPrefetcher(Files.newByteChannel(Paths.get(input)), 1024);
    testSeeking(chan1, chan2, 1024);
    testSeeking(chan1, chan2, 1500);
    testSeeking(chan1, chan2, 128);
    testSeeking(chan1, chan2, 256);
    testSeeking(chan1, chan2, 128);
    // yes, testReading - let's make sure that reading more than one block still works
    // even after a seek.
    testReading(chan1, chan2, 1500);
    testSeeking(chan1, chan2, 2048);
    testSeeking(chan1, chan2, 0);
    testSeeking(chan1, chan2, 3000);
    testSeeking(chan1, chan2, 6000);
    testSeeking(chan1, chan2, (int) chan1.size() - 127);
    testSeeking(chan1, chan2, (int) chan1.size() - 128);
    testSeeking(chan1, chan2, (int) chan1.size() - 129);
}
Also used : SeekableByteChannel(java.nio.channels.SeekableByteChannel) Test(org.testng.annotations.Test)

Example 20 with SeekableByteChannel

use of java.nio.channels.SeekableByteChannel in project gatk by broadinstitute.

the class GenomicsDBImport method getReaderFromVCFUri.

/**
     * Creates a feature reader object from a given VCF URI (can also be
     * a local file path) and returns it
     * @param variantPath  URI or file path
     * @return  Feature reader
     */
private AbstractFeatureReader<VariantContext, LineIterator> getReaderFromVCFUri(final String variantPath) {
    final String variantURI = IOUtils.getPath(variantPath).toAbsolutePath().toUri().toString();
    final Function<SeekableByteChannel, SeekableByteChannel> cloudWrapper = (cloudPrefetchBuffer > 0 ? is -> SeekableByteChannelPrefetcher.addPrefetcher(cloudPrefetchBuffer, is) : Function.identity());
    final Function<SeekableByteChannel, SeekableByteChannel> cloudIndexWrapper = (cloudIndexPrefetchBuffer > 0 ? is -> SeekableByteChannelPrefetcher.addPrefetcher(cloudIndexPrefetchBuffer, is) : Function.identity());
    return AbstractFeatureReader.getFeatureReader(variantURI, null, new VCFCodec(), true, cloudWrapper, cloudIndexWrapper);
}
Also used : VCFHeaderLine(htsjdk.variant.vcf.VCFHeaderLine) CommandLineProgramProperties(org.broadinstitute.barclay.argparser.CommandLineProgramProperties) java.util(java.util) LineIterator(htsjdk.tribble.readers.LineIterator) VCFHeader(htsjdk.variant.vcf.VCFHeader) Argument(org.broadinstitute.barclay.argparser.Argument) Advanced(org.broadinstitute.barclay.argparser.Advanced) FeatureReader(htsjdk.tribble.FeatureReader) StandardArgumentDefinitions(org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions) GATKException(org.broadinstitute.hellbender.exceptions.GATKException) Function(java.util.function.Function) VariantProgramGroup(org.broadinstitute.hellbender.cmdline.programgroups.VariantProgramGroup) AbstractFeatureReader(htsjdk.tribble.AbstractFeatureReader) GenomicsDBCallsetsMapProto(com.intel.genomicsdb.GenomicsDBCallsetsMapProto) VCFCodec(htsjdk.variant.vcf.VCFCodec) Path(java.nio.file.Path) GenomicsDBImporter(com.intel.genomicsdb.GenomicsDBImporter) IOUtils(org.broadinstitute.hellbender.utils.io.IOUtils) Files(java.nio.file.Files) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) IOException(java.io.IOException) GenomicsDBImportConfiguration(com.intel.genomicsdb.GenomicsDBImportConfiguration) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) GATKTool(org.broadinstitute.hellbender.engine.GATKTool) SeekableByteChannel(java.nio.channels.SeekableByteChannel) UserException(org.broadinstitute.hellbender.exceptions.UserException) SeekableByteChannelPrefetcher(org.broadinstitute.hellbender.utils.nio.SeekableByteChannelPrefetcher) VariantContext(htsjdk.variant.variantcontext.VariantContext) VCFUtils(htsjdk.variant.vcf.VCFUtils) Utils(org.broadinstitute.hellbender.utils.Utils) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ChromosomeInterval(com.intel.genomicsdb.ChromosomeInterval) CommandLineException(org.broadinstitute.barclay.argparser.CommandLineException) SeekableByteChannel(java.nio.channels.SeekableByteChannel) VCFCodec(htsjdk.variant.vcf.VCFCodec)

Aggregations

SeekableByteChannel (java.nio.channels.SeekableByteChannel)130 ByteBuffer (java.nio.ByteBuffer)58 Path (java.nio.file.Path)48 IOException (java.io.IOException)42 Test (org.junit.Test)33 InputStream (java.io.InputStream)14 NoSuchFileException (java.nio.file.NoSuchFileException)12 Test (org.testng.annotations.Test)9 ReadableByteChannel (java.nio.channels.ReadableByteChannel)8 OpenOption (java.nio.file.OpenOption)7 StandardOpenOption (java.nio.file.StandardOpenOption)7 HashSet (java.util.HashSet)7 File (java.io.File)6 FileSystem (java.nio.file.FileSystem)6 CloudStorageFileSystem (com.google.cloud.storage.contrib.nio.CloudStorageFileSystem)5 URI (java.net.URI)5 RandomAccessData (org.apache.beam.runners.dataflow.util.RandomAccessData)5 OutputStream (java.io.OutputStream)4 FileChannel (java.nio.channels.FileChannel)4 WritableByteChannel (java.nio.channels.WritableByteChannel)4