本文整理汇总了Java中htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder.setOutputFile方法的典型用法代码示例。如果您正苦于以下问题:Java VariantContextWriterBuilder.setOutputFile方法的具体用法?Java VariantContextWriterBuilder.setOutputFile怎么用?Java VariantContextWriterBuilder.setOutputFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder
的用法示例。
在下文中一共展示了VariantContextWriterBuilder.setOutputFile方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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());
}
}
示例3: 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;
}
示例4: open
import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入方法依赖的package包/类
@Override
public void open(final ExecutionContext executionContext) throws ItemStreamException {
if(this.filenameFactory==null) throw new ItemStreamException("resource is not defined");
try {
final String filename = this.filenameFactory.apply(executionContext);
if(StringUtil.isBlank(filename)) throw new ItemStreamException("No output file defined.");
if(LOG.isInfoEnabled()) LOG.info("Opening "+filename+" for writing");
if(!Arrays.stream(IOUtil.VCF_EXTENSIONS).anyMatch(SUFF->filename.endsWith(SUFF)))
{
throw new ItemStreamException("Bad extension for a VCF file:" + filename);
}
final File vcfFile = new File(filename);
VCFHeader header= SpringBatchUtils.getVcfHeader(executionContext);
final VariantContextWriterBuilder vcwb = new VariantContextWriterBuilder();
vcwb.setOutputFile(vcfFile);
if(this.reference!=null)
{
final SAMSequenceDictionary dic=SAMSequenceDictionaryExtractor.extractDictionary(this.reference);
vcwb.setReferenceDictionary(dic);
if(header.getSequenceDictionary()==null) {
header = new VCFHeader(header);
header.setSequenceDictionary(dic);
}
}
else
{
vcwb.setReferenceDictionary(header.getSequenceDictionary());
}
vcwb.setCreateMD5(this.createMD5);
this.vcw = vcwb.build();
this.vcw.writeHeader(header);
}
catch(final Exception err)
{
priv_close();
throw new ItemStreamException(err);
}
}
示例5: doVcfToVcf
import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入方法依赖的package包/类
private int doVcfToVcf(String inputName, final VcfIterator vcfIn,final File outFile) throws IOException {
SortingVCFWriter sortingVCW=null;
VariantContextWriterBuilder vcwb=new VariantContextWriterBuilder();
VariantContextWriter w=null;
try {
SAMSequenceDictionary dict = vcfIn.getHeader().getSequenceDictionary();
if(dict!=null) vcwb.setReferenceDictionary(dict);
vcwb.setOutputFile(outFile);
vcwb.setOutputFileType(OutputType.BLOCK_COMPRESSED_VCF);
w = vcwb.build();
if(this.sort)
{
LOG.info("Creating a sorting writer");
sortingVCW= new SortingVCFWriter(w);
w=sortingVCW;
}
w.writeHeader(vcfIn.getHeader());
SAMSequenceDictionaryProgress progress=new SAMSequenceDictionaryProgress(vcfIn.getHeader());
while(vcfIn.hasNext())
{
w.add(progress.watch(vcfIn.next()));
}
progress.finish();
w.close();
w=null;
return RETURN_OK;
}
catch (Exception e)
{
if(outFile.exists() && outFile.isFile())
{
LOG.warn("Deleting "+outFile);
outFile.delete();
File tbi = new File(outFile.getPath()+TabixUtils.STANDARD_INDEX_EXTENSION);
if(tbi.exists() && tbi.isFile()) tbi.delete();
}
LOG.error(e);
return -1;
}
finally
{
CloserUtil.close(w);
}
}
示例6: saveVariants
import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入方法依赖的package包/类
private File saveVariants(Window owner,final File f) {
if(f==null) return null;
VariantContextWriterBuilder vcb = new VariantContextWriterBuilder();
VariantContextWriter w=null;
try {
SAMSequenceDictionary dict=this.vcfHeader.getSequenceDictionary();
if(dict!=null)
{
vcb.setReferenceDictionary(dict);
}
vcb.setOutputFile(f);
final VCFHeader header2=new VCFHeader(this.vcfHeader);
if(header2.getFormatHeaderLine(this.reviewFormat.getID())==null)
{
header2.addMetaDataLine(this.reviewFormat);
}
w = vcb.build();
w.writeHeader(header2);
int x=0;
while(x<this.genotypeTable.getItems().size())
{
VariantContext v1= this.genotypeTable.getItems().get(x).ctx;
List<Genotype> genotypes = new ArrayList<>();
genotypes.add(this.genotypeTable.getItems().get(x).makeGenotype());
int y=x+1;
while(y<this.genotypeTable.getItems().size())
{
VariantContext v2= this.genotypeTable.getItems().get(y).ctx;
if(v2!=v1) break;//yes '!=' is enough
genotypes.add(this.genotypeTable.getItems().get(y).makeGenotype());
y++;
}
VariantContextBuilder vb=new VariantContextBuilder(v1);
vb.genotypes(genotypes);
w.add(vb.make());
x=y;
}
w.close();
return f;
}
catch(final Exception err) {
JfxUtils.dialog().cause(err).show(owner);
return null;
}
finally
{
CloserUtil.close(w);
}
}
示例7: 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);
}