@Override public LocationAware makeIndexableSourceFromStream(final InputStream inputStream) { return new AsciiLineReaderIterator(AsciiLineReader.from(inputStream)); }
@Test public void testVCFHeaderSampleRenamingSingleSampleVCF() throws Exception { final VCFCodec codec = new VCFCodec(); codec.setRemappedSampleName("FOOSAMPLE"); final AsciiLineReaderIterator vcfIterator = new AsciiLineReaderIterator(AsciiLineReader.from(new FileInputStream(variantTestDataRoot + "HiSeq.10000.vcf"))); final VCFHeader header = (VCFHeader) codec.readHeader(vcfIterator).getHeaderValue(); Assert.assertEquals(header.getNGenotypeSamples(), 1, "Wrong number of samples in remapped header"); Assert.assertEquals(header.getGenotypeSamples().get(0), "FOOSAMPLE", "Sample name in remapped header has incorrect value"); int recordCount = 0; while (vcfIterator.hasNext() && recordCount < 10) { recordCount++; final VariantContext vcfRecord = codec.decode(vcfIterator.next()); Assert.assertEquals(vcfRecord.getSampleNames().size(), 1, "Wrong number of samples in vcf record after remapping"); Assert.assertEquals(vcfRecord.getSampleNames().iterator().next(), "FOOSAMPLE", "Wrong sample in vcf record after remapping"); } }
@Test(dataProvider = "gzippedBedTestData") public void testReadActualHeader(final File gzippedBedFile, final int firstFeatureOffset) throws IOException { // Given an indexable SOURCE on a BED file, test that readActualHeader retains the correct offset // of the first feature, whether there is a header or not BEDCodec bedCodec = new BEDCodec(); try (final InputStream is = ParsingUtils.openInputStream(gzippedBedFile.getPath()); final BlockCompressedInputStream bcis = new BlockCompressedInputStream(is)) { AsciiLineReaderIterator it = (AsciiLineReaderIterator) bedCodec.makeIndexableSourceFromStream(bcis); Object header = bedCodec.readActualHeader(it); // BEDCodec doesn't model or return the BED header, even when there is one! Assert.assertNull(header); Assert.assertEquals(BlockCompressedFilePointerUtil.getBlockAddress(it.getPosition()), 0); Assert.assertEquals(BlockCompressedFilePointerUtil.getBlockOffset(it.getPosition()), firstFeatureOffset); } }
FileInputStream fis = new FileInputStream(fakeVCFFile)) { AsciiLineReaderIterator iterator = new AsciiLineReaderIterator(new AsciiLineReader(".vcf.gz".equals(extension) ? bcis : fis)); int counter = 0; while (iterator.hasNext()) { VariantContext context = codec.decode(iterator.next()); counter++;
@Override public LocationAware makeIndexableSourceFromStream(final InputStream inputStream) { return new AsciiLineReaderIterator(AsciiLineReader.from(inputStream)); }
/** test, using the writer and reader, that we can output and input a VCF body without problems */ @Test public void testWriteAndReadAsyncVCFHeaderless() throws IOException { final File fakeVCFFile = VariantBaseTest.createTempFile("testWriteAndReadAsyncVCFHeaderless.", IOUtil.VCF_FILE_EXTENSION); fakeVCFFile.deleteOnExit(); Tribble.indexFile(fakeVCFFile).deleteOnExit(); final Set<VCFHeaderLine> metaData = new HashSet<>(); final Set<String> additionalColumns = new HashSet<>(); final SAMSequenceDictionary sequenceDict = createArtificialSequenceDictionary(); final VCFHeader header = createFakeHeader(metaData, additionalColumns, sequenceDict); try (final VariantContextWriter writer = new VariantContextWriterBuilder() .setOutputFile(fakeVCFFile).setReferenceDictionary(sequenceDict) .setOptions(EnumSet.of(Options.ALLOW_MISSING_FIELDS_IN_HEADER, Options.INDEX_ON_THE_FLY, Options.USE_ASYNC_IO)) .build()) { writer.setHeader(header); writer.add(createVC(header)); writer.add(createVC(header)); } final VCFCodec codec = new VCFCodec(); codec.setVCFHeader(header, VCFHeaderVersion.VCF4_2); try (final FileInputStream fis = new FileInputStream(fakeVCFFile)) { final AsciiLineReaderIterator iterator = new AsciiLineReaderIterator(new AsciiLineReader(fis)); int counter = 0; while (iterator.hasNext()) { VariantContext context = codec.decode(iterator.next()); counter++; } Assert.assertEquals(counter, 2); } }
/** A VCFHeader is read from the input Path. */ public VCFRecordWriter( Path output, Path input, boolean writeHeader, TaskAttemptContext ctx) throws IOException { final AsciiLineReader r = new AsciiLineReader( input.getFileSystem(ctx.getConfiguration()).open(input)); final FeatureCodecHeader h = codec.readHeader(new AsciiLineReaderIterator(r)); if (h == null || !(h.getHeaderValue() instanceof VCFHeader)) throw new IOException("No VCF header found in "+ input); r.close(); init(output, (VCFHeader) h.getHeaderValue(), writeHeader, ctx); } public VCFRecordWriter(
@Override public LocationAware makeIndexableSourceFromStream(final InputStream bufferedInputStream) { final PositionalBufferedStream pbs; if (bufferedInputStream instanceof PositionalBufferedStream) { pbs = (PositionalBufferedStream) bufferedInputStream; } else { pbs = new PositionalBufferedStream(bufferedInputStream); } return new AsciiLineReaderIterator(new AsciiLineReader(pbs)); }
/** A VCFHeader is read from the input Path. */ public VCFRecordWriter( Path output, Path input, boolean writeHeader, TaskAttemptContext ctx) throws IOException { final AsciiLineReader r = new AsciiLineReader( input.getFileSystem(ctx.getConfiguration()).open(input)); final FeatureCodecHeader h = codec.readHeader(new AsciiLineReaderIterator(r)); if (h == null || !(h.getHeaderValue() instanceof VCFHeader)) throw new IOException("No VCF header found in "+ input); r.close(); init(output, (VCFHeader) h.getHeaderValue(), writeHeader, ctx); } public VCFRecordWriter(
@Override public LocationAware makeIndexableSourceFromStream(final InputStream bufferedInputStream) { final PositionalBufferedStream pbs; if (bufferedInputStream instanceof PositionalBufferedStream) { pbs = (PositionalBufferedStream) bufferedInputStream; } else { pbs = new PositionalBufferedStream(bufferedInputStream); } return new AsciiLineReaderIterator(new AsciiLineReader(pbs)); }
/** A VCFHeader is read from the input Path. */ public VCFRecordWriter( Path output, Path input, boolean writeHeader, TaskAttemptContext ctx) throws IOException { final AsciiLineReader r = new AsciiLineReader( input.getFileSystem(ctx.getConfiguration()).open(input)); final FeatureCodecHeader h = codec.readHeader(new AsciiLineReaderIterator(r)); if (h == null || !(h.getHeaderValue() instanceof VCFHeader)) throw new IOException("No VCF header found in "+ input); r.close(); init(output, (VCFHeader) h.getHeaderValue(), writeHeader, ctx); } public VCFRecordWriter(
@Test(expectedExceptions = TribbleException.class) public void testVCFHeaderSampleRenamingSitesOnlyVCF() throws Exception { final VCFCodec codec = new VCFCodec(); codec.setRemappedSampleName("FOOSAMPLE"); final AsciiLineReaderIterator vcfIterator = new AsciiLineReaderIterator(AsciiLineReader.from(new FileInputStream(variantTestDataRoot + "dbsnp_135.b37.1000.vcf"))); final VCFHeader header = (VCFHeader) codec.readHeader(vcfIterator).getHeaderValue(); }
@Test(expectedExceptions = TribbleException.class) public void testVCFHeaderSampleRenamingMultiSampleVCF() throws Exception { final VCFCodec codec = new VCFCodec(); codec.setRemappedSampleName("FOOSAMPLE"); final AsciiLineReaderIterator vcfIterator = new AsciiLineReaderIterator(AsciiLineReader.from(new FileInputStream(variantTestDataRoot + "ex2.vcf"))); final VCFHeader header = (VCFHeader) codec.readHeader(vcfIterator).getHeaderValue(); }
AsciiLineReaderIterator it = new AsciiLineReaderIterator(reader);
AsciiLineReaderIterator it = new AsciiLineReaderIterator(reader);
public static VCFHeader readHeaderFrom(final SeekableStream in) throws IOException { Object headerCodec = null; Object header = null; final long initialPos = in.position(); try { BufferedInputStream bis = new BufferedInputStream(in); InputStream is = VCFFormat.isGzip(bis) ? new GZIPInputStream(bis) : bis; headerCodec = new VCFCodec().readHeader(new AsciiLineReaderIterator(new AsciiLineReader(is))); } catch (TribbleException e) { logger.warn("Exception while trying to read VCF header from file:", e); in.seek(initialPos); InputStream bin = new BufferedInputStream(in); if (BlockCompressedInputStream.isValidFile(bin)) bin = new BlockCompressedInputStream(bin); headerCodec = new BCF2Codec().readHeader( new PositionalBufferedStream(bin)); } if (!(headerCodec instanceof FeatureCodecHeader)) throw new IOException("No VCF header found"); header = ((FeatureCodecHeader)headerCodec).getHeaderValue(); return (VCFHeader)header; } }
BufferedInputStream bis = new BufferedInputStream(in); InputStream is = VCFFormat.isGzip(bis) ? new GZIPInputStream(bis) : bis; headerCodec = new VCFCodec().readHeader(new AsciiLineReaderIterator(new AsciiLineReader(is))); } catch (TribbleException e) { logger.warn("Exception while trying to read VCF header from file:", e);
AsciiLineReaderIterator it = new AsciiLineReaderIterator(reader);
public static VCFHeader readHeaderFrom(final SeekableStream in) throws IOException { Object headerCodec = null; Object header = null; final long initialPos = in.position(); try { BufferedInputStream bis = new BufferedInputStream(in); InputStream is = VCFFormat.isGzip(bis) ? new GZIPInputStream(bis) : bis; headerCodec = new VCFCodec().readHeader(new AsciiLineReaderIterator(new AsciiLineReader(is))); } catch (TribbleException e) { logger.warn("Exception while trying to read VCF header from file:", e); in.seek(initialPos); InputStream bin = new BufferedInputStream(in); if (BlockCompressedInputStream.isValidFile(bin)) bin = new BlockCompressedInputStream(bin); headerCodec = new BCF2Codec().readHeader( new PositionalBufferedStream(bin)); } if (!(headerCodec instanceof FeatureCodecHeader)) throw new IOException("No VCF header found"); header = ((FeatureCodecHeader)headerCodec).getHeaderValue(); return (VCFHeader)header; } }