本文整理汇总了Java中htsjdk.variant.variantcontext.writer.VariantContextWriter.close方法的典型用法代码示例。如果您正苦于以下问题:Java VariantContextWriter.close方法的具体用法?Java VariantContextWriter.close怎么用?Java VariantContextWriter.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类htsjdk.variant.variantcontext.writer.VariantContextWriter
的用法示例。
在下文中一共展示了VariantContextWriter.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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);
}
示例3: 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;
}
示例4: 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;
}
示例5: testCreateVCFWriterDefaults
import htsjdk.variant.variantcontext.writer.VariantContextWriter; //导入方法依赖的package包/类
@Test(dataProvider = "createVCFWriterData")
public void testCreateVCFWriterDefaults(
final File inputFile, // unused
final String outputExtension,
final String indexExtension,
final boolean createIndex, // unused
final boolean createMD5 // unused
) throws IOException {
// create a writer and make sure the default index/md5 params are honored
final TestGATKToolWithVariants tool = createTestVariantTool(null);
final File tmpDir = createTempDir("createVCFTest");
final File outputFile = new File(tmpDir.getAbsolutePath(), "createVCFTest" + outputExtension);
final VariantContextWriter writer = tool.createVCFWriter(outputFile);
writer.close();
final File outFileIndex = new File(outputFile.getAbsolutePath() + indexExtension);
final File outFileMD5 = new File(outputFile.getAbsolutePath() + ".md5");
Assert.assertTrue(outputFile.exists(), "No output file was not created");
Assert.assertTrue(outFileIndex.exists(), "The index file was not created");
Assert.assertFalse(outFileMD5.exists(), "An md5 file was created and should not have been");
}
示例6: testCreateVCFWriterWithOptions
import htsjdk.variant.variantcontext.writer.VariantContextWriter; //导入方法依赖的package包/类
@Test(dataProvider = "createVCFWriterData")
public void testCreateVCFWriterWithOptions(
final File inputFile,
final String outputExtension,
final String indexExtension,
final boolean createIndex,
final boolean createMD5) throws IOException {
// create a writer and make sure the requested index/md5 params are honored
final TestGATKToolWithVariants tool = new TestGATKToolWithVariants();
final File outputFile = setupVCFWriter(inputFile, outputExtension, tool, createIndex, createMD5, false);
final VariantContextWriter writer = tool.createVCFWriter(outputFile);
writer.close();
final File outFileIndex = new File(outputFile.getAbsolutePath() + indexExtension);
final File outFileMD5 = new File(outputFile.getAbsolutePath() + ".md5");
Assert.assertTrue(outputFile.exists(), "No output file was not created");
Assert.assertEquals(outFileIndex.exists(), createIndex, "The createIndex argument was not honored");
Assert.assertEquals(outFileMD5.exists(), createMD5, "The createMD5 argument was not honored");
}
示例7: testCreateVCFWriterWithNoSequenceDictionary
import htsjdk.variant.variantcontext.writer.VariantContextWriter; //导入方法依赖的package包/类
@Test(dataProvider = "createVCFWriterData")
public void testCreateVCFWriterWithNoSequenceDictionary(
final File inputFile,
final String outputExtension,
final String indexExtension,
final boolean createIndex,
final boolean createMD5) throws IOException
{
// verify that a null sequence dictionary still results in a file, but with no index
final TestGATKVariantToolWithNoSequenceDictionary tool = new TestGATKVariantToolWithNoSequenceDictionary();
final File outputFile = setupVCFWriter(inputFile, outputExtension, tool, createIndex, createMD5, false);
final VariantContextWriter writer = tool.createVCFWriter(outputFile);
writer.close();
final File outFileIndex = new File(outputFile.getAbsolutePath() + indexExtension);
final File outFileMD5 = new File(outputFile.getAbsolutePath() + ".md5");
Assert.assertTrue(outputFile.exists(), "No output file was not created");
Assert.assertEquals(outFileIndex.exists(), false, "An index file should not have been created"); // always false with no seq dictionary
Assert.assertEquals(outFileMD5.exists(), createMD5, "The createMD5 argument was not honored");
}
示例8: doVcfToVcf
import htsjdk.variant.variantcontext.writer.VariantContextWriter; //导入方法依赖的package包/类
@Override
protected int doVcfToVcf(
final String inputName,
final VcfIterator in,
final VariantContextWriter delegate)
{
final VariantContextWriter out = this.component.open(delegate);
final SAMSequenceDictionaryProgress progess=new SAMSequenceDictionaryProgress(in.getHeader()).logger(LOG);
out.writeHeader(in.getHeader());
while(in.hasNext())
{
out.add(progess.watch(in.next()));
}
progess.finish();
out.close();
return 0;
}
示例9: doVcfToVcf
import htsjdk.variant.variantcontext.writer.VariantContextWriter; //导入方法依赖的package包/类
@Override
protected int doVcfToVcf(final String inputName, final VcfIterator r, final VariantContextWriter delegate) {
final VariantContextWriter w = this.component.open(delegate);
w.writeHeader(r.getHeader());
final SAMSequenceDictionaryProgress progress = new SAMSequenceDictionaryProgress(r.getHeader()).logger(LOG);
while(r.hasNext())
{
w.add(progress.watch(r.next()));
// JVM crash sometimes ? suspect there is a memory leak ?
if(progress.getCount()%1000L==0)
{
System.gc();
}
}
progress.finish();
w.close();
return 0;
}
示例10: doVcfToVcf
import htsjdk.variant.variantcontext.writer.VariantContextWriter; //导入方法依赖的package包/类
@Override
protected int doVcfToVcf(
final String inputName,
final VcfIterator in,
final VariantContextWriter delegate)
{
final VariantContextWriter out = this.component.open(delegate);
final SAMSequenceDictionaryProgress progess=new SAMSequenceDictionaryProgress(in.getHeader()).logger(LOG);
out.writeHeader(in.getHeader());
while(in.hasNext() && !out.checkError())
{
out.add(progess.watch(in.next()));
}
progess.finish();
out.close();
return 0;
}
示例11: doVcfToVcf
import htsjdk.variant.variantcontext.writer.VariantContextWriter; //导入方法依赖的package包/类
@Override
protected int doVcfToVcf(
final String inputName,final VcfIterator vcfIterator,
final VariantContextWriter delegate) {
final VcfIterator in = VCFUtils.createAssertSortedVcfIterator(vcfIterator, VCFUtils.createTidPosComparator(vcfIterator.getHeader().getSequenceDictionary()));
final VariantContextWriter out = this.component.open(delegate);
final SAMSequenceDictionaryProgress progess=new SAMSequenceDictionaryProgress(in.getHeader()).logger(LOG);
out.writeHeader(in.getHeader());
while(in.hasNext())
{
out.add(progess.watch(in.next()));
}
out.close();
progess.finish();
CloserUtil.close(in);
return 0;
}
示例12: doVcfToVcf
import htsjdk.variant.variantcontext.writer.VariantContextWriter; //导入方法依赖的package包/类
@Override
protected int doVcfToVcf(
final String inputName,
final VcfIterator iter,
final VariantContextWriter delegate
) {
final VariantContextWriter out = this.component.open(delegate);
final SAMSequenceDictionaryProgress progress = new SAMSequenceDictionaryProgress(iter.getHeader()).logger(LOG);
out.writeHeader(iter.getHeader());
while(iter.hasNext())
{
out.add(progress.watch(iter.next()));
}
out.close();
progress.finish();
return 0;
}
示例13: doVcfToVcf
import htsjdk.variant.variantcontext.writer.VariantContextWriter; //导入方法依赖的package包/类
@Override
protected int doVcfToVcf(
final String inputName,
final VcfIterator in,
final VariantContextWriter delegate) {
try
{
final VariantContextWriter out = this.component.open(delegate);
out.writeHeader(in.getHeader());
final SAMSequenceDictionaryProgress progress= new SAMSequenceDictionaryProgress(in.getHeader()).logger(LOG);
while(in.hasNext())
{
out.add(progress.watch(in.next()));
}
progress.finish();
out.close();
return 0;
}
catch(final Exception err)
{
LOG.error(err);
return -1;
}
}
示例14: doVcfToVcf
import htsjdk.variant.variantcontext.writer.VariantContextWriter; //导入方法依赖的package包/类
@Override
protected int doVcfToVcf(
final String inputName,
final VcfIterator r,
final VariantContextWriter delegate
)
{
final VariantContextWriter w= this.component.open(delegate);
w.writeHeader(r.getHeader());
final SAMSequenceDictionaryProgress progress= new SAMSequenceDictionaryProgress(r.getHeader()).logger(LOG);
while(r.hasNext())
{
w.add(progress.watch(r.next()));
}
progress.finish();
w.close();
return RETURN_OK;
}
示例15: doVcfToVcf
import htsjdk.variant.variantcontext.writer.VariantContextWriter; //导入方法依赖的package包/类
@Override
protected int doVcfToVcf(
final String inputName,
final VcfIterator in,
final VariantContextWriter delegate) {
try
{
final VariantContextWriter out = this.component.open(delegate);
out.writeHeader(in.getHeader());
final SAMSequenceDictionaryProgress progress= new SAMSequenceDictionaryProgress(in.getHeader()).logger(LOG);
while(in.hasNext())
{
out.add(progress.watch(in.next()));
}
progress.finish();
out.close();
return 0;
}
catch(final Exception err)
{
LOG.error(err);
return -1;
}
}