use of htsjdk.variant.variantcontext.writer.VariantContextWriter in project hmftools by hartwigmedical.
the class StrelkaPostProcessApplication method processVariants.
private static void processVariants(@NotNull final String filePath, @NotNull final Slicer highConfidenceSlicer, @NotNull final String outputVcf, @NotNull final String sampleName, @NotNull final String tumorBam) {
final VCFFileReader vcfReader = new VCFFileReader(new File(filePath), false);
final VCFHeader outputHeader = generateOutputHeader(vcfReader.getFileHeader(), sampleName);
final VariantContextWriter writer = new VariantContextWriterBuilder().setOutputFile(outputVcf).setReferenceDictionary(outputHeader.getSequenceDictionary()).build();
writer.writeHeader(outputHeader);
final MNVValidator validator = ImmutableMNVValidator.of(tumorBam);
Pair<PotentialMNVRegion, Optional<PotentialMNVRegion>> outputPair = ImmutablePair.of(PotentialMNVRegion.empty(), Optional.empty());
final VariantContextFilter filter = new StrelkaPostProcess(highConfidenceSlicer);
for (final VariantContext variantContext : vcfReader) {
if (filter.test(variantContext)) {
final VariantContext simplifiedVariant = StrelkaPostProcess.simplifyVariant(variantContext, sampleName);
final PotentialMNVRegion potentialMNV = outputPair.getLeft();
outputPair = MNVDetector.fitsMNVRegion(potentialMNV, simplifiedVariant);
outputPair.getRight().ifPresent(mnvRegion -> validator.mergeVariants(mnvRegion).forEach(writer::add));
}
}
validator.mergeVariants(outputPair.getLeft()).forEach(writer::add);
writer.close();
vcfReader.close();
LOGGER.info("Written output variants to " + outputVcf);
}
use of htsjdk.variant.variantcontext.writer.VariantContextWriter in project gridss by PapenfussLab.
the class IntermediateFilesTest method createVCF.
public void createVCF(GenomicProcessingContext context, File file, VariantContext... data) {
VariantContextWriter writer = context.getVariantContextWriter(file, true);
for (VariantContext vc : data) {
writer.add(vc);
}
writer.close();
}
use of htsjdk.variant.variantcontext.writer.VariantContextWriter in project gridss by PapenfussLab.
the class GenomicProcessingContext method getVariantContextWriter.
/**
* Gets a VCF file ready to write variants to
* A header based on this processing context will have already been written to the returned writer
* It is the responsibility of the caller to close the returned @link {@link VariantContextWriter}
* @param output file
* @return opened output VCF stream
*/
public VariantContextWriter getVariantContextWriter(File file, boolean createIndex) {
VariantContextWriterBuilder builder = getVariantContextWriterBuilder(file, createIndex);
VariantContextWriter vcfWriter = builder.build();
final VCFHeader vcfHeader = new VCFHeader();
GridssVcfConstants.addHeaders(vcfHeader);
vcfHeader.setSequenceDictionary(getReference().getSequenceDictionary());
vcfWriter.writeHeader(vcfHeader);
return vcfWriter;
}
use of htsjdk.variant.variantcontext.writer.VariantContextWriter in project gridss by PapenfussLab.
the class SimulatedChromosome method assemble.
protected void assemble(File fasta, File vcf, List<Fragment> fragList, boolean includeReference) throws IOException {
StringBuilder sb = new StringBuilder();
if (includeReference) {
sb.append(">");
sb.append(getChr());
sb.append("\n");
sb.append(new String(seq, StandardCharsets.US_ASCII));
sb.append("\n");
}
sb.append(">chromothripsis." + getChr() + "\n");
List<IdsvVariantContext> calls = Lists.newArrayList();
Fragment last = null;
for (int i = 0; i < fragList.size(); i++) {
Fragment f = fragList.get(i);
sb.append(f.getSequence());
if (last != null) {
BreakpointSummary bp = new BreakpointSummary(last.getEndBreakend(), f.getStartBreakend());
String event = String.format("truth_%d_", i);
calls.add(create(bp, event).make());
calls.add(create(bp.remoteBreakpoint(), event).make());
}
last = f;
}
Collections.sort(calls, IdsvVariantContext.ByLocationStart);
Files.write(sb.toString(), fasta, StandardCharsets.US_ASCII);
VariantContextWriter writer = context.getVariantContextWriter(vcf, true);
for (VariantContext vc : calls) {
writer.add(vc);
}
writer.close();
}
use of htsjdk.variant.variantcontext.writer.VariantContextWriter in project jvarkit by lindenb.
the class VcfGnomad method doVcfToVcf.
@Override
protected int doVcfToVcf(final String inputName, final VcfIterator iter, final VariantContextWriter delegate) {
final VariantContextWriter out = this.component.open(delegate);
final SAMSequenceDictionaryProgress progress = new SAMSequenceDictionaryProgress(iter.getHeader()).logger(LOG);
out.writeHeader(iter.getHeader());
while (iter.hasNext()) {
out.add(progress.watch(iter.next()));
}
out.close();
progress.finish();
return 0;
}
Aggregations