本文整理汇总了Java中htsjdk.samtools.util.CloserUtil类的典型用法代码示例。如果您正苦于以下问题:Java CloserUtil类的具体用法?Java CloserUtil怎么用?Java CloserUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CloserUtil类属于htsjdk.samtools.util包,在下文中一共展示了CloserUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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);
}
示例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);
}
}
示例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);
}
示例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;
}
示例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);
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
}