VcfFiles { public static Stream<VariantContext> readVariantContexts(Path vcfPath) { Objects.requireNonNull(vcfPath, "Cannot read from null vcfPath"); logger.debug("Reading variants from VCF file {}", vcfPath); try (VCFFileReader vcfReader = new VCFFileReader(vcfPath, false)) { return vcfReader.iterator().stream(); } } private  VcfFiles(); static Stream<VariantContext> readVariantContexts(Path vcfPath); static VCFHeader readVcfHeader(Path vcfPath);  }
@Test public void testCreateVariantContextsNullPath() { assertThrows(NullPointerException.class, () -> VcfFiles.readVariantContexts(null)); }
@Test public void testCreateVariantContextsNonExistentFile() { Path vcfPath = Paths.get("src/test/resources/wibble.vcf"); assertThrows(TribbleException.class, () -> VcfFiles.readVariantContexts(vcfPath)); }
@Test public void testCreateVariantContextsSingleAlleles() { Path vcfPath = Paths.get("src/test/resources/smallTest.vcf"); long numVariants; try (Stream<VariantContext> variantStream = VcfFiles.readVariantContexts(vcfPath)) { numVariants = variantStream.count(); } assertThat(numVariants, equalTo(3L)); }
@Test public void testStreamVariantContextsSingleAlleles() { Path vcfPath = Paths.get("src/test/resources/smallTest.vcf"); List<VariantContext> variants = VcfFiles.readVariantContexts(vcfPath) .filter(variantContext -> (variantContext.getContig().equals("1"))) .collect(toList()); assertThat(variants.size(), equalTo(3)); }
@Test public void testCreateVariantContextsMultipleAlleles() { Path vcfPath = Paths.get("src/test/resources/altAllele.vcf"); List<VariantContext> variants = VcfFiles.readVariantContexts(vcfPath).collect(toList()); assertThat(variants.size(), equalTo(1)); }