private static AbstractFeatureReader<VariantContext, LineIterator> getReaderFromPath(final Path variantPath) { final String variantURI = variantPath.toAbsolutePath().toUri().toString(); try { return AbstractFeatureReader.getFeatureReader(variantURI, null, new VCFCodec(), false, Function.identity(), Function.identity()); } catch (final TribbleException e) { throw new PicardException("Failed to create reader from " + variantURI, e); } } }
private static AbstractFeatureReader<VariantContext, LineIterator> getReaderFromPath(final Path variantPath) { final String variantURI = variantPath.toAbsolutePath().toUri().toString(); try { return AbstractFeatureReader.getFeatureReader(variantURI, null, new VCFCodec(), false, Function.identity(), Function.identity()); } catch (final TribbleException e) { throw new PicardException("Failed to create reader from " + variantURI, e); } } }
public static VCFHeader parseVcfHeader(String variantFileHeader) throws IOException { VCFCodec vcfCodec = new VCFCodec(); LineIterator source = vcfCodec.makeSourceFromStream(new ByteArrayInputStream(variantFileHeader.getBytes())); FeatureCodecHeader featureCodecHeader = vcfCodec.readHeader(source); return (VCFHeader) featureCodecHeader.getHeaderValue(); }
/** Allows construction of a VCFFileReader with a specified index file. */ public VCFFileReader(final File file, final File indexFile, final boolean requireIndex) { this.reader = AbstractFeatureReader.getFeatureReader( file.getAbsolutePath(), indexFile.getAbsolutePath(), isBCF(file) ? new BCF2Codec() : new VCFCodec(), requireIndex); }
/** * returns Correct Feature codec for Path depending whether * the name seems to indicate that it's a BCF. * * @param path to vcf/bcf * @return FeatureCodec for input Path */ private static FeatureCodec<VariantContext, ?> getCodecForPath(Path path) { return isBCF(path) ? new BCF2Codec() : new VCFCodec(); }
/** Allows construction of a VCFFileReader that will or will not assert the presence of an index as desired. */ public VCFFileReader(final File file, final boolean requireIndex) { this.reader = AbstractFeatureReader.getFeatureReader( file.getAbsolutePath(), isBCF(file) ? new BCF2Codec() : new VCFCodec(), requireIndex); }
@DataProvider(name = "serializationTestData") public Object[][] getSerializationTestData() { return new Object[][] { { new File("src/test/resources/htsjdk/variant/HiSeq.10000.vcf"), new VCFCodec() }, { new File("src/test/resources/htsjdk/variant/serialization_test.bcf"), new BCF2Codec() } }; }
public Index getIndex(final File vcfFile) { switch (type) { case DYNAMIC_SEEK : return IndexFactory.createDynamicIndex(vcfFile, new VCFCodec(), IndexFactory.IndexBalanceApproach.FOR_SEEK_TIME); case DYNAMIC_SIZE : return IndexFactory.createDynamicIndex(vcfFile, new VCFCodec(), IndexFactory.IndexBalanceApproach.FOR_SIZE); case LINEAR : return IndexFactory.createLinearIndex(vcfFile, new VCFCodec(), parameter); case INTERVAL : return IndexFactory.createIntervalIndex(vcfFile, new VCFCodec(), parameter); default : throw new TestException("Invalid index type"); } } }
public Index getIndex(final File vcfFile) { switch (type) { case DYNAMIC_SEEK : return IndexFactory.createDynamicIndex(vcfFile, new VCFCodec(), IndexFactory.IndexBalanceApproach.FOR_SEEK_TIME); case DYNAMIC_SIZE : return IndexFactory.createDynamicIndex(vcfFile, new VCFCodec(), IndexFactory.IndexBalanceApproach.FOR_SIZE); case LINEAR : return IndexFactory.createLinearIndex(vcfFile, new VCFCodec(), parameter); case INTERVAL : return IndexFactory.createIntervalIndex(vcfFile, new VCFCodec(), parameter); default : throw new TestException("Invalid index type"); } } }
@Test public void testDisableAutoIndexGeneration() throws IOException { final File unindexedVCF = new File(privateTestDir + "unindexed.vcf"); final File unindexedVCFIndex = Tribble.indexFile(unindexedVCF); Index index = builder.loadIndex(unindexedVCF, new VCFCodec()); Assert.assertFalse(unindexedVCFIndex.exists()); Assert.assertNotNull(index); }
@Test public void testLoadOnDiskIndex() { final File originalVCF = new File(privateTestDir + "vcf4.1.example.vcf"); final File tempVCFWithCorrectIndex = createTempVCFFileAndIndex(originalVCF, false); final File tempVCFIndexFile = Tribble.indexFile(tempVCFWithCorrectIndex); final Index index = builder.loadFromDisk(tempVCFWithCorrectIndex, tempVCFIndexFile); Assert.assertNotNull(index); Assert.assertTrue(tempVCFIndexFile.exists()); final Index inMemoryIndex = builder.createIndexInMemory(tempVCFWithCorrectIndex, new VCFCodec()); Assert.assertTrue(index.equalsIgnoreProperties(inMemoryIndex)); }
public void timeV14(int rep) { for ( int i = 0; i < rep; i++ ) { FunctionToBenchmark<VariantContext> func = getV14FunctionToBenchmark(); final VCFCodec codec = new VCFCodec(); runBenchmark(codec, func); } }
@BeforeClass public static void setUpClass() throws IOException { File idxFile = new File(testFile + ".idx"); FeatureCodec codec = new VCFCodec(); createIndex(idxFile, codec); bfr = AbstractFeatureReader.getFeatureReader(testFile, codec); }
@Test(dataProvider = "failsWithoutWrappers", expectedExceptions = {TribbleException.class, FileTruncatedException.class}) public void testFailureIfNoWrapper(String file, String index) throws IOException, URISyntaxException { try(final FileSystem fs = Jimfs.newFileSystem("test", Configuration.unix()); final FeatureReader<?> reader = getFeatureReader(file, index, null, null, new VCFCodec(), fs)){ // should have exploded by now } }
@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(); }
@Test public void testAskingGCContent() throws IOException{ WalkerTestSpec spec = new WalkerTestSpec( baseTestString() + " --variant " + privateTestDir + "vcfexample2.vcf -I " + validationDataLocation + "low_coverage_CEU.chr1.10k-11k.bam -L 1:10,020,000-10,021,000 -A GCContent", 1, Arrays.asList("fcc42d7e0351efa7c3db0a114cbc17ed")); final File outputVCF = executeTest("test file has annotations, adding GCContent annotation", spec).getFirst().get(0); final VCFCodec codec = new VCFCodec(); final VCFHeader header = (VCFHeader) codec.readActualHeader(codec.makeSourceFromStream(new FileInputStream(outputVCF))); final VCFHeaderLine infoLineGC = header.getInfoHeaderLine(GATKVCFConstants.GC_CONTENT_KEY); // GC content must be a Float type Assert.assertTrue(infoLineGC.toString().contains("Type=Float")); }
@Test @Ignore("Requires largedata bundle") public void testIntervalIndex40() throws Exception { String testFile = TestUtils.LARGE_DATA_DIR + "CEU.SRP000032.2010_03_v4.0.genotypes.head.vcf"; FeatureCodec codec = new VCFCodec(); tstIntervalIndex(testFile, codec); }
private VCFHeader createHeader(String headerStr) { VCFCodec codec = new VCFCodec(); VCFHeader head = null; head = (VCFHeader) codec.readActualHeader(codec.makeSourceFromStream(new PositionalBufferedStream(new StringBufferInputStream(headerStr)))); return head; }
public static void assertVCFandBCFFilesAreTheSame(final File vcfFile, final File bcfFile) throws IOException { final Pair<VCFHeader, VCIterable<LineIterator>> vcfData = VCIterable.readAllVCs(vcfFile, new VCFCodec()); final Pair<VCFHeader, VCIterable<PositionalBufferedStream>> bcfData = VCIterable.readAllVCs(bcfFile, new BCF2Codec()); assertVCFHeadersAreEqual(bcfData.getFirst(), vcfData.getFirst()); assertVariantContextStreamsAreEqual(bcfData.getSecond(), vcfData.getSecond()); }
public static void assertVCFandBCFFilesAreTheSame(final File vcfFile, final File bcfFile) throws IOException { final VariantContextContainer vcfData = readAllVCs(vcfFile, new VCFCodec()); final VariantContextContainer bcfData = readAllVCs(bcfFile, new BCF2Codec()); assertEquals(bcfData.getHeader(), vcfData.getHeader()); assertEquals(bcfData.getVCs(), vcfData.getVCs()); }