use of htsjdk.variant.variantcontext.VariantContextComparator in project gatk by broadinstitute.
the class AbstractVcfMergingClpTester method validateSnpAndIndelResults.
/**
* Make sure that the order of the output file is identical to the order
* of the input files by iterating through the output, making sure that,
* if the context is an indel (snp), the next genomic position in the indel
* (snp) queue is the same. Also make sure that the context is in the order
* specified by the input files.
*/
private void validateSnpAndIndelResults(final File output, final Queue<String> indelContigPositions, final Queue<String> snpContigPositions) {
final VCFFileReader outputReader = new VCFFileReader(output, false);
final VariantContextComparator outputComparator = outputReader.getFileHeader().getVCFRecordComparator();
VariantContext last = null;
try (final CloseableIterator<VariantContext> iterator = outputReader.iterator()) {
while (iterator.hasNext()) {
final VariantContext outputContext = iterator.next();
if (outputContext.isIndel())
Assert.assertEquals(getContigPosition(outputContext), indelContigPositions.poll());
if (outputContext.isSNP())
Assert.assertEquals(getContigPosition(outputContext), snpContigPositions.poll());
if (last != null)
Assert.assertTrue(outputComparator.compare(last, outputContext) <= 0);
last = outputContext;
}
}
// We should have polled everything off the indel (snp) queues
Assert.assertEquals(indelContigPositions.size(), 0);
Assert.assertEquals(snpContigPositions.size(), 0);
}
use of htsjdk.variant.variantcontext.VariantContextComparator in project gatk by broadinstitute.
the class MultiVariantDataSource method getMergedIteratorFromDataSources.
/**
* Close any existing iterator, create a new iterator and update the local cached iterator reference.
* @param iteratorFromSource function to retrieve individual iterator, to be applied to each data source
* @return
*/
private Iterator<VariantContext> getMergedIteratorFromDataSources(final Function<FeatureDataSource<VariantContext>, Iterator<VariantContext>> iteratorFromSource) {
// Tribble documentation states that having multiple iterators open simultaneously over the same FeatureReader
// results in undefined behavior
closeOpenIterationIfNecessary();
if (featureDataSources.size() > 1) {
final List<CloseableIterator<VariantContext>> iterators = new ArrayList<>(featureDataSources.size());
featureDataSources.forEach(ds -> iterators.add(getCloseableIteratorWrapper(iteratorFromSource.apply((ds)))));
final VariantContextComparator varComparator = new VariantContextComparator(getSequenceDictionary());
currentIterator = new MergingIterator<>(varComparator, iterators);
} else {
currentIterator = getCloseableIteratorWrapper(iteratorFromSource.apply(featureDataSources.get(0)));
}
return currentIterator;
}
Aggregations