use of htsjdk.variant.vcf.VCFReader in project jvarkit by lindenb.
the class VcfBurdenFisherHTest method test01.
@Test(dataProvider = "src1", enabled = false)
public void test01(final String inputFile) throws IOException {
try {
final VCFReader r0 = VCFReaderFactory.makeDefault().open(new File(inputFile), false);
final VCFHeader vcfheader = r0.getHeader();
if (vcfheader.getNGenotypeSamples() < 2) {
r0.close();
return;
}
final CloseableIterator<VariantContext> iter = r0.iterator();
final Path inputVcf = support.createTmpPath(".vcf");
final VariantContextWriter w = VCFUtils.createVariantContextWriter(inputVcf.toFile());
w.writeHeader(vcfheader);
iter.stream().filter(V -> V.getAlleles().size() == 2).forEach(V -> w.add(V));
iter.close();
w.close();
r0.close();
final Path ped = support.createRandomPedigreeFromFile(inputFile);
if (ped == null) {
Reporter.getCurrentTestResult().setAttribute("warn", "No Pedigree for " + inputFile);
return;
}
final Path output = support.createTmpPath(".vcf");
Assert.assertEquals(new VcfBurdenFisherH().instanceMain(new String[] { "-o", output.toString(), "--pedigree", ped.toString() }), 0);
support.assertIsVcf(output);
} finally {
support.removeTmpFiles();
}
}
use of htsjdk.variant.vcf.VCFReader in project jvarkit by lindenb.
the class VcfFilterNotInPedigreeTest method test01.
@Test(dataProvider = "src1")
public void test01(final String inputFile) throws IOException {
try {
final VCFReader r0 = VCFReaderFactory.makeDefault().open(Paths.get(inputFile), false);
final VCFHeader vcfheader = r0.getHeader();
if (vcfheader.getNGenotypeSamples() < 1) {
r0.close();
return;
}
r0.close();
final Path ped = support.createRandomPedigreeFromFile(inputFile);
if (ped == null) {
Reporter.getCurrentTestResult().setAttribute("warn", "No Pedigree for " + inputFile);
return;
}
final Path output = support.createTmpPath(".vcf");
Assert.assertEquals(new VcfFilterNotInPedigree().instanceMain(new String[] { "-o", output.toString(), "--pedigree", ped.toString(), inputFile.toString() }), 0);
support.assertIsVcf(output);
} finally {
support.removeTmpFiles();
}
}
use of htsjdk.variant.vcf.VCFReader in project jvarkit by lindenb.
the class Biostar130456Test method test01.
@Test(dataProvider = "src1")
public void test01(final String vcfpath) throws IOException {
try {
final VCFReader r = VCFReaderFactory.makeDefault().open(new File(vcfpath), false);
final Set<String> samples = new HashSet<>(r.getHeader().getSampleNamesInOrder());
r.close();
if (samples.isEmpty())
return;
final String vcfOut = IOUtils.getDefaultTmpDir().getPath() + File.separatorChar + "tmp.__SAMPLE__.vcf.gz";
final Path tsvout = support.createTmpPath(".txt");
Assert.assertEquals(new Biostar130456().instanceMain(new String[] { "-o", tsvout.toString(), "-p", vcfOut, vcfpath }), 0);
Assert.assertTrue(Files.exists(tsvout));
for (final String s : samples) {
final Path vcfIn2 = Paths.get(vcfOut.replaceAll("__SAMPLE__", s));
support.assertIsVcf(vcfIn2);
final VCFReader r2 = VCFReaderFactory.makeDefault().open(vcfIn2, false);
final List<String> samples2 = r2.getHeader().getSampleNamesInOrder();
r2.close();
Assert.assertTrue(samples2.size() == 1);
Assert.assertEquals(samples2.get(0), s);
Assert.assertTrue(Files.deleteIfExists(vcfIn2));
}
} finally {
support.removeTmpFiles();
}
}
use of htsjdk.variant.vcf.VCFReader in project jvarkit by lindenb.
the class TestSupport method variantStream.
public Stream<VariantContext> variantStream(final Path vcfFile) {
final VCFReader r = VCFReaderFactory.makeDefault().open(vcfFile, false);
final CloseableIterator<VariantContext> iter = r.iterator();
return iter.stream().onClose(() -> {
CloserUtil.close(iter);
CloserUtil.close(r);
});
}
use of htsjdk.variant.vcf.VCFReader in project jvarkit by lindenb.
the class VCFCompareGTTest method mute.
private Path mute(final Path in) throws IOException {
Path outVcf = support.createTmpPath(".vcf");
final VariantContextWriter w = VCFUtils.createVariantContextWriterToPath(outVcf);
final VCFReader r = VCFReaderFactory.makeDefault().open(in, true);
w.writeHeader(r.getHeader());
final CloseableIterator<VariantContext> iter = r.iterator();
while (iter.hasNext()) {
final VariantContext ctx = iter.next();
// ignore some variants
if (support.random.nextDouble() < 0.1)
continue;
w.add(mute(ctx));
}
w.close();
iter.close();
r.close();
support.assertIsVcf(outVcf);
return outVcf;
}
Aggregations