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(); }
/** 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(
/** 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(
/** 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(); }
final FeatureCodecHeader h = codec.readHeader(it); if (h == null || !(h.getHeaderValue() instanceof VCFHeader)) throw new IOException("No VCF header found in "+ file);
final FeatureCodecHeader h = codec.readHeader(it); if (h == null || !(h.getHeaderValue() instanceof VCFHeader)) throw new IOException("No VCF header found in "+ file);
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);
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; } }
final FeatureCodecHeader h = codec.readHeader(it); if (h == null || !(h.getHeaderValue() instanceof VCFHeader)) throw new IOException("No VCF header found in "+ file);
@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 public void HCTestDanglingTailMergingForDeletions() throws IOException { final String base = String.format("-T HaplotypeCaller --disableDithering --pcr_indel_model NONE -R %s -I %s", REF, NA12878_BAM) + " --no_cmdline_in_header -o %s -L 20:10130740-10130800 --allowNonUniqueKmersInRef"; final WalkerTestSpec spec = new WalkerTestSpec(base, 1, Arrays.asList("")); final File outputVCF = executeTest("HCTestDanglingTailMergingForDeletions", spec).getFirst().get(0); // confirm that the call is the correct one final VCFCodec codec = new VCFCodec(); final FileInputStream s = new FileInputStream(outputVCF); final LineIterator lineIterator = codec.makeSourceFromStream(new PositionalBufferedStream(s)); codec.readHeader(lineIterator); final String line = lineIterator.next(); Assert.assertFalse(line == null); final VariantContext vc = codec.decode(line); Assert.assertTrue(vc.isBiallelic()); Assert.assertTrue(vc.getReference().basesMatch("ATGTATG")); Assert.assertTrue(vc.getAlternateAllele(0).basesMatch("A")); }
/** * Returns a list of VariantContext records from a VCF file * * @param vcfFile VCF file * * @throws IOException if the file does not exist or can not be opened * * @return list of VariantContext records */ private static List<VariantContext> getVariantContexts(final File vcfFile) throws IOException { final VCFCodec codec = new VCFCodec(); final FileInputStream s = new FileInputStream(vcfFile); final LineIterator lineIteratorVCF = codec.makeSourceFromStream(new PositionalBufferedStream(s)); codec.readHeader(lineIteratorVCF); final List<VariantContext> VCs = new ArrayList<>(); while ( lineIteratorVCF.hasNext() ) { final String line = lineIteratorVCF.next(); Assert.assertFalse(line == null); VCs.add(codec.decode(line)); } return VCs; }
final FileInputStream originalStream = new FileInputStream(MultiAllelicsTest); final LineIterator originalLineIterator = codec.makeSourceFromStream(new PositionalBufferedStream(originalStream)); codec.readHeader(originalLineIterator); int numOriginalRecords = 0; while ( originalLineIterator.hasNext() ) { codec.readHeader(newLineIterator); int numNewRecords = 0; while ( newLineIterator.hasNext() ) {
final FileInputStream s = new FileInputStream(outputVCF); final LineIterator lineIterator = codec.makeSourceFromStream(new PositionalBufferedStream(s)); codec.readHeader(lineIterator); codecAnn.readHeader(lineIteratorAnn);
/** * Returns a list of attribute values from a VCF file * * @param vcfFile VCF file * @param attributeName attribute name * * @throws IOException if the file does not exist or can not be opened * * @return list of attribute values */ private List<String> getAttributeValues(final File vcfFile, final String attributeName) throws IOException { final VCFCodec codec = new VCFCodec(); final FileInputStream s = new FileInputStream(vcfFile); final LineIterator lineIteratorVCF = codec.makeSourceFromStream(new PositionalBufferedStream(s)); codec.readHeader(lineIteratorVCF); final List<String> attributeValues = new ArrayList<String>(); while (lineIteratorVCF.hasNext()) { final String line = lineIteratorVCF.next(); Assert.assertFalse(line == null); final VariantContext vc = codec.decode(line); for (final Genotype g : vc.getGenotypes()) { if (g.hasExtendedAttribute(attributeName)) { attributeValues.add((String) g.getExtendedAttribute(attributeName)); } } } return attributeValues; }
final FileInputStream s = new FileInputStream(vcfFile); final LineIterator lineIteratorVCF = codec.makeSourceFromStream(new PositionalBufferedStream(s)); codec.readHeader(lineIteratorVCF);
final FileInputStream s = new FileInputStream(outputVCF); final LineIterator lineIterator = codec.makeSourceFromStream(new PositionalBufferedStream(s)); codec.readHeader(lineIterator); codecAnn.readHeader(lineIteratorAnn);