use of htsjdk.variant.vcf.VCFFileReader in project gatk by broadinstitute.
the class FilterVcfTest method testNoFiltering.
/** Tests that all records get PASS set as their filter when extreme values are used for filtering. */
@Test
public void testNoFiltering() throws Exception {
final File out = testFiltering(INPUT, 0, 0, 0, Double.MAX_VALUE);
final VCFFileReader in = new VCFFileReader(out, false);
for (final VariantContext ctx : in) {
if (!ctx.filtersWereApplied() || ctx.isFiltered()) {
Assert.fail("Context should not have been filtered: " + ctx.toString());
}
}
}
use of htsjdk.variant.vcf.VCFFileReader in project gatk-protected by broadinstitute.
the class CreateSomaticPanelOfNormals method doWork.
public Object doWork() {
final List<File> inputVcfs = new ArrayList<>(vcfs);
final Collection<CloseableIterator<VariantContext>> iterators = new ArrayList<>(inputVcfs.size());
final Collection<VCFHeader> headers = new HashSet<>(inputVcfs.size());
final VCFHeader headerOfFirstVcf = new VCFFileReader(inputVcfs.get(0), false).getFileHeader();
final SAMSequenceDictionary sequenceDictionary = headerOfFirstVcf.getSequenceDictionary();
final VariantContextComparator comparator = headerOfFirstVcf.getVCFRecordComparator();
for (final File vcf : inputVcfs) {
final VCFFileReader reader = new VCFFileReader(vcf, false);
iterators.add(reader.iterator());
final VCFHeader header = reader.getFileHeader();
Utils.validateArg(comparator.isCompatible(header.getContigLines()), () -> vcf.getAbsolutePath() + " has incompatible contigs.");
headers.add(header);
}
final VariantContextWriter writer = GATKVariantContextUtils.createVCFWriter(outputVcf, sequenceDictionary, false, Options.INDEX_ON_THE_FLY);
writer.writeHeader(new VCFHeader(VCFUtils.smartMergeHeaders(headers, false)));
final MergingIterator<VariantContext> mergingIterator = new MergingIterator<>(comparator, iterators);
SimpleInterval currentPosition = new SimpleInterval("FAKE", 1, 1);
final List<VariantContext> variantsAtThisPosition = new ArrayList<>(20);
while (mergingIterator.hasNext()) {
final VariantContext vc = mergingIterator.next();
if (!currentPosition.overlaps(vc)) {
processVariantsAtSamePosition(variantsAtThisPosition, writer);
variantsAtThisPosition.clear();
currentPosition = new SimpleInterval(vc.getContig(), vc.getStart(), vc.getStart());
}
variantsAtThisPosition.add(vc);
}
mergingIterator.close();
writer.close();
return "SUCCESS";
}
use of htsjdk.variant.vcf.VCFFileReader in project gatk by broadinstitute.
the class GATKToolUnitTest method testFeaturesHeader.
@Test
public void testFeaturesHeader() throws Exception {
final TestGATKToolWithFeatures tool = new TestGATKToolWithFeatures();
final CommandLineParser clp = new CommandLineArgumentParser(tool);
final File vcfFile = new File(publicTestDir + "org/broadinstitute/hellbender/engine/feature_data_source_test_with_bigHeader.vcf");
final String[] args = { "--mask", vcfFile.getCanonicalPath() };
clp.parseArguments(System.out, args);
tool.onStartup();
final Object headerForFeatures = tool.getHeaderForFeatures(tool.mask);
Assert.assertTrue(headerForFeatures instanceof VCFHeader);
final VCFHeader vcfheaderForFeatures = (VCFHeader) headerForFeatures;
try (final VCFFileReader vcfReader = new VCFFileReader(vcfFile, false)) {
//read the file directly and compare headers
final VCFHeader vcfFileHeader = vcfReader.getFileHeader();
Assert.assertEquals(vcfheaderForFeatures.getGenotypeSamples(), vcfFileHeader.getGenotypeSamples());
Assert.assertEquals(vcfheaderForFeatures.getInfoHeaderLines(), vcfFileHeader.getInfoHeaderLines());
Assert.assertEquals(vcfheaderForFeatures.getFormatHeaderLines(), vcfFileHeader.getFormatHeaderLines());
Assert.assertEquals(vcfheaderForFeatures.getFilterLines(), vcfFileHeader.getFilterLines());
Assert.assertEquals(vcfheaderForFeatures.getContigLines(), vcfFileHeader.getContigLines());
Assert.assertEquals(vcfheaderForFeatures.getOtherHeaderLines(), vcfFileHeader.getOtherHeaderLines());
}
tool.doWork();
tool.onShutdown();
}
use of htsjdk.variant.vcf.VCFFileReader in project gatk by broadinstitute.
the class GATKToolUnitTest method testBestSequenceDictionary_fromVariants.
@Test
public void testBestSequenceDictionary_fromVariants() throws Exception {
final GATKTool tool = new TestGATKToolWithFeatures();
final CommandLineParser clp = new CommandLineArgumentParser(tool);
final File vcfFile = new File(publicTestDir + "org/broadinstitute/hellbender/engine/feature_data_source_test_withSequenceDict.vcf");
final String[] args = { "--mask", vcfFile.getCanonicalPath() };
clp.parseArguments(System.out, args);
tool.onStartup();
//read the dict back in and compare to vcf dict
final SAMSequenceDictionary toolDict = tool.getBestAvailableSequenceDictionary();
try (final VCFFileReader reader = new VCFFileReader(vcfFile)) {
final SAMSequenceDictionary vcfDict = reader.getFileHeader().getSequenceDictionary();
toolDict.assertSameDictionary(vcfDict);
vcfDict.assertSameDictionary(toolDict);
Assert.assertEquals(toolDict, vcfDict);
}
}
use of htsjdk.variant.vcf.VCFFileReader in project gatk by broadinstitute.
the class SortVcfTest method validateSortingResults.
/**
* Checks the ordering and total number of variant context entries in the specified output VCF file.
* Does NOT check explicitly that the VC genomic positions match exactly those from the inputs. We assume this behavior from other tests.
*
* @param output VCF file representing the output of SortVCF
* @param expectedVariantContextCount the total number of variant context entries from all input files that were merged/sorted
*/
private void validateSortingResults(final File output, final int expectedVariantContextCount) {
final VCFFileReader outputReader = new VCFFileReader(output, false);
final VariantContextComparator outputComparator = outputReader.getFileHeader().getVCFRecordComparator();
VariantContext last = null;
int variantContextCount = 0;
try (final CloseableIterator<VariantContext> iterator = outputReader.iterator()) {
while (iterator.hasNext()) {
final VariantContext outputContext = iterator.next();
if (last != null)
Assert.assertTrue(outputComparator.compare(last, outputContext) <= 0);
last = outputContext;
variantContextCount++;
}
}
Assert.assertEquals(variantContextCount, expectedVariantContextCount);
}
Aggregations