本文整理汇总了Java中htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder类的典型用法代码示例。如果您正苦于以下问题:Java VariantContextWriterBuilder类的具体用法?Java VariantContextWriterBuilder怎么用?Java VariantContextWriterBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VariantContextWriterBuilder类属于htsjdk.variant.variantcontext.writer包,在下文中一共展示了VariantContextWriterBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: 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);
}
开发者ID:hartwigmedical,项目名称:hmftools,代码行数:26,代码来源:StrelkaPostProcessApplication.java
示例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);
}
开发者ID:hartwigmedical,项目名称:hmftools,代码行数:19,代码来源:MNVValidatorApplication.java
示例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));
}
}
开发者ID:verilylifesciences,项目名称:genomewarp,代码行数:27,代码来源:VariantToVcf.java
示例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;
}
开发者ID:dariober,项目名称:ASCIIGenome,代码行数:27,代码来源:Utils.java
示例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();
}
}
开发者ID:broadinstitute,项目名称:picard,代码行数:25,代码来源:GenotypeConcordance.java
示例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;
}
开发者ID:broadinstitute,项目名称:picard,代码行数:34,代码来源:VcfTestUtils.java
示例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);
}
开发者ID:HadoopGenomics,项目名称:Hadoop-BAM,代码行数:17,代码来源:BCFRecordWriter.java
示例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();
}
开发者ID:broadinstitute,项目名称:gatk,代码行数:18,代码来源:SVVCFWriter.java
示例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;
}
开发者ID:charite,项目名称:jannovar,代码行数:30,代码来源:VariantContextWriterConstructionHelper.java
示例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());
}
}
开发者ID:lindenb,项目名称:jvarkit,代码行数:24,代码来源:VCFUtils.java
示例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);
}
开发者ID:BGI-flexlab,项目名称:SOAPgaea,代码行数:13,代码来源:VCFFileWriter.java
示例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);
}
开发者ID:hartwigmedical,项目名称:hmftools,代码行数:31,代码来源:MNVDetectorApplication.java
示例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;
}
开发者ID:broadinstitute,项目名称:gatk-protected,代码行数:41,代码来源:EvaluateCopyNumberTriStateCalls.java
示例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;
}
开发者ID:broadinstitute,项目名称:picard,代码行数:38,代码来源:VcfFormatConverter.java
示例16: writeAllViolations
import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入依赖的package包/类
private void writeAllViolations(final MendelianViolationDetector.Result result) {
if (VCF_DIR != null) {
LOG.info(String.format("Writing family violation VCFs to %s/", VCF_DIR.getAbsolutePath()));
final VariantContextComparator vcComparator = new VariantContextComparator(inputHeader.get().getContigLines());
final Set<VCFHeaderLine> headerLines = new LinkedHashSet<>(inputHeader.get().getMetaDataInInputOrder());
headerLines.add(new VCFInfoHeaderLine(MendelianViolationDetector.MENDELIAN_VIOLATION_KEY, 1, VCFHeaderLineType.String, "Type of mendelian violation."));
headerLines.add(new VCFInfoHeaderLine(MendelianViolationDetector.ORIGINAL_AC, VCFHeaderLineCount.A, VCFHeaderLineType.Integer, "Original AC"));
headerLines.add(new VCFInfoHeaderLine(MendelianViolationDetector.ORIGINAL_AF, VCFHeaderLineCount.A, VCFHeaderLineType.Float, "Original AF"));
headerLines.add(new VCFInfoHeaderLine(MendelianViolationDetector.ORIGINAL_AN, 1, VCFHeaderLineType.Integer, "Original AN"));
for (final PedFile.PedTrio trio : pedFile.get().values()) {
final File outputFile = new File(VCF_DIR, IOUtil.makeFileNameSafe(trio.getFamilyId() + IOUtil.VCF_FILE_EXTENSION));
LOG.info(String.format("Writing %s violation VCF to %s", trio.getFamilyId(), outputFile.getAbsolutePath()));
final VariantContextWriter out = new VariantContextWriterBuilder()
.setOutputFile(outputFile)
.unsetOption(INDEX_ON_THE_FLY)
.build();
final VCFHeader newHeader = new VCFHeader(headerLines, CollectionUtil.makeList(trio.getMaternalId(), trio.getPaternalId(), trio.getIndividualId()));
final TreeSet<VariantContext> orderedViolations = new TreeSet<>(vcComparator);
orderedViolations.addAll(result.violations().get(trio.getFamilyId()));
out.writeHeader(newHeader);
orderedViolations.forEach(out::add);
out.close();
}
}
}
开发者ID:broadinstitute,项目名称:picard,代码行数:33,代码来源:FindMendelianViolations.java
示例17: writeSortedOutput
import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入依赖的package包/类
private void writeSortedOutput(final VCFHeader outputHeader, final SortingCollection<VariantContext> sortedOutput) {
final ProgressLogger writeProgress = new ProgressLogger(log, 25000, "wrote", "records");
final EnumSet<Options> options = CREATE_INDEX ? EnumSet.of(Options.INDEX_ON_THE_FLY) : EnumSet.noneOf(Options.class);
final VariantContextWriter out = new VariantContextWriterBuilder().
setReferenceDictionary(outputHeader.getSequenceDictionary()).
setOptions(options).
setOutputFile(OUTPUT).build();
out.writeHeader(outputHeader);
for (final VariantContext variantContext : sortedOutput) {
out.add(variantContext);
writeProgress.record(variantContext.getContig(), variantContext.getStart());
}
out.close();
}
开发者ID:broadinstitute,项目名称:picard,代码行数:15,代码来源:SortVcf.java
示例18: doWork
import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入依赖的package包/类
@Override
protected int doWork() {
IOUtil.assertFileIsReadable(INPUT);
IOUtil.assertFileIsWritable(OUTPUT);
final VCFFileReader in = new VCFFileReader(INPUT);
final VCFHeader header = in.getFileHeader();
if (header.getGenotypeSamples().size() > 1) {
throw new IllegalArgumentException("Input VCF must be single-sample.");
}
if (OLD_SAMPLE_NAME != null && !OLD_SAMPLE_NAME.equals(header.getGenotypeSamples().get(0))) {
throw new IllegalArgumentException("Input VCF did not contain expected sample. Contained: " + header.getGenotypeSamples().get(0));
}
final EnumSet<Options> options = EnumSet.copyOf(VariantContextWriterBuilder.DEFAULT_OPTIONS);
if (CREATE_INDEX) options.add(Options.INDEX_ON_THE_FLY); else options.remove(Options.INDEX_ON_THE_FLY);
final VCFHeader outHeader = new VCFHeader(header.getMetaDataInInputOrder(), CollectionUtil.makeList(NEW_SAMPLE_NAME));
final VariantContextWriter out = new VariantContextWriterBuilder()
.setOptions(options)
.setOutputFile(OUTPUT).setReferenceDictionary(outHeader.getSequenceDictionary()).build();
out.writeHeader(outHeader);
for (final VariantContext ctx : in) {
out.add(ctx);
}
out.close();
in.close();
return 0;
}
开发者ID:broadinstitute,项目名称:picard,代码行数:35,代码来源:RenameSampleInVcf.java
示例19: writeAsVcf
import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder; //导入依赖的package包/类
public void writeAsVcf(final File output, final File refFile) throws FileNotFoundException {
ReferenceSequenceFile ref = new IndexedFastaSequenceFile(refFile);
try (VariantContextWriter writer = new VariantContextWriterBuilder()
.setOutputFile(output)
.setReferenceDictionary(ref.getSequenceDictionary())
.build()) {
final VCFHeader vcfHeader = new VCFHeader(
VCFUtils.withUpdatedContigsAsLines(Collections.emptySet(), refFile, header.getSequenceDictionary(), false),
Collections.singleton(HET_GENOTYPE_FOR_PHASING));
VCFUtils.withUpdatedContigsAsLines(Collections.emptySet(), refFile, header.getSequenceDictionary(), false);
vcfHeader.addMetaDataLine(new VCFHeaderLine(VCFHeaderVersion.VCF4_2.getFormatString(), VCFHeaderVersion.VCF4_2.getVersionString()));
vcfHeader.addMetaDataLine(new VCFInfoHeaderLine(VCFConstants.ALLELE_FREQUENCY_KEY, VCFHeaderLineCount.A, VCFHeaderLineType.Float, "Allele Frequency, for each ALT allele, in the same order as listed"));
vcfHeader.addMetaDataLine(new VCFFormatHeaderLine(VCFConstants.GENOTYPE_KEY, 1, VCFHeaderLineType.String, "Genotype"));
vcfHeader.addMetaDataLine(new VCFFormatHeaderLine(VCFConstants.PHASE_SET_KEY, 1, VCFHeaderLineType.String, "Phase-set identifier for phased genotypes."));
vcfHeader.addMetaDataLine(new VCFHeaderLine(VCFHeader.SOURCE_KEY,"HaplotypeMap::writeAsVcf"));
vcfHeader.addMetaDataLine(new VCFHeaderLine("reference","HaplotypeMap::writeAsVcf"));
// vcfHeader.addMetaDataLine(new VCFHeaderLine());
writer.writeHeader(vcfHeader);
final LinkedList<VariantContext> variants = new LinkedList<>(this.asVcf(ref));
variants.sort(vcfHeader.getVCFRecordComparator());
variants.forEach(writer::add);
}
}
开发者ID:broadinstitute,项目名称:picard,代码行数:29,代码来源:HaplotypeMap.java
示例20: 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
注:本文中的htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论