本文整理汇总了Java中htsjdk.variant.variantcontext.writer.VariantContextWriter类的典型用法代码示例。如果您正苦于以下问题:Java VariantContextWriter类的具体用法?Java VariantContextWriter怎么用?Java VariantContextWriter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
VariantContextWriter类属于htsjdk.variant.variantcontext.writer包,在下文中一共展示了VariantContextWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeOutRecalibrationTable
import htsjdk.variant.variantcontext.writer.VariantContextWriter; //导入依赖的package包/类
public void writeOutRecalibrationTable( final VariantContextWriter recalWriter ) {
// we need to sort in coordinate order in order to produce a valid VCF
Collections.sort( data, new Comparator<VariantDatum>() {
public int compare(VariantDatum vd1, VariantDatum vd2) {
return vd1.loc.compareTo(vd2.loc);
}} );
// create dummy alleles to be used
final List<Allele> alleles = new ArrayList<Allele>(2);
alleles.add(Allele.create("N", true));
alleles.add(Allele.create("<VQSR>", false));
// to be used for the important INFO tags
final HashMap<String, Object> attributes = new HashMap<String, Object>(3);
for( final VariantDatum datum : data ) {
attributes.put(VCFConstants.END_KEY, datum.loc.getStop());
attributes.put(VCFQualityControl.VQS_LOD_KEY, String.format("%.4f", datum.lod));
attributes.put(VCFQualityControl.CULPRIT_KEY, (datum.worstAnnotation != -1 ? annotationKeys.get(datum.worstAnnotation) : "NULL"));
VariantContextBuilder builder = new VariantContextBuilder("VQSR", datum.loc.getContig(), datum.loc.getStart(), datum.loc.getStop(), alleles).attributes(attributes);
recalWriter.add(builder.make());
}
}
示例2: writeOutRecalibrationTable
import htsjdk.variant.variantcontext.writer.VariantContextWriter; //导入依赖的package包/类
public void writeOutRecalibrationTable(final VariantContextWriter recalWriter,
final SAMSequenceDictionary seqDictionary) {
// we need to sort in coordinate order in order to produce a valid VCF
Collections.sort(data, VariantDatum.getComparator(seqDictionary));
// create dummy alleles to be used
List<Allele> alleles = Arrays.asList(Allele.create("N", true), Allele.create("<VQSR>", false));
for (final VariantDatum datum : data) {
if (VRAC.useASannotations)
alleles = Arrays.asList(datum.referenceAllele, datum.alternateAllele);
VariantContextBuilder builder = new VariantContextBuilder("VQSR", datum.loc.getContig(),
datum.loc.getStart(), datum.loc.getStop(), alleles);
builder.attribute(VCFConstants.END_KEY, datum.loc.getStop());
builder.attribute(GaeaVCFConstants.VQS_LOD_KEY, String.format("%.4f", datum.lod));
builder.attribute(GaeaVCFConstants.CULPRIT_KEY,
(datum.worstAnnotation != -1 ? annotationKeys.get(datum.worstAnnotation) : "NULL"));
if (datum.atTrainingSite)
builder.attribute(GaeaVCFConstants.POSITIVE_LABEL_KEY, true);
if (datum.atAntiTrainingSite)
builder.attribute(GaeaVCFConstants.NEGATIVE_LABEL_KEY, true);
recalWriter.add(builder.make());
}
}
示例3: createVCFWriter
import htsjdk.variant.variantcontext.writer.VariantContextWriter; //导入依赖的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();
}
示例4: processVariants
import htsjdk.variant.variantcontext.writer.VariantContextWriter; //导入依赖的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);
}
示例5: processVariants
import htsjdk.variant.variantcontext.writer.VariantContextWriter; //导入依赖的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);
}
示例6: vcfHeaderToStrings
import htsjdk.variant.variantcontext.writer.VariantContextWriter; //导入依赖的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;
}
示例7: encodeAll
import htsjdk.variant.variantcontext.writer.VariantContextWriter; //导入依赖的package包/类
@Override
public Map<String, Object> encodeAll(OutputStream outputStream, Iterator<? extends VCFVariant> features) throws IOException {
SAMSequenceDictionary seqDict = new SAMSequenceDictionary();
EnumSet<Options> options = VariantContextWriterFactory.DEFAULT_OPTIONS;
options.add(Options.ALLOW_MISSING_FIELDS_IN_HEADER);
options.remove(Options.INDEX_ON_THE_FLY);
VariantContextWriter writer = VariantContextWriterFactory.create(outputStream, seqDict, options);
writer.writeHeader(this.header);
while(features.hasNext()){
writer.add(features.next().getVariantContext());
}
return null;
}
示例8: composeVariantContextAndWrite
import htsjdk.variant.variantcontext.writer.VariantContextWriter; //导入依赖的package包/类
/**
* For each segment in genotypingSegments, compose the variant context and write to outputWriter
*
* @param genotypingSegments a list of genotyping segments
* @param outputWriter a VCF writer
* @param variantPrefix a prefix for composing variant IDs
* @param commandLine (optional) command line used to generated the data
*/
private void composeVariantContextAndWrite(@Nonnull final List<GenotypingSegment> genotypingSegments,
@Nonnull final VariantContextWriter outputWriter,
@Nonnull final String variantPrefix,
@Nullable final String commandLine) {
outputWriter.writeHeader(composeHeader(commandLine));
int counter = 0;
int prevReportedDonePercentage = -1;
for (final GenotypingSegment segment : genotypingSegments) {
final int donePercentage = (int)(100 * counter / (double)genotypingSegments.size());
if (donePercentage % 10 == 0 && prevReportedDonePercentage != donePercentage) {
logger.info(String.format("%d%% done...", donePercentage));
prevReportedDonePercentage = donePercentage;
}
final VariantContext variant = composeVariantContext(segment, variantPrefix);
counter++;
outputWriter.add(variant);
}
logger.info("100% done.");
}
示例9: makeVCFWriter
import htsjdk.variant.variantcontext.writer.VariantContextWriter; //导入依赖的package包/类
/**
* Create a VCF or GVCF writer as appropriate, given our arguments
*
* @param outputVCF location to which the vcf should be written
* @param readsDictionary sequence dictionary for the reads
* @return a VCF or GVCF writer as appropriate, ready to use
*/
public VariantContextWriter makeVCFWriter( final String outputVCF, final SAMSequenceDictionary readsDictionary ) {
Utils.nonNull(outputVCF);
Utils.nonNull(readsDictionary);
VariantContextWriter writer = GATKVariantContextUtils.createVCFWriter(new File(outputVCF), readsDictionary, false);
if ( hcArgs.emitReferenceConfidence == ReferenceConfidenceMode.GVCF ) {
try {
writer = new GVCFWriter(writer, hcArgs.GVCFGQBands, hcArgs.genotypeArgs.samplePloidy);
} catch ( IllegalArgumentException e ) {
throw new CommandLineException.BadArgumentValue("GQBands", "are malformed: " + e.getMessage());
}
}
return writer;
}
示例10: writeHeader
import htsjdk.variant.variantcontext.writer.VariantContextWriter; //导入依赖的package包/类
public void writeHeader(final VariantContextWriter vcfWriter, final SAMSequenceDictionary sequenceDictionary,
final Set<VCFHeaderLine> defaultToolHeaderLines) {
final Set<VCFHeaderLine> headerInfo = new HashSet<>();
// all annotation fields from VariantAnnotatorEngine
headerInfo.addAll(annotationEngine.getVCFAnnotationDescriptions());
headerInfo.addAll(defaultToolHeaderLines);
// all callers need to add these standard FORMAT field header lines
VCFStandardHeaderLines.addStandardFormatLines(headerInfo, true,
VCFConstants.GENOTYPE_KEY,
VCFConstants.GENOTYPE_ALLELE_DEPTHS,
VCFConstants.GENOTYPE_QUALITY_KEY,
VCFConstants.DEPTH_KEY,
VCFConstants.GENOTYPE_PL_KEY);
headerInfo.addAll(getM2HeaderLines());
headerInfo.addAll(getSampleHeaderLines());
final VCFHeader vcfHeader = new VCFHeader(headerInfo, samplesList.asListOfSamples());
vcfHeader.setSequenceDictionary(sequenceDictionary);
vcfWriter.writeHeader(vcfHeader);
}
示例11: getVariantContextWriter
import htsjdk.variant.variantcontext.writer.VariantContextWriter; //导入依赖的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();
}
}
示例12: createTemporaryIndexedVcfFromInput
import htsjdk.variant.variantcontext.writer.VariantContextWriter; //导入依赖的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;
}
示例13: createVCFWriter
import htsjdk.variant.variantcontext.writer.VariantContextWriter; //导入依赖的package包/类
/**
* Creates a VariantContextWriter whose outputFile type is determined by
* the outFile's extension, using the best available sequence dictionary for
* this tool, and default index, leniency and md5 generation settings.
*
* @param outFile output File for this writer. May not be null.
* @returns VariantContextWriter must be closed by the caller
*/
public VariantContextWriter createVCFWriter(final File outFile) {
Utils.nonNull(outFile);
final SAMSequenceDictionary sequenceDictionary = getBestAvailableSequenceDictionary();
List<Options> options = new ArrayList<>();
if (lenientVCFProcessing) {
options.add(Options.ALLOW_MISSING_FIELDS_IN_HEADER);
}
if (createOutputVariantIndex) {
if (null == sequenceDictionary) {
logger.warn("An variant index will not be created - a sequence dictionary is required to create an output index");
// fall through and create without an index
} else {
options.add(Options.INDEX_ON_THE_FLY);
}
}
return GATKVariantContextUtils.createVCFWriter(
outFile,
sequenceDictionary,
createOutputVariantMD5,
options.toArray(new Options[options.size()]));
}
示例14: writeOutRecalibrationTable
import htsjdk.variant.variantcontext.writer.VariantContextWriter; //导入依赖的package包/类
public void writeOutRecalibrationTable(final VariantContextWriter recalWriter, final SAMSequenceDictionary seqDictionary) {
// we need to sort in coordinate order in order to produce a valid VCF
Collections.sort( data, VariantDatum.getComparator(seqDictionary) );
// create dummy alleles to be used
List<Allele> alleles = Arrays.asList(Allele.create("N", true), Allele.create("<VQSR>", false));
for( final VariantDatum datum : data ) {
if (VRAC.useASannotations)
alleles = Arrays.asList(datum.referenceAllele, datum.alternateAllele); //use the alleles to distinguish between multiallelics in AS mode
VariantContextBuilder builder = new VariantContextBuilder("VQSR", datum.loc.getContig(), datum.loc.getStart(), datum.loc.getEnd(), alleles);
builder.attribute(VCFConstants.END_KEY, datum.loc.getEnd());
builder.attribute(GATKVCFConstants.VQS_LOD_KEY, String.format("%.4f", datum.lod));
builder.attribute(GATKVCFConstants.CULPRIT_KEY, (datum.worstAnnotation != -1 ? annotationKeys.get(datum.worstAnnotation) : "NULL"));
if ( datum.atTrainingSite ) builder.attribute(GATKVCFConstants.POSITIVE_LABEL_KEY, true);
if ( datum.atAntiTrainingSite ) builder.attribute(GATKVCFConstants.NEGATIVE_LABEL_KEY, true);
recalWriter.add(builder.make());
}
}
示例15: getVCFWriter
import htsjdk.variant.variantcontext.writer.VariantContextWriter; //导入依赖的package包/类
private VariantContextWriter getVCFWriter() {
final SortedSet<String> samples = getSamplesForVariants();
final VCFHeader inputVCFHeader = new VCFHeader(getHeaderForVariants().getMetaDataInInputOrder(), samples);
final Set<VCFHeaderLine> headerLines = new LinkedHashSet<>(inputVCFHeader.getMetaDataInInputOrder());
headerLines.addAll(getDefaultToolVCFHeaderLines());
headerLines.addAll(annotationEngine.getVCFAnnotationDescriptions());
// add headers for annotations added by this tool
headerLines.add(VCFStandardHeaderLines.getInfoLine(VCFConstants.DEPTH_KEY)); // needed for gVCFs without DP tags
if ( dbsnp.dbsnp != null ) {
VCFStandardHeaderLines.addStandardInfoLines(headerLines, true, VCFConstants.DBSNP_KEY);
}
VariantContextWriter writer = createVCFWriter(outputFile);
final Set<String> sampleNameSet = new IndexedSampleList(samples).asSetOfSamples();
final VCFHeader vcfHeader = new VCFHeader(headerLines, new TreeSet<>(sampleNameSet));
writer.writeHeader(vcfHeader);
return writer;
}