当前位置: 首页>>代码示例>>Java>>正文


Java VariantContextWriterBuilder.setOption方法代码示例

本文整理汇总了Java中htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder.setOption方法的典型用法代码示例。如果您正苦于以下问题:Java VariantContextWriterBuilder.setOption方法的具体用法?Java VariantContextWriterBuilder.setOption怎么用?Java VariantContextWriterBuilder.setOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder的用法示例。


在下文中一共展示了VariantContextWriterBuilder.setOption方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
 
开发者ID:BGI-flexlab,项目名称:SOAPgaea,代码行数:24,代码来源:VariantRecalibrator.java

示例2: 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();
}
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:18,代码来源:SVVCFWriter.java

示例3: 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);
}
 
开发者ID:BGI-flexlab,项目名称:SOAPgaea,代码行数:13,代码来源:VCFFileWriter.java

示例4: 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;
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:38,代码来源:VcfFormatConverter.java

示例5: createVCFWriter

import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入方法依赖的package包/类
/**
 * Creates a VariantContextWriter whose outputFile type is based on the extension of the output file name.
 * The default options set by VariantContextWriter are cleared before applying ALLOW_MISSING_FIELDS_IN_HEADER (if
 * <code>lenientProcessing</code> is set), followed by the set of options specified by any <code>options</code> args.
 *
 * @param outFile output File for this writer. May not be null.
 * @param referenceDictionary required if on the fly indexing is set, otherwise can be null
 * @param createMD5 true if an md5 file should be created
 * @param options variable length list of additional Options to be set for this writer
 * @returns VariantContextWriter must be closed by the caller
 */
public static VariantContextWriter createVCFWriter(
        final File outFile,
        final SAMSequenceDictionary referenceDictionary,
        final boolean createMD5,
        final Options... options)
{
    Utils.nonNull(outFile);

    VariantContextWriterBuilder vcWriterBuilder =
            new VariantContextWriterBuilder().clearOptions().setOutputFile(outFile);

    if (VariantContextWriterBuilder.OutputType.UNSPECIFIED == getVariantFileTypeFromExtension(outFile)) {
        // the only way the user has to specify an output type is by file extension, and htsjdk
        // throws if it can't map the file extension to a known vcf type, so fallback to a default
        // of VCF
        logger.warn(String.format(
                "Can't determine output variant file format from output file extension \"%s\". Defaulting to VCF.",
                FilenameUtils.getExtension(outFile.getPath())));
        vcWriterBuilder = vcWriterBuilder.setOutputFileType(VariantContextWriterBuilder.OutputType.VCF);
    }

    if (createMD5) {
        vcWriterBuilder.setCreateMD5();
    }

    if (null != referenceDictionary) {
        vcWriterBuilder = vcWriterBuilder.setReferenceDictionary(referenceDictionary);
    }

    for (Options opt : options) {
        vcWriterBuilder = vcWriterBuilder.setOption(opt);
    }

    return vcWriterBuilder.build();
}
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:47,代码来源:GATKVariantContextUtils.java

示例6: makeBuilder

import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入方法依赖的package包/类
/**
 * Common parts of {@link VariantContextWriterBuilder} creation for the openVariantContextWriter functions.
 */
private static VariantContextWriterBuilder makeBuilder(VCFHeader header) {
	// construct factory object for VariantContextWriter
	VariantContextWriterBuilder builder = new VariantContextWriterBuilder();
	builder.setReferenceDictionary(header.getSequenceDictionary());
	// Be more lenient in missing header fields.
	builder.setOption(Options.ALLOW_MISSING_FIELDS_IN_HEADER);
	// Disable on-the-fly generation of Tribble index if the input file does not have a sequence dictionary.
	if (header.getSequenceDictionary() == null)
		builder.unsetOption(Options.INDEX_ON_THE_FLY);
	return builder;
}
 
开发者ID:charite,项目名称:jannovar,代码行数:15,代码来源:VariantContextWriterConstructionHelper.java

示例7: openOutputFile

import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入方法依赖的package包/类
private VariantContextWriter openOutputFile() {
	VariantContextWriterBuilder builder = new VariantContextWriterBuilder()
			.setReferenceDictionary(fasta.getSequenceDictionary()).setOutputFile(options.getPathOutputVCF());
	if (options.getPathOutputVCF().endsWith(".gz") || options.getPathOutputVCF().endsWith(".bcf"))
		builder.setOption(Options.INDEX_ON_THE_FLY);
	else
		builder.unsetOption(Options.INDEX_ON_THE_FLY);
	VariantContextWriter writer = builder.build();

	VCFHeader header = new VCFHeader();
	int i = 0;
	for (SAMSequenceRecord record : fasta.getSequenceDictionary().getSequences()) {
		Map<String, String> mapping = new TreeMap<String, String>();
		mapping.put("ID", record.getSequenceName());
		mapping.put("length", Integer.toString(record.getSequenceLength()));
		header.addMetaDataLine(new VCFContigHeaderLine(mapping, i++));
	}

	header.addMetaDataLine(new VCFSimpleHeaderLine("ALT", "ERROR", "Error in conversion"));
	header.addMetaDataLine(new VCFFilterHeaderLine("PARSE_ERROR",
			"Problem in parsing original HGVS variant string, written out as variant at 1:g.1N>N"));
	header.addMetaDataLine(new VCFInfoHeaderLine("ERROR_MESSAGE", 1, VCFHeaderLineType.String, "Error message"));
	header.addMetaDataLine(new VCFInfoHeaderLine("ORIG_VAR", 1, VCFHeaderLineType.String,
			"Original HGVS variant string from input file to hgvs-to-vcf"));

	writer.writeHeader(header);

	return writer;
}
 
开发者ID:charite,项目名称:jannovar,代码行数:30,代码来源:ProjectTranscriptToChromosome.java

示例8: doWork

import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入方法依赖的package包/类
@Override
protected int doWork() {
    IOUtil.assertFileIsReadable(INPUT);
    IOUtil.assertFileIsWritable(OUTPUT);

 final VCFFileReader reader = new VCFFileReader(INPUT, false);
 final VCFHeader inputVcfHeader = new VCFHeader(reader.getFileHeader().getMetaDataInInputOrder());
 final SAMSequenceDictionary sequenceDictionary = inputVcfHeader.getSequenceDictionary();

 if (CREATE_INDEX && sequenceDictionary == null) {
  throw new PicardException("A sequence dictionary must be available (either through the input file or by setting it explicitly) when creating indexed output.");
 }

    final ProgressLogger progress = new ProgressLogger(Log.getInstance(MakeSitesOnlyVcf.class), 10000);

    // Setup the site-only file writer
    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();

    final VCFHeader header = new VCFHeader(inputVcfHeader.getMetaDataInInputOrder(), SAMPLE);
    writer.writeHeader(header);

    // Go through the input, strip the records and write them to the output
    final CloseableIterator<VariantContext> iterator = reader.iterator();
 while (iterator.hasNext()) {
  final VariantContext full = iterator.next();
        final VariantContext site = subsetToSamplesWithOriginalAnnotations(full, SAMPLE);
        writer.add(site);
        progress.record(site.getContig(), site.getStart());
    }

 CloserUtil.close(iterator);
 CloserUtil.close(reader);
 writer.close();

    return 0;
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:44,代码来源:MakeSitesOnlyVcf.java

示例9: doWork

import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入方法依赖的package包/类
@Override
protected int doWork() {
    final ProgressLogger progress = new ProgressLogger(log, 10000);
    final List<String> sampleList = new ArrayList<String>();
    INPUT = IOUtil.unrollFiles(INPUT, IOUtil.VCF_EXTENSIONS);
    final Collection<CloseableIterator<VariantContext>> iteratorCollection = new ArrayList<CloseableIterator<VariantContext>>(INPUT.size());
    final Collection<VCFHeader> headers = new HashSet<VCFHeader>(INPUT.size());
    VariantContextComparator variantContextComparator = null;
    SAMSequenceDictionary sequenceDictionary = null;

    if (SEQUENCE_DICTIONARY != null) {
        sequenceDictionary = SamReaderFactory.makeDefault().referenceSequence(REFERENCE_SEQUENCE).open(SEQUENCE_DICTIONARY).getFileHeader().getSequenceDictionary();
    }

    for (final File file : INPUT) {
        IOUtil.assertFileIsReadable(file);
        final VCFFileReader fileReader = new VCFFileReader(file, false);
        final VCFHeader fileHeader = fileReader.getFileHeader();

        if (variantContextComparator == null) {
            variantContextComparator = fileHeader.getVCFRecordComparator();
        } else {
            if (!variantContextComparator.isCompatible(fileHeader.getContigLines())) {
                throw new IllegalArgumentException(
                        "The contig entries in input file " + file.getAbsolutePath() + " are not compatible with the others.");
            }
        }

        if (sequenceDictionary == null) sequenceDictionary = fileHeader.getSequenceDictionary();

        if (sampleList.isEmpty()) {
            sampleList.addAll(fileHeader.getSampleNamesInOrder());
        } else {
            if (!sampleList.equals(fileHeader.getSampleNamesInOrder())) {
                throw new IllegalArgumentException("Input file " + file.getAbsolutePath() + " has sample entries that don't match the other files.");
            }
        }

        headers.add(fileHeader);
        iteratorCollection.add(fileReader.iterator());
    }

    if (CREATE_INDEX && sequenceDictionary == null) {
        throw new PicardException("A sequence dictionary must be available (either through the input file or by setting it explicitly) 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(new VCFHeader(VCFUtils.smartMergeHeaders(headers, false), sampleList));

    final MergingIterator<VariantContext> mergingIterator = new MergingIterator<VariantContext>(variantContextComparator, iteratorCollection);
    while (mergingIterator.hasNext()) {
        final VariantContext context = mergingIterator.next();
        writer.add(context);
        progress.record(context.getContig(), context.getStart());
    }

    CloserUtil.close(mergingIterator);
    writer.close();
    return 0;
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:71,代码来源:MergeVcfs.java

示例10: doWork

import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入方法依赖的package包/类
@Override
protected int doWork() {
    IOUtil.assertFileIsReadable(INPUT);
    final ProgressLogger progress = new ProgressLogger(log, 10000);

    final VCFFileReader fileReader = new VCFFileReader(INPUT);
    final VCFHeader fileHeader = fileReader.getFileHeader();

    final SAMSequenceDictionary sequenceDictionary =
            SEQUENCE_DICTIONARY != null
                    ? SamReaderFactory.makeDefault().referenceSequence(REFERENCE_SEQUENCE).getFileHeader(SEQUENCE_DICTIONARY).getSequenceDictionary()
                    : fileHeader.getSequenceDictionary();
    if (CREATE_INDEX && sequenceDictionary == null) {
        throw new PicardException("A sequence dictionary must be available (either through the input file or by setting it explicitly) when creating indexed output.");
    }

    final VariantContextWriterBuilder builder = new VariantContextWriterBuilder()
            .setReferenceDictionary(sequenceDictionary)
            .clearOptions();
    if (CREATE_INDEX)
        builder.setOption(Options.INDEX_ON_THE_FLY);

    final VariantContextWriter snpWriter = builder.setOutputFile(SNP_OUTPUT).build();
    final VariantContextWriter indelWriter = builder.setOutputFile(INDEL_OUTPUT).build();
    snpWriter.writeHeader(fileHeader);
    indelWriter.writeHeader(fileHeader);

    int incorrectVariantCount = 0;

    final CloseableIterator<VariantContext> iterator = fileReader.iterator();
    while (iterator.hasNext()) {
        final VariantContext context = iterator.next();
        if (context.isIndel()) indelWriter.add(context);
        else if (context.isSNP()) snpWriter.add(context);
        else {
            if (STRICT) throw new IllegalStateException("Found a record with type " + context.getType().name());
            else incorrectVariantCount++;
        }

        progress.record(context.getContig(), context.getStart());
    }

    if (incorrectVariantCount > 0) {
        log.debug("Found " + incorrectVariantCount + " records that didn't match SNP or INDEL");
    }

    CloserUtil.close(iterator);
    CloserUtil.close(fileReader);
    snpWriter.close();
    indelWriter.close();

    return 0;
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:54,代码来源:SplitVcfs.java

示例11: doWork

import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入方法依赖的package包/类
@Override
protected int doWork() {
    IOUtil.assertFileIsReadable(INPUT);
    IOUtil.assertFileIsReadable(SEQUENCE_DICTIONARY);
    IOUtil.assertFileIsWritable(OUTPUT);

    final SAMSequenceDictionary samSequenceDictionary = SAMSequenceDictionaryExtractor.extractDictionary(SEQUENCE_DICTIONARY.toPath());

    final VCFFileReader fileReader = new VCFFileReader(INPUT, false);
    final VCFHeader fileHeader = fileReader.getFileHeader();

    final VariantContextWriterBuilder builder = new VariantContextWriterBuilder()
            .setReferenceDictionary(samSequenceDictionary)
            .clearOptions();
    if (CREATE_INDEX)
        builder.setOption(Options.INDEX_ON_THE_FLY);

    try {
        builder.setOutputStream(new FileOutputStream(OUTPUT));
    } catch (final FileNotFoundException ex ) {
        throw new PicardException("Could not open " + OUTPUT.getAbsolutePath() + ": " + ex.getMessage(), ex);
    }

    final VariantContextWriter vcfWriter = builder.build();
    fileHeader.setSequenceDictionary(samSequenceDictionary);
    vcfWriter.writeHeader(fileHeader);

    final ProgressLogger progress = new ProgressLogger(log, 10000);
    final CloseableIterator<VariantContext> iterator = fileReader.iterator();
    while (iterator.hasNext()) {
        final VariantContext context = iterator.next();
        vcfWriter.add(context);
        progress.record(context.getContig(), context.getStart());
    }

    CloserUtil.close(iterator);
    CloserUtil.close(fileReader);
    vcfWriter.close();

    return 0;
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:42,代码来源:UpdateVcfSequenceDictionary.java

示例12: writeHeader

import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入方法依赖的package包/类
@Override
public void writeHeader(final VCFHeader header) {
	if(this.delegate!=null) {
		throw new IllegalStateException("WriteHeader called twice");
		}
	
	SAMSequenceDictionary dict=config.dict;
	if(config.createIndex &&  dict==null) {
		dict= header.getSequenceDictionary();
		}
	
	final VariantContextWriterBuilder builder = this.config.createVariantContextWriterBuilder();
	builder.unsetOption(Options.INDEX_ON_THE_FLY);
	if(dict!=null) {
		builder.setReferenceDictionary(dict);
		}
	
	if(this.outputFileOrNull==null) {
		builder.setCreateMD5(false);
		if(this.config.outputbcf) {
			builder.setOutputBCFStream(this._stdout);
			}
		else
			{
			builder.setOutputVCFStream(this._stdout);
			}
		}
	else
		{
		builder.setCreateMD5(this.config.createMd5);
		if(this.config.createIndex)
			{
			if(dict==null|| dict.isEmpty()) {
				throw new JvarkitException.DictionaryMissing("Cannot index vcf when SamSequence dictionary missing");
				}
			builder.setOption(Options.INDEX_ON_THE_FLY);
			}
		builder.setOutputFile(this.outputFileOrNull);
		}
	this.delegate = builder.build();
	this.delegate.writeHeader(header);
	}
 
开发者ID:lindenb,项目名称:jvarkit,代码行数:43,代码来源:PostponedVariantContextWriter.java


注:本文中的htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder.setOption方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。