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


Java CloserUtil.close方法代码示例

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


在下文中一共展示了CloserUtil.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fakeBciFile

import htsjdk.samtools.util.CloserUtil; //导入方法依赖的package包/类
public void fakeBciFile(final File bci, final List<Integer> expectedTiles) throws IOException {
    tiles = expectedTiles;
    final FileOutputStream fileOutputStream = new FileOutputStream(bci);
    final FileChannel channel = fileOutputStream.getChannel();
    final ByteBuffer buffer = ByteBuffer.allocate(8 * expectedTiles.size());
    buffer.order(ByteOrder.LITTLE_ENDIAN);

    fakeFile(buffer);
    buffer.flip();

    channel.write(buffer);
    channel.force(true);

    CloserUtil.close(channel);
    CloserUtil.close(fileOutputStream);
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:17,代码来源:BciFileFaker.java

示例2: doWork

import htsjdk.samtools.util.CloserUtil; //导入方法依赖的package包/类
protected int doWork() {
    IOUtil.assertFileIsReadable(INPUT);
    IOUtil.assertFileIsWritable(OUTPUT);
    final SamReader reader = SamReaderFactory.makeDefault().referenceSequence(REFERENCE_SEQUENCE).open(INPUT);
    final SAMFileWriter writer = new SAMFileWriterFactory().makeWriter(reader.getFileHeader(), true, OUTPUT, REFERENCE_SEQUENCE);

    if (CREATE_INDEX && writer.getFileHeader().getSortOrder() != SAMFileHeader.SortOrder.coordinate) {
        throw new PicardException("Can't CREATE_INDEX unless sort order is coordinate");
    }

    final ProgressLogger progress = new ProgressLogger(Log.getInstance(SamFormatConverter.class));
    for (final SAMRecord rec : reader) {
        writer.addAlignment(rec);
        progress.record(rec);
    }
    CloserUtil.close(reader);
    writer.close();
    return 0;
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:20,代码来源:SamFormatConverter.java

示例3: doVcfToVcf

import htsjdk.samtools.util.CloserUtil; //导入方法依赖的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;
		}
 
开发者ID:lindenb,项目名称:jvarkit,代码行数:19,代码来源:VcfBurdenFilterExac.java

示例4: doWork

import htsjdk.samtools.util.CloserUtil; //导入方法依赖的package包/类
@Override
public int doWork(List<String> args) {
	try 
		{
		if(this.component.initialize()!=0) {
			return -1;
			}
		return doVcfToVcf(args,this.outputFile);
		}
	catch(final Exception err) {
		LOG.error(err);
		return -1;
		}
	finally
		{
		CloserUtil.close(this.component);
		}
	}
 
开发者ID:lindenb,项目名称:jvarkit,代码行数:19,代码来源:VcfBurdenFilterExac.java

示例5: doWork

import htsjdk.samtools.util.CloserUtil; //导入方法依赖的package包/类
@Override
public int doWork(final List<String> args) {
	try 
		{
		if(this.component.initialize()!=0) {
			return -1;
			}
		return doVcfToVcf(args,this.outputFile);
		}
	catch(final Exception err) {
		LOG.error(err);
		return -1;
		}
	finally
		{
		CloserUtil.close(this.component);
		}
	}
 
开发者ID:lindenb,项目名称:jvarkit,代码行数:19,代码来源:VcfBurdenMAF.java

示例6: close

import htsjdk.samtools.util.CloserUtil; //导入方法依赖的package包/类
@Override
public void close() throws IOException {
	if(this.gzStream != null) {
		 CloserUtil.close(gzStream);
	} else {
		 CloserUtil.close(reader);
	}
}
 
开发者ID:mulinlab,项目名称:vanno,代码行数:9,代码来源:LineIteratorImpl.java

示例7: copyTo

import htsjdk.samtools.util.CloserUtil; //导入方法依赖的package包/类
public static void copyTo(final File f,final OutputStream fous) throws IOException
{
FileInputStream fin=null;
try {
	fin =new FileInputStream(f);
	copyTo(fin,fous);
	fous.flush();
} finally {
	CloserUtil.close(fin);
	}
}
 
开发者ID:dariober,项目名称:ASCIIGenome,代码行数:12,代码来源:IOUtils.java

示例8: advance

import htsjdk.samtools.util.CloserUtil; //导入方法依赖的package包/类
@Override
protected String advance()
	{
	if(in==null) return null;
	String s;
	try {
		s = in.readLine();
		if(s==null) {CloserUtil.close(this.in);this.in=null;}
		return s;
	} catch (Exception e) {
		throw new RuntimeException(e);
		}
	}
 
开发者ID:dariober,项目名称:ASCIIGenome,代码行数:14,代码来源:IOUtils.java

示例9: run

import htsjdk.samtools.util.CloserUtil; //导入方法依赖的package包/类
@Override
public void run() throws IOException {

    SamReaderFactory.setDefaultValidationStringency(ValidationStringency.SILENT);
    final SamReader reader = SamReaderFactory.makeDefault().open(inputFile);


    reader.getFileHeader().setSortOrder(SAMFileHeader.SortOrder.coordinate);
    SAMFileWriterFactory samFileWriterFactory = new SAMFileWriterFactory();
    if(this.tmpDir != null) {
        samFileWriterFactory.setTempDirectory(this.tmpDir);
    }
    if(this.maxRecords > 0) {
        samFileWriterFactory.setMaxRecordsInRam(this.maxRecords);
    }
    final SAMFileWriter writer = samFileWriterFactory.makeSAMOrBAMWriter(reader.getFileHeader(), false, outputFile);

    int count = 0;
    for (final SAMRecord rec : reader) {
        if(++count % 100000 == 0) {
            if(IGV.hasInstance()) {
                System.out.println("" + count + " records processed");   // GUI
            }
            else {
                log.info("" + count + " records processed");   // Command line
            }
        }
        writer.addAlignment(rec);
    }

    CloserUtil.close(reader);
    writer.close();
}
 
开发者ID:hyounesy,项目名称:ALEA,代码行数:34,代码来源:BAMSorter.java

示例10: close

import htsjdk.samtools.util.CloserUtil; //导入方法依赖的package包/类
/**
 * Close the underlying writer.
 *
 * @throws DistmapException if the writer is in paired and not second read is added.
 */
@Override
public void close() throws IOException {
    // close the handler if it is a DistmapPairedConsumer
    CloserUtil.close(singleEndHandler);
    writer.close();
}
 
开发者ID:magicDGS,项目名称:ReadTools,代码行数:12,代码来源:DistmapGATKWriter.java

示例11: close

import htsjdk.samtools.util.CloserUtil; //导入方法依赖的package包/类
/**
 * Closes the underlying stream
 */
public void close() {
    if (reader != null)  {
        reader.close();
    }
    for(final InputStream stream : inputs){
        CloserUtil.close(stream);
    }
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:12,代码来源:BasicInputParser.java

示例12: doWork

import htsjdk.samtools.util.CloserUtil; //导入方法依赖的package包/类
@Override
protected int doWork() {
    IOUtil.assertFileIsReadable(INTERVAL_LIST);
    IOUtil.assertFileIsReadable(REFERENCE_SEQUENCE);
    IOUtil.assertFileIsWritable(OUTPUT);

    final IntervalList intervals = IntervalList.fromFile(INTERVAL_LIST);
    final ReferenceSequenceFile ref = ReferenceSequenceFileFactory.getReferenceSequenceFile(REFERENCE_SEQUENCE);
    SequenceUtil.assertSequenceDictionariesEqual(intervals.getHeader().getSequenceDictionary(), ref.getSequenceDictionary());

    final BufferedWriter out = IOUtil.openFileForBufferedWriting(OUTPUT);

    for (final Interval interval : intervals) {
        final ReferenceSequence seq = ref.getSubsequenceAt(interval.getContig(), interval.getStart(), interval.getEnd());
        final byte[] bases = seq.getBases();
        if (interval.isNegativeStrand()) SequenceUtil.reverseComplement(bases);

        try {
            out.write(">");
            out.write(interval.getName());
            out.write("\n");

            for (int i=0; i<bases.length; ++i) {
                if (i > 0 && i % LINE_LENGTH == 0) out.write("\n");
                out.write(bases[i]);
            }

            out.write("\n");
        }
        catch (IOException ioe) {
            throw new PicardException("Error writing to file " + OUTPUT.getAbsolutePath(), ioe);

        }
    }

    CloserUtil.close(out);

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

示例13: test

import htsjdk.samtools.util.CloserUtil; //导入方法依赖的package包/类
protected void test() {
    try {
        final SamFileValidator validator = new SamFileValidator(new PrintWriter(System.out), 8000);

        // Validate it has the expected cigar
        validator.setIgnoreWarnings(true);
        validator.setVerbose(true, 1000);
        validator.setErrorsToIgnore(Arrays.asList(SAMValidationError.Type.MISSING_READ_GROUP));
        SamReaderFactory factory = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.LENIENT);
        SamReader samReader = factory.open(getOutput());
        final SAMRecordIterator iterator = samReader.iterator();
        while (iterator.hasNext()) {
            final SAMRecord rec = iterator.next();
            Assert.assertEquals(rec.getCigarString(), expectedCigar);
            if (SAMUtils.hasMateCigar(rec)) {
                Assert.assertEquals(SAMUtils.getMateCigarString(rec), expectedCigar);
            }
        }
        CloserUtil.close(samReader);

        // Run validation on the output file
        samReader = factory.open(getOutput());
        final boolean validated = validator.validateSamFileVerbose(samReader, null);
        CloserUtil.close(samReader);

        Assert.assertTrue(validated, "ValidateSamFile failed");
    } finally {
        TestUtil.recursiveDelete(getOutputDir());
    }
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:31,代码来源:CleanSamTester.java

示例14: svDiscoveryVCFEquivalenceTest

import htsjdk.samtools.util.CloserUtil; //导入方法依赖的package包/类
static void svDiscoveryVCFEquivalenceTest(final String generatedVCFPath, final String expectedVCFPath,
                                          final String experimentalOutputPath,
                                          final List<String> attributesToIgnore, final boolean onHDFS) throws Exception {

    final VCFFileReader fileReader = new VCFFileReader(new File(expectedVCFPath), false);
    final CloseableIterator<VariantContext> iterator = fileReader.iterator();
    final List<VariantContext> expectedVcs = Utils.stream(iterator).collect(Collectors.toList());
    CloserUtil.close(iterator);
    CloserUtil.close(fileReader);

    List<VariantContext> actualVcs = extractActualVCs(generatedVCFPath, onHDFS);

    GATKBaseTest.assertCondition(actualVcs, expectedVcs,
            (a, e) -> VariantContextTestUtils.assertVariantContextsAreEqual(a, e, attributesToIgnore));

    if ( experimentalOutputPath != null ) {
        final java.nio.file.Path path = IOUtils.getPath(experimentalOutputPath).resolve("nonComplex.vcf");
        final String experimentalInsDelVcf = onHDFS ? path.toUri().toString() : path.toString();
        actualVcs = extractActualVCs(experimentalInsDelVcf, onHDFS);

        // TODO: 1/28/18 see ticket #4228
        final List<String> moreAttributesToIgnoreForNow = new ArrayList<>(attributesToIgnore);
        moreAttributesToIgnoreForNow.addAll(Collections.singletonList("EXTERNAL_CNV_CALLS"));
        GATKBaseTest.assertCondition(actualVcs, expectedVcs,
                (a, e) -> VariantContextTestUtils.assertVariantContextsAreEqual(a, e, moreAttributesToIgnoreForNow));
    }
}
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:28,代码来源:StructuralVariationDiscoveryPipelineSparkIntegrationTest.java

示例15: doWork

import htsjdk.samtools.util.CloserUtil; //导入方法依赖的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


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