use of htsjdk.variant.variantcontext.writer.VariantContextWriter in project gatk by broadinstitute.
the class EvaluateCopyNumberTriStateCalls method doWork.
@Override
protected Object doWork() {
final TargetCollection<Target> targets = targetArguments.readTargetCollection(false);
final VCFFileReader truthReader = openVCFReader(truthFile);
final VCFFileReader callsReader = openVCFReader(callsFile);
final GenotypeEvaluationRecordWriter caseWriter = openGenotypeEvaluationOutputWriter(caseDetailOutputFile);
if (samples.isEmpty()) {
samples = composeSetOfSamplesToEvaluate(callsReader);
}
final VariantContextWriter outputWriter = openVCFWriter(outputFile, samples);
final Map<String, EvaluationSampleSummaryRecord> sampleStats = samples.stream().collect(Collectors.toMap(s -> s, EvaluationSampleSummaryRecord::new));
final List<SimpleInterval> intervals = composeListOfProcessingIntervalsFromInputs(truthReader, callsReader);
for (final SimpleInterval interval : intervals) {
for (final VariantEvaluationContext vc : processInterval(truthReader, callsReader, interval, targets)) {
outputWriter.add(vc);
outputCases(caseWriter, vc, targets);
updateSampleStats(sampleStats, vc);
}
}
truthReader.close();
callsReader.close();
outputWriter.close();
closeCaseRecordWriter(caseWriter);
writeSampleSummaryFile(sampleSummaryOutputFile, sampleStats);
return "SUCCESS";
}
use of htsjdk.variant.variantcontext.writer.VariantContextWriter in project gatk by broadinstitute.
the class EvaluateCopyNumberTriStateCalls method openVCFWriter.
private VariantContextWriter openVCFWriter(final File outputFile, final Set<String> samples) {
final VariantContextWriterBuilder builder = new VariantContextWriterBuilder();
builder.setOutputFile(outputFile);
builder.clearOptions();
final VariantContextWriter result = builder.build();
final VCFHeader header = new VCFHeader(Collections.emptySet(), samples);
CopyNumberTriStateAllele.addHeaderLinesTo(header);
EvaluationClass.addHeaderLinesTo(header);
// Format annotations.
header.addMetaDataLine(new VCFFormatHeaderLine(VCFConstants.GENOTYPE_KEY, 1, VCFHeaderLineType.Character, "Called genotype"));
header.addMetaDataLine(new VCFFormatHeaderLine(VariantEvaluationContext.CALL_QUALITY_KEY, 1, VCFHeaderLineType.Float, "Quality of the call"));
header.addMetaDataLine(new VCFFormatHeaderLine(VariantEvaluationContext.CALLED_SEGMENTS_COUNT_KEY, 1, VCFHeaderLineType.Integer, "Number of called segments that overlap with the truth"));
header.addMetaDataLine(new VCFFormatHeaderLine(VariantEvaluationContext.CALLED_ALLELE_COUNTS_KEY, VCFHeaderLineCount.G, VCFHeaderLineType.Integer, "Called allele count for mixed calls"));
header.addMetaDataLine(new VCFFormatHeaderLine(VariantEvaluationContext.TRUTH_COPY_FRACTION_KEY, 1, VCFHeaderLineType.Float, "Truth copy fraction estimated"));
header.addMetaDataLine(new VCFFormatHeaderLine(VariantEvaluationContext.TRUTH_QUALITY_KEY, 1, VCFHeaderLineType.Float, "Truth call quality"));
header.addMetaDataLine(new VCFFormatHeaderLine(VariantEvaluationContext.EVALUATION_CLASS_KEY, 1, VCFHeaderLineType.Character, "The evaluation class for the call or lack of call. It the values of the header key '" + EvaluationClass.VCF_HEADER_KEY + "'"));
header.addMetaDataLine(new VCFFormatHeaderLine(VariantEvaluationContext.TRUTH_GENOTYPE_KEY, 1, VCFHeaderLineType.Character, "The truth genotype"));
header.addMetaDataLine(new VCFFormatHeaderLine(VariantEvaluationContext.CALLED_TARGET_COUNT_KEY, 1, VCFHeaderLineType.Integer, "Number of targets covered by called segments"));
header.addMetaDataLine(new VCFFormatHeaderLine(VariantEvaluationContext.CALL_QUALITY_KEY, 1, VCFHeaderLineType.Float, "1 - The probability of th event in Phred scale (the maximum if ther are more than one segment"));
header.addMetaDataLine(new VCFFormatHeaderLine(VCFConstants.GENOTYPE_QUALITY_KEY, 1, VCFHeaderLineType.Integer, "The quality of the call (the maximum if there are more than one segment"));
header.addMetaDataLine(new VCFFormatHeaderLine(VCFConstants.GENOTYPE_FILTER_KEY, VCFHeaderLineCount.UNBOUNDED, VCFHeaderLineType.Character, "Genotype filters"));
// Info annotations.
header.addMetaDataLine(new VCFInfoHeaderLine(VariantEvaluationContext.TRUTH_ALLELE_FREQUENCY_KEY, VCFHeaderLineCount.A, VCFHeaderLineType.Float, "The frequency of the alternative alleles in the truth callset"));
header.addMetaDataLine(new VCFInfoHeaderLine(VariantEvaluationContext.TRUTH_ALLELE_NUMBER_KEY, 1, VCFHeaderLineType.Integer, "Total number of called alleles in the truth callset"));
header.addMetaDataLine(new VCFInfoHeaderLine(VariantEvaluationContext.CALLS_ALLELE_FREQUENCY_KEY, VCFHeaderLineCount.A, VCFHeaderLineType.Float, "The frequency of the alternative alleles in the actual callset"));
header.addMetaDataLine(new VCFInfoHeaderLine(VariantEvaluationContext.CALLS_ALLELE_NUMBER_KEY, 1, VCFHeaderLineType.Integer, "Total number of called alleles in the actual callset"));
header.addMetaDataLine(new VCFInfoHeaderLine(VariantEvaluationContext.TRUTH_TARGET_COUNT_KEY, 1, VCFHeaderLineType.Integer, "Number of targets overlapped by this variant"));
header.addMetaDataLine(new VCFInfoHeaderLine(VCFConstants.END_KEY, 1, VCFHeaderLineType.Integer, "Stop position for the variant"));
// Filter annotations.
for (final EvaluationFilter filter : EvaluationFilter.values()) {
header.addMetaDataLine(new VCFFilterHeaderLine(filter.name(), filter.description));
header.addMetaDataLine(new VCFFilterHeaderLine(filter.acronym, filter.description));
}
header.addMetaDataLine(new VCFFilterHeaderLine(EvaluationFilter.PASS, "Indicates that it passes all filters"));
result.writeHeader(header);
return result;
}
use of htsjdk.variant.variantcontext.writer.VariantContextWriter in project gatk by broadinstitute.
the class GATKVariantContextUtilsUnitTest method testCreateVCFWriterLenientFalse.
@Test(dataProvider = "createVCFWriterLenientData", expectedExceptions = IllegalStateException.class)
public void testCreateVCFWriterLenientFalse(final String outputExtension, // unused
final String indexExtension, final boolean createIndex, final boolean createMD5) throws IOException {
final File tmpDir = createTempDir("createVCFTest");
final File outputFile = new File(tmpDir.getAbsolutePath(), "createVCFTest" + outputExtension);
Options[] options = createIndex ? new Options[] { Options.INDEX_ON_THE_FLY } : new Options[] {};
try (final VariantContextWriter vcw = GATKVariantContextUtils.createVCFWriter(outputFile, makeSimpleSequenceDictionary(), createMD5, options)) {
writeHeader(vcw);
// write a bad attribute and throw...
writeBadVariant(vcw);
}
}
use of htsjdk.variant.variantcontext.writer.VariantContextWriter in project gatk by broadinstitute.
the class GATKVariantContextUtilsUnitTest method testCreateVCFWriterWithOptions.
@Test(dataProvider = "createVCFWriterData")
public void testCreateVCFWriterWithOptions(final String outputExtension, final String indexExtension, final boolean createIndex, final boolean createMD5) throws IOException {
final File tmpDir = createTempDir("createVCFTest");
final File outputFile = new File(tmpDir.getAbsolutePath(), "createVCFTest" + outputExtension);
Options[] options = createIndex ? new Options[] { Options.INDEX_ON_THE_FLY } : new Options[] {};
try (final VariantContextWriter writer = GATKVariantContextUtils.createVCFWriter(outputFile, makeSimpleSequenceDictionary(), createMD5, options)) {
writeHeader(writer);
}
final File outFileIndex = new File(outputFile.getAbsolutePath() + indexExtension);
final File outFileMD5 = new File(outputFile.getAbsolutePath() + ".md5");
Assert.assertTrue(outputFile.exists(), "No output file was not created");
Assert.assertEquals(outFileIndex.exists(), createIndex, "The createIndex argument was not honored");
Assert.assertEquals(outFileMD5.exists(), createMD5, "The createMD5 argument was not honored");
verifyFileType(outputFile, outputExtension);
}
use of htsjdk.variant.variantcontext.writer.VariantContextWriter in project gatk by broadinstitute.
the class GATKVariantContextUtilsUnitTest method testCreateVCFWriterLenientTrue.
@Test(dataProvider = "createVCFWriterLenientData")
public void testCreateVCFWriterLenientTrue(final String outputExtension, final String indexExtension, final boolean createIndex, final boolean createMD5) throws IOException {
final File tmpDir = createTempDir("createVCFTest");
final File outputFile = new File(tmpDir.getAbsolutePath(), "createVCFTest" + outputExtension);
Options[] options = createIndex ? new Options[] { Options.ALLOW_MISSING_FIELDS_IN_HEADER, Options.INDEX_ON_THE_FLY } : new Options[] { Options.ALLOW_MISSING_FIELDS_IN_HEADER };
try (final VariantContextWriter vcw = GATKVariantContextUtils.createVCFWriter(outputFile, makeSimpleSequenceDictionary(), createMD5, options)) {
writeHeader(vcw);
// verify leniency by writing a bogus attribute
writeBadVariant(vcw);
}
final File outFileIndex = new File(outputFile.getAbsolutePath() + indexExtension);
final File outFileMD5 = new File(outputFile.getAbsolutePath() + ".md5");
Assert.assertTrue(outputFile.exists(), "No output file was not created");
Assert.assertEquals(outFileIndex.exists(), createIndex, "The createIndex argument was not honored");
Assert.assertEquals(outFileMD5.exists(), createMD5, "The createMD5 argument was not honored");
}
Aggregations