Search in sources :

Example 1 with LineIterator

use of htsjdk.tribble.readers.LineIterator 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)

Example 2 with LineIterator

use of htsjdk.tribble.readers.LineIterator in project gatk by broadinstitute.

the class TableCodecUnitTest method testDecodeFailsNoHeader.

@Test(expectedExceptions = UserException.MalformedFile.class)
public void testDecodeFailsNoHeader() {
    TableCodec tc = new TableCodec();
    LineReader reader = makeReader(asList("1:1  1   2   3"));
    LineIterator li = new LineIteratorImpl(reader);
    tc.readActualHeader(li);
}
Also used : LineReader(htsjdk.tribble.readers.LineReader) LineIteratorImpl(htsjdk.tribble.readers.LineIteratorImpl) LineIterator(htsjdk.tribble.readers.LineIterator) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 3 with LineIterator

use of htsjdk.tribble.readers.LineIterator in project gatk by broadinstitute.

the class TableCodecUnitTest method testDecodeOnlyComments.

@Test
public void testDecodeOnlyComments() {
    TableCodec tc = new TableCodec();
    LineReader reader = makeReader(asList("#HEADER a b c", "#HEADER d e f"));
    LineIterator li = new LineIteratorImpl(reader);
    final List<String> strings = tc.readActualHeader(li);
    Assert.assertEquals(strings, emptyList());
}
Also used : LineReader(htsjdk.tribble.readers.LineReader) LineIteratorImpl(htsjdk.tribble.readers.LineIteratorImpl) LineIterator(htsjdk.tribble.readers.LineIterator) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 4 with LineIterator

use of htsjdk.tribble.readers.LineIterator in project gatk by broadinstitute.

the class LineIteratorReaderUnitTest method testRead.

@Test(dataProvider = "testParameter")
public void testRead(@SuppressWarnings("unused") final int textSize, @SuppressWarnings("unused") final int lineSize, final int bufferSize, final String text) {
    final LineIterator lineIterator = new TestLineIterator(text);
    final LineIteratorReader reader = new LineIteratorReader(lineIterator);
    final StringBuilder sb = new StringBuilder();
    final char[] buffer = new char[bufferSize];
    int readResult;
    while ((readResult = reader.read(buffer, 0, bufferSize)) >= 0) {
        sb.append(buffer, 0, readResult);
    }
    final String actualText = sb.toString();
    Assert.assertEquals(actualText, text);
}
Also used : LineIterator(htsjdk.tribble.readers.LineIterator) Test(org.testng.annotations.Test)

Example 5 with LineIterator

use of htsjdk.tribble.readers.LineIterator in project gatk by broadinstitute.

the class TableCodecUnitTest method testTwoHeaders.

@Test
public void testTwoHeaders() {
    TableCodec tc = new TableCodec();
    LineReader reader = makeReader(asList("HEADER a b c", "HEADER d e f"));
    LineIterator li = new LineIteratorImpl(reader);
    final List<String> strings = tc.readActualHeader(li);
    Assert.assertEquals(strings, asList("HEADER", "a", "b", "c"));
}
Also used : LineReader(htsjdk.tribble.readers.LineReader) LineIteratorImpl(htsjdk.tribble.readers.LineIteratorImpl) LineIterator(htsjdk.tribble.readers.LineIterator) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Aggregations

LineIterator (htsjdk.tribble.readers.LineIterator)13 Test (org.testng.annotations.Test)9 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)7 LineIteratorImpl (htsjdk.tribble.readers.LineIteratorImpl)6 LineReader (htsjdk.tribble.readers.LineReader)6 VariantContext (htsjdk.variant.variantcontext.VariantContext)5 VCFCodec (htsjdk.variant.vcf.VCFCodec)5 PositionalBufferedStream (htsjdk.tribble.readers.PositionalBufferedStream)4 File (java.io.File)3 GenomicsDBFeatureReader (com.intel.genomicsdb.GenomicsDBFeatureReader)2 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)2 BCF2Codec (htsjdk.variant.bcf2.BCF2Codec)2 VCFHeader (htsjdk.variant.vcf.VCFHeader)2 FileInputStream (java.io.FileInputStream)2 ArrayList (java.util.ArrayList)2 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ChromosomeInterval (com.intel.genomicsdb.ChromosomeInterval)1 GenomicsDBCallsetsMapProto (com.intel.genomicsdb.GenomicsDBCallsetsMapProto)1 GenomicsDBImportConfiguration (com.intel.genomicsdb.GenomicsDBImportConfiguration)1