本文整理汇总了Java中htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder类的典型用法代码示例。如果您正苦于以下问题:Java VariantContextWriterBuilder类的具体用法?Java VariantContextWriterBuilder怎么用?Java VariantContextWriterBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VariantContextWriterBuilder类属于htsjdk.variant.variantcontext.writer包,在下文中一共展示了VariantContextWriterBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createVCFWriter
import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入依赖的package包/类
public static VariantContextWriter createVCFWriter(final File outFile,VCFHeader header) {
Utils.nonNull(outFile);
VariantContextWriterBuilder vcWriterBuilder = new VariantContextWriterBuilder().clearOptions()
.setOutputFile(outFile);
if (lenientVCFProcessing) {
vcWriterBuilder = vcWriterBuilder.setOption(Options.ALLOW_MISSING_FIELDS_IN_HEADER);
}
if (createOutputVariantIndex && null != header) {
vcWriterBuilder = vcWriterBuilder.setOption(Options.INDEX_ON_THE_FLY);
}
if (createOutputVariantMD5) {
vcWriterBuilder.setCreateMD5();
}
if (null != header) {
vcWriterBuilder = vcWriterBuilder.setReferenceDictionary(header.getSequenceDictionary());
}
return vcWriterBuilder.build();
}
示例2: processVariants
import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入依赖的package包/类
private static void processVariants(@NotNull final String filePath, @NotNull final Slicer highConfidenceSlicer,
@NotNull final String outputVcf, @NotNull final String sampleName, @NotNull final String tumorBam) throws HartwigException {
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);
}
示例3: processVariants
import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入依赖的package包/类
private static void processVariants(@NotNull final String filePath, @NotNull final String outputVcf, @NotNull final String tumorBam) {
final VCFFileReader vcfReader = new VCFFileReader(new File(filePath), false);
final VariantContextWriter vcfWriter = new VariantContextWriterBuilder().setOutputFile(outputVcf)
.setReferenceDictionary(vcfReader.getFileHeader().getSequenceDictionary())
.build();
vcfWriter.writeHeader(vcfReader.getFileHeader());
final MNVValidator validator = ImmutableMNVValidator.of(tumorBam);
Pair<PotentialMNVRegion, Optional<PotentialMNVRegion>> outputPair = ImmutablePair.of(PotentialMNVRegion.empty(), Optional.empty());
for (final VariantContext variant : vcfReader) {
final PotentialMNVRegion potentialMNV = outputPair.getLeft();
outputPair = MNVDetector.fitsMNVRegion(potentialMNV, variant);
outputPair.getRight().ifPresent(mnvRegion -> validator.mergeVariants(mnvRegion).forEach(vcfWriter::add));
}
validator.mergeVariants(outputPair.getLeft()).forEach(vcfWriter::add);
vcfWriter.close();
vcfReader.close();
LOGGER.info("Written output variants to " + outputVcf);
}
示例4: convertVariantToVcf
import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入依赖的package包/类
/**
* Converts a list of variants into a VCF file, given a {@link VCFHeader}
* and an {@link OutputStream}.
* <p> This function uses HTSJDK to create {@link VariantCall} objects then
* writes them to the given output stream. Note that this implementation depends
* heavily on HTSJDK and makes the same assumptions as HTSJDK (e.g. integer values GQ).
*
* @param header The header to use to generate the output VCF
* @param variants A list of variants to encode in the output VCF
* @param os The output stream to which to write the generated VCF
*/
public static void convertVariantToVcf(VCFHeader header, List<Variant> variants,
OutputStream os, boolean writeHeader) {
if (vcfWriter == null) {
vcfWriter = new VariantContextWriterBuilder().clearOptions()
.setOutputVCFStream(os).build();
}
if (writeHeader) {
vcfWriter.writeHeader(header);
}
for (Variant currVariant : variants) {
vcfWriter.add(getContextFromVariant(header, currVariant));
}
}
示例5: vcfHeaderToStrings
import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入依赖的package包/类
public static List<String> vcfHeaderToStrings(VCFHeader header) {
File fakeVCFFile;
List<String> str= new ArrayList<String>();
try {
fakeVCFFile = Utils.createTempFile(".vcfheader", ".vcf");
fakeVCFFile.deleteOnExit();
final VariantContextWriter writer = new VariantContextWriterBuilder()
.setOutputFile(fakeVCFFile)
.setReferenceDictionary(header.getSequenceDictionary())
.setOptions(EnumSet.of(Options.ALLOW_MISSING_FIELDS_IN_HEADER, Options.WRITE_FULL_FORMAT_FIELD))
.build();
writer.writeHeader(header);
writer.close();
BufferedReader br= new BufferedReader(new FileReader(fakeVCFFile));
String line= br.readLine();
while(line != null){
str.add(line);
line= br.readLine();
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
示例6: getVariantContextWriter
import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入依赖的package包/类
/** Gets the variant context writer if the output VCF is to be written, otherwise empty. */
private Optional<VariantContextWriter> getVariantContextWriter(final VCFFileReader truthReader, final VCFFileReader callReader) {
if (OUTPUT_VCF) {
final File outputVcfFile = new File(OUTPUT + OUTPUT_VCF_FILE_EXTENSION);
final VariantContextWriterBuilder builder = new VariantContextWriterBuilder()
.setOutputFile(outputVcfFile)
.setReferenceDictionary(callReader.getFileHeader().getSequenceDictionary())
.setOption(Options.ALLOW_MISSING_FIELDS_IN_HEADER)
.setOption(Options.INDEX_ON_THE_FLY);
final VariantContextWriter writer = builder.build();
// create the output header
final List<String> sampleNames = Arrays.asList(OUTPUT_VCF_CALL_SAMPLE_NAME, OUTPUT_VCF_TRUTH_SAMPLE_NAME);
final Set<VCFHeaderLine> headerLines = new HashSet<>();
headerLines.addAll(callReader.getFileHeader().getMetaDataInInputOrder());
headerLines.addAll(truthReader.getFileHeader().getMetaDataInInputOrder());
headerLines.add(CONTINGENCY_STATE_HEADER_LINE);
writer.writeHeader(new VCFHeader(headerLines, sampleNames));
return Optional.of(writer);
}
else {
return Optional.empty();
}
}
示例7: createTemporaryIndexedVcfFromInput
import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入依赖的package包/类
/**
* This method makes a copy of the input VCF and creates an index file for it in the same location.
* This is done so that we don't need to store the index file in the same repo
* The copy of the input is done so that it and its index are in the same directory which is typically required.
*
* @param vcfFile the vcf file to index
* @return File a vcf file (index file is created in same path).
*/
public static File createTemporaryIndexedVcfFromInput(final File vcfFile, final String tempFilePrefix) throws IOException {
final String extension;
if (vcfFile.getAbsolutePath().endsWith(".vcf")) extension = ".vcf";
else if (vcfFile.getAbsolutePath().endsWith(".vcf.gz")) extension = ".vcf.gz";
else
throw new IllegalArgumentException("couldn't find a .vcf or .vcf.gz ending for input file " + vcfFile.getAbsolutePath());
File output = createTemporaryIndexedVcfFile(tempFilePrefix, extension);
final VCFFileReader in = new VCFFileReader(vcfFile, false);
final VCFHeader header = in.getFileHeader();
final VariantContextWriter out = new VariantContextWriterBuilder().
setReferenceDictionary(header.getSequenceDictionary()).
setOptions(EnumSet.of(Options.INDEX_ON_THE_FLY)).
setOutputFile(output).build();
out.writeHeader(header);
for (final VariantContext ctx : in) {
out.add(ctx);
}
out.close();
in.close();
return output;
}
示例8: init
import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入依赖的package包/类
private void init(
OutputStream output, VCFHeader header, final boolean writeHeader)
throws IOException
{
final BCFStoppableOutputStream stopOut =
new BCFStoppableOutputStream(!writeHeader, output);
writer = new VariantContextWriterBuilder().clearOptions()
.setOption(Options.FORCE_BCF)
.setOutputBCFStream(stopOut).build();
writer.writeHeader(header);
stopOut.stopped = false;
setInputHeader(header);
}
示例9: getVariantContextWriter
import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入依赖的package包/类
private static VariantContextWriter getVariantContextWriter(final OutputStream outputStream,
final SAMSequenceDictionary referenceSequenceDictionary) {
VariantContextWriterBuilder vcWriterBuilder = new VariantContextWriterBuilder()
.clearOptions()
.setOutputStream(outputStream);
if (null != referenceSequenceDictionary) {
vcWriterBuilder = vcWriterBuilder.setReferenceDictionary(referenceSequenceDictionary);
}
// todo: remove this when things are solid?
vcWriterBuilder = vcWriterBuilder.setOption(Options.ALLOW_MISSING_FIELDS_IN_HEADER);
for (final Options opt : new Options[]{}) {
vcWriterBuilder = vcWriterBuilder.setOption(opt);
}
return vcWriterBuilder.build();
}
示例10: openVariantContextWriter
import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入依赖的package包/类
/**
* Return a new {@link VariantContextWriter} that uses the header from <code>reader</code> but has the header
* extended header through {@link #extendHeaderFields}.
*
* @param header
* the VCF header to use for the construction
* @param fileName
* path to output file
* @param additionalHeaderLines
* additional {@link VCFHeaderLine}s to add
* @param generateIndex
* whether or not to generate an index
* @return A correct writer for variantContexts
*/
public static VariantContextWriter openVariantContextWriter(VCFHeader header, String fileName,
Collection<VCFHeaderLine> additionalHeaderLines, boolean generateIndex) {
VariantContextWriterBuilder builder = makeBuilder(header);
builder.setOutputFile(new File(fileName));
if (!generateIndex)
builder.unsetOption(Options.INDEX_ON_THE_FLY);
// construct VariantContextWriter and write out header
VariantContextWriter out = builder.build();
final VCFHeader updatedHeader = extendHeaderFields(new VCFHeader(header));
for (VCFHeaderLine headerLine : additionalHeaderLines)
updatedHeader.addMetaDataLine(headerLine);
out.writeHeader(updatedHeader);
return out;
}
示例11: createVariantContextWriter
import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入依赖的package包/类
/**
* create a VariantContextWriter
* @param OUT output file or null to stdout
* @return
* @throws IOException
*/
public static VariantContextWriter createVariantContextWriter(final File OUT) throws IOException
{
if(OUT==null)
{
return createVariantContextWriterToStdout();
}
else
{
IOUtil.assertFileIsWritable(OUT);
final VariantContextWriterBuilder vcwb=new VariantContextWriterBuilder();
vcwb.setCreateMD5(false);
vcwb.setReferenceDictionary(null);
vcwb.clearOptions();
vcwb.setOutputFile(OUT);
return new VariantContextWriterDelayedFlush(vcwb.build());
}
}
示例12: initBuilder
import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入依赖的package包/类
private void initBuilder(OutputStream os, boolean doNotWriteGenotypes,
boolean allowMissingFieldsInHeader) {
builder = new VariantContextWriterBuilder();
builder.clearOptions();
if(doNotWriteGenotypes) {
builder.setOption(Options.DO_NOT_WRITE_GENOTYPES);
}
if(allowMissingFieldsInHeader) {
builder.setOption(Options.ALLOW_MISSING_FIELDS_IN_HEADER);
}
builder.setOutputStream(os);
}
示例13: processVariants
import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入依赖的package包/类
private static void processVariants(@NotNull final String filePath, @NotNull final String outputVcf, @NotNull final String outputBed,
boolean strelka) throws IOException, HartwigException {
final VCFFileReader vcfReader = new VCFFileReader(new File(filePath), false);
final VCFHeader outputHeader =
strelka ? generateOutputHeader(vcfReader.getFileHeader(), StrelkaPostProcess.TUMOR_GENOTYPE) : vcfReader.getFileHeader();
final BufferedWriter bedWriter = new BufferedWriter(new FileWriter(outputBed, false));
final VariantContextWriter vcfWriter = new VariantContextWriterBuilder().setOutputFile(outputVcf)
.setReferenceDictionary(outputHeader.getSequenceDictionary())
.build();
vcfWriter.writeHeader(outputHeader);
Pair<PotentialMNVRegion, Optional<PotentialMNVRegion>> outputPair = ImmutablePair.of(PotentialMNVRegion.empty(), Optional.empty());
for (final VariantContext rawVariant : vcfReader) {
final VariantContext variant =
strelka ? StrelkaPostProcess.simplifyVariant(rawVariant, StrelkaPostProcess.TUMOR_GENOTYPE) : rawVariant;
final PotentialMNVRegion potentialMNVregion = outputPair.getLeft();
outputPair = MNVDetector.fitsMNVRegion(potentialMNVregion, variant);
outputPair.getRight()
.ifPresent(mnvRegion -> filterMnvRegion(mnvRegion).ifPresent(filteredRegion -> writeMnvRegionToFiles(filteredRegion,
vcfWriter,
bedWriter,
"\n")));
}
filterMnvRegion(outputPair.getLeft()).ifPresent(mnvRegion -> writeMnvRegionToFiles(mnvRegion, vcfWriter, bedWriter, ""));
vcfWriter.close();
vcfReader.close();
bedWriter.close();
LOGGER.info("Written output variants to {}. Written bed regions to {}.", outputVcf, outputBed);
}
示例14: openVCFWriter
import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入依赖的package包/类
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;
}
示例15: doWork
import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入依赖的package包/类
@Override
protected int doWork() {
final ProgressLogger progress = new ProgressLogger(LOG, 10000);
IOUtil.assertFileIsReadable(INPUT);
IOUtil.assertFileIsWritable(OUTPUT);
final VCFFileReader reader = new VCFFileReader(INPUT, REQUIRE_INDEX);
final VCFHeader header = new VCFHeader(reader.getFileHeader());
final SAMSequenceDictionary sequenceDictionary = header.getSequenceDictionary();
if (CREATE_INDEX && sequenceDictionary == null) {
throw new PicardException("A sequence dictionary must be available in the input file when creating indexed output.");
}
final VariantContextWriterBuilder builder = new VariantContextWriterBuilder()
.setOutputFile(OUTPUT)
.setReferenceDictionary(sequenceDictionary);
if (CREATE_INDEX)
builder.setOption(Options.INDEX_ON_THE_FLY);
else
builder.unsetOption(Options.INDEX_ON_THE_FLY);
final VariantContextWriter writer = builder.build();
writer.writeHeader(header);
final CloseableIterator<VariantContext> iterator = reader.iterator();
while (iterator.hasNext()) {
final VariantContext context = iterator.next();
writer.add(context);
progress.record(context.getContig(), context.getStart());
}
CloserUtil.close(iterator);
CloserUtil.close(reader);
writer.close();
return 0;
}