本文整理汇总了Java中htsjdk.samtools.util.CloserUtil类的典型用法代码示例。如果您正苦于以下问题:Java CloserUtil类的具体用法?Java CloserUtil怎么用?Java CloserUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CloserUtil类属于htsjdk.samtools.util包,在下文中一共展示了CloserUtil类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: ClusterIntensityFileReader
import htsjdk.samtools.util.CloserUtil; //导入依赖的package包/类
/**
* Prepare to parse a CIF or CNF file.
* @param file The file to be parsed.
*/
public ClusterIntensityFileReader(final File file) {
try {
this.file = file;
final FileInputStream is = new FileInputStream(this.file);
final FileChannel channel = is.getChannel();
final long fileSize = channel.size();
buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, fileSize);
buf.order(ByteOrder.LITTLE_ENDIAN);
CloserUtil.close(channel);
CloserUtil.close(is);
final byte [] headerBytes = new byte[HEADER_SIZE];
buf.get(headerBytes);
this.header = new ClusterIntensityFileHeader(headerBytes, this.file);
} catch (IOException e) {
throw new PicardException("IOException opening cluster intensity file " + file, e);
}
cycleSize = NUM_CHANNELS * header.numClusters * header.elementSize;
channelSize = header.numClusters * header.elementSize;
}
开发者ID:broadinstitute,项目名称:picard,代码行数:24,代码来源:ClusterIntensityFileReader.java
示例2: readHeaders
import htsjdk.samtools.util.CloserUtil; //导入依赖的package包/类
public static ClusterIntensityFileHeader readHeaders(final File intensityFile) {
FileInputStream reader = null;
byte [] headerBytes = new byte[HEADER_SIZE];
int bytesRead = 0;
try {
reader = new FileInputStream(intensityFile);
bytesRead = reader.read(headerBytes);
} catch(FileNotFoundException fnfExc) {
throw new PicardException("Error opening intensity file (" + intensityFile.getAbsolutePath() +")", fnfExc);
} catch(IOException ioExc) {
throw new PicardException("Error reading values from header for intensity file (" + intensityFile.getAbsolutePath() + ")", ioExc);
} finally {
CloserUtil.close(reader);
}
if(bytesRead != HEADER_SIZE)
throw new PicardException("Error reading intensity file header, too few bytes read, expected( " + HEADER_SIZE + ") read(" + bytesRead + ")");
return new ClusterIntensityFileHeader(headerBytes, intensityFile);
}
开发者ID:broadinstitute,项目名称:picard,代码行数:21,代码来源:ClusterIntensityFileReader.java
示例3: TileIndex
import htsjdk.samtools.util.CloserUtil; //导入依赖的package包/类
TileIndex(final File tileIndexFile) {
try {
this.tileIndexFile = tileIndexFile;
final InputStream is = IOUtil.maybeBufferInputStream(new FileInputStream(tileIndexFile));
final ByteBuffer buf = ByteBuffer.allocate(8);
buf.order(ByteOrder.LITTLE_ENDIAN);
int absoluteRecordIndex = 0;
int numTiles = 0;
while (readTileIndexRecord(buf.array(), buf.capacity(), is)) {
buf.rewind();
buf.limit(buf.capacity());
final int tile = buf.getInt();
// Note: not handling unsigned ints > 2^31, but could if one of these exceptions is thrown.
if (tile < 0) throw new PicardException("Tile number too large in " + tileIndexFile.getAbsolutePath());
final int numClusters = buf.getInt();
if (numClusters < 0) throw new PicardException("Cluster size too large in " + tileIndexFile.getAbsolutePath());
tiles.add(new TileIndexRecord(tile, numClusters, absoluteRecordIndex, numTiles++));
absoluteRecordIndex += numClusters;
}
CloserUtil.close(is);
} catch (final IOException e) {
throw new PicardException("Problem reading " + tileIndexFile.getAbsolutePath(), e);
}
}
开发者ID:broadinstitute,项目名称:picard,代码行数:25,代码来源:TileIndex.java
示例4: 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
示例5: getBuffer
import htsjdk.samtools.util.CloserUtil; //导入依赖的package包/类
private static ByteBuffer getBuffer(final File binaryFile) {
final ByteBuffer buf;
try {
final FileInputStream is = new FileInputStream(binaryFile);
final FileChannel channel = is.getChannel();
final long fileSize = channel.size();
buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, fileSize);
buf.order(ByteOrder.LITTLE_ENDIAN);
CloserUtil.close(channel);
CloserUtil.close(is);
} catch (IOException e) {
throw new PicardException("IOException opening cluster binary file " + binaryFile, e);
}
return buf;
}
开发者ID:broadinstitute,项目名称:picard,代码行数:17,代码来源:MMapBackedIteratorFactory.java
示例6: getExpectedTiles
import htsjdk.samtools.util.CloserUtil; //导入依赖的package包/类
/**
* Return the list of tiles we would expect for this lane based on the metrics found in InterOp/TileMetricsOut.bin
*/
public List<Integer> getExpectedTiles() {
IOUtil.assertFileIsReadable(tileMetricsOut);
//Used just to ensure predictable ordering
final TreeSet<Integer> expectedTiles = new TreeSet<>();
final Iterator<TileMetricsOutReader.IlluminaTileMetrics> tileMetrics = new TileMetricsOutReader(tileMetricsOut, TileMetricsOutReader.TileMetricsVersion.TWO);
while (tileMetrics.hasNext()) {
final TileMetricsOutReader.IlluminaTileMetrics tileMetric = tileMetrics.next();
if (tileMetric.getLaneNumber() == lane &&
!expectedTiles.contains(tileMetric.getTileNumber())) {
expectedTiles.add(tileMetric.getTileNumber());
}
}
CloserUtil.close(tileMetrics);
return new ArrayList<>(expectedTiles);
}
开发者ID:broadinstitute,项目名称:picard,代码行数:22,代码来源:IlluminaFileUtil.java
示例7: gatherNormally
import htsjdk.samtools.util.CloserUtil; //导入依赖的package包/类
/**
* Simple implementation of a gather operations that uses SAMFileReaders and Writers in order to concatenate
* multiple BAM files.
*/
private static void gatherNormally(final List<File> inputs, final File output, final boolean createIndex, final boolean createMd5,
final File referenceFasta) {
final SAMFileHeader header;
{
header = SamReaderFactory.makeDefault().referenceSequence(referenceFasta).getFileHeader(inputs.get(0));
}
final SAMFileWriter out = new SAMFileWriterFactory().setCreateIndex(createIndex).setCreateMd5File(createMd5).makeSAMOrBAMWriter(header, true, output);
for (final File f : inputs) {
log.info("Gathering " + f.getAbsolutePath());
final SamReader in = SamReaderFactory.makeDefault().referenceSequence(referenceFasta).open(f);
for (final SAMRecord rec : in) out.addAlignment(rec);
CloserUtil.close(in);
}
out.close();
}
开发者ID:broadinstitute,项目名称:picard,代码行数:23,代码来源:GatherBamFiles.java
示例8: 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);
if (reader.getFileHeader().getSortOrder() != SAMFileHeader.SortOrder.coordinate) {
throw new SAMException("Input must be coordinate-sorted for this program to run. Found: " + reader.getFileHeader().getSortOrder());
}
final SAMFileWriter writer = new SAMFileWriterFactory().makeSAMOrBAMWriter(reader.getFileHeader(), true, OUTPUT);
writer.setProgressLogger(
new ProgressLogger(log, (int) 1e7, "Wrote", "records"));
final ReferenceSequenceFileWalker refSeqWalker = new ReferenceSequenceFileWalker(REFERENCE_SEQUENCE);
StreamSupport.stream(reader.spliterator(), false)
.peek(rec -> fixRecord(rec, refSeqWalker))
.forEach(writer::addAlignment);
CloserUtil.close(reader);
writer.close();
return 0;
}
开发者ID:broadinstitute,项目名称:picard,代码行数:23,代码来源:SetNmMdAndUqTags.java
示例9: 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
示例10: 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);
;
reader.getFileHeader().setSortOrder(SORT_ORDER.getSortOrder());
final SAMFileWriter writer = new SAMFileWriterFactory().makeSAMOrBAMWriter(reader.getFileHeader(), false, OUTPUT);
writer.setProgressLogger(
new ProgressLogger(log, (int) 1e7, "Wrote", "records from a sorting collection"));
final ProgressLogger progress = new ProgressLogger(log, (int) 1e7, "Read");
for (final SAMRecord rec : reader) {
writer.addAlignment(rec);
progress.record(rec);
}
log.info("Finished reading inputs, merging and writing to output now.");
CloserUtil.close(reader);
writer.close();
return 0;
}
开发者ID:broadinstitute,项目名称:picard,代码行数:23,代码来源:SortSam.java
示例11: doWork
import htsjdk.samtools.util.CloserUtil; //导入依赖的package包/类
/**
* Do the work after command line has been parsed. RuntimeException may be
* thrown by this method, and are reported appropriately.
*
* @return program exit status.
*/
@Override
protected int doWork() {
for (int i = 0; i < samFiles.size(); ++i) {
samReaders[i] = SamReaderFactory.makeDefault().referenceSequence(REFERENCE_SEQUENCE).open(samFiles.get(i));
}
areEqual = compareHeaders();
areEqual = compareAlignments() && areEqual;
printReport();
if (!areEqual) {
System.out.println("SAM files differ.");
} else {
System.out.println("SAM files match.");
}
CloserUtil.close(samReaders);
return 0;
}
开发者ID:broadinstitute,项目名称:picard,代码行数:23,代码来源:CompareSAMs.java
示例12: standardReheader
import htsjdk.samtools.util.CloserUtil; //导入依赖的package包/类
private void standardReheader(final SAMFileHeader replacementHeader) {
final SamReader recordReader = SamReaderFactory.makeDefault().referenceSequence(REFERENCE_SEQUENCE).validationStringency(ValidationStringency.SILENT).open(INPUT);
if (replacementHeader.getSortOrder() != recordReader.getFileHeader().getSortOrder()) {
throw new PicardException("Sort orders of INPUT (" + recordReader.getFileHeader().getSortOrder().name() +
") and HEADER (" + replacementHeader.getSortOrder().name() + ") do not agree.");
}
final SAMFileWriter writer = new SAMFileWriterFactory().makeSAMOrBAMWriter(replacementHeader, true, OUTPUT);
final ProgressLogger progress = new ProgressLogger(Log.getInstance(ReplaceSamHeader.class));
for (final SAMRecord rec : recordReader) {
rec.setHeader(replacementHeader);
writer.addAlignment(rec);
progress.record(rec);
}
writer.close();
CloserUtil.close(recordReader);
}
开发者ID:broadinstitute,项目名称:picard,代码行数:18,代码来源:ReplaceSamHeader.java
示例13: unsortedInputSortedOutputTest
import htsjdk.samtools.util.CloserUtil; //导入依赖的package包/类
/**
* Confirm that unsorted input can result in coordinate sorted output, with index created.
*/
@Test
public void unsortedInputSortedOutputTest() throws Exception {
final File unsortedInputTestDataDir = new File(TEST_DATA_DIR, "unsorted_input");
final File mergedOutput = File.createTempFile("unsortedInputSortedOutputTest.", BamFileIoUtils.BAM_FILE_EXTENSION);
mergedOutput.deleteOnExit();
final String[] args = {
"I=" + new File(unsortedInputTestDataDir, "1.sam").getAbsolutePath(),
"I=" + new File(unsortedInputTestDataDir, "2.sam").getAbsolutePath(),
"O=" + mergedOutput.getAbsolutePath(),
"SO=coordinate"
};
final int mergeExitStatus = runPicardCommandLine(args);
Assert.assertEquals(mergeExitStatus, 0);
final SamReader reader = SamReaderFactory.makeDefault().open(mergedOutput);
Assert.assertEquals(reader.getFileHeader().getSortOrder(), SAMFileHeader.SortOrder.coordinate);
new ValidateSamTester().assertSamValid(mergedOutput);
CloserUtil.close(reader);
}
开发者ID:broadinstitute,项目名称:picard,代码行数:23,代码来源:MergeSamFilesTest.java
示例14: 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,代码行数:18,代码来源:VcfTrap.java
示例15: doWork
import htsjdk.samtools.util.CloserUtil; //导入依赖的package包/类
@Override
public int doWork(final List<String> args) {
try
{
if(this.component.initialize()!=0) {
LOG.error("Cannot initialize");
return -1;
}
return doVcfToVcf(args, this.outputFile);
}
catch(final Exception err)
{
LOG.error(err);
return -1;
}
finally
{
CloserUtil.close(this.component);
}
}
开发者ID:lindenb,项目名称:jvarkit,代码行数:21,代码来源:VcfFilterJdk.java
示例16: readBedFileAsBooleanIntervalTreeMap
import htsjdk.samtools.util.CloserUtil; //导入依赖的package包/类
/** reads a Bed file and convert it to a IntervalTreeMap<Boolean> */
protected IntervalTreeMap<Boolean> readBedFileAsBooleanIntervalTreeMap(final java.io.File file) throws java.io.IOException
{
java.io.BufferedReader r=null;
try
{
final IntervalTreeMap<Boolean> intervals = new IntervalTreeMap<Boolean>();
r=com.github.lindenb.jvarkit.io.IOUtils.openFileForBufferedReading(file);
final BedLineCodec bedCodec=new BedLineCodec();
r.lines().
filter(line->!(line.startsWith("#") || com.github.lindenb.jvarkit.util.bio.bed.BedLine.isBedHeader(line) || line.isEmpty())).
map(line->bedCodec.decode(line)).
filter(B->B!=null).
map(B->B.toInterval()).
filter(L->L.getStart()<L.getEnd()).
forEach(L->{intervals.put(L,true); }
);
return intervals;
}
finally
{
htsjdk.samtools.util.CloserUtil.close(r);
}
}
开发者ID:lindenb,项目名称:jvarkit,代码行数:25,代码来源:Launcher.java
示例17: 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,代码来源:VcfBurdenFisherV.java
示例18: actionLoadScript
import htsjdk.samtools.util.CloserUtil; //导入依赖的package包/类
private void actionLoadScript(final Stage dialog,final TextArea scriptArea) {
final FileChooser fc= NgsStage.this.owner.newFileChooser();
fc.getExtensionFilters().addAll(JS_EXTENSION_FILTERS);
final File js=NgsStage.this.owner.updateLastDir(fc.showOpenDialog(dialog));
if(js==null) return;
InputStream in=null;
try
{
in= new FileInputStream(js);
scriptArea.setText(IOUtil.readFully(in));
in.close();
}
catch(final Exception err)
{
JfxNgs.showExceptionDialog(dialog, err);
}
finally
{
CloserUtil.close(in);
}
}
开发者ID:lindenb,项目名称:jvarkit,代码行数:22,代码来源:NgsStage.java
示例19: openVcfUrl
import htsjdk.samtools.util.CloserUtil; //导入依赖的package包/类
void openVcfUrl(final Window owner)
{
final String lastkey="last.vcf.url";
final TextInputDialog dialog=new TextInputDialog(this.preferences.get(lastkey, ""));
dialog.setContentText("URL:");
dialog.setTitle("Get VCF URL");
dialog.setHeaderText("Input VCF URL");
final Optional<String> choice=dialog.showAndWait();
if(!choice.isPresent()) return;
VcfFile input=null;
try {
input = VcfFile.newInstance(choice.get());
this.preferences.put(lastkey, choice.get());
VcfStage stage=new VcfStage(JfxNgs.this, input);
stage.show();
} catch (final Exception err) {
CloserUtil.close(input);
showExceptionDialog(owner, err);
}
}
开发者ID:lindenb,项目名称:jvarkit,代码行数:21,代码来源:JfxNgs.java
示例20: 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
注:本文中的htsjdk.samtools.util.CloserUtil类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论