public static void writeTribbleIndex(Index idx, String idxFile) throws IOException { LittleEndianOutputStream stream = null; try { stream = new LittleEndianOutputStream(new BufferedOutputStream(new FileOutputStream(idxFile))); idx.write(stream); } catch (Exception e) { log.error(e.getMessage(), e); // Delete output file as its probably corrupt File tmp = new File(idxFile); if (tmp.exists()) { tmp.delete(); } } finally { if (stream != null) { stream.close(); } } }
@Override public void writeBasedOnFeatureFile(final File featureFile) throws IOException { if (!featureFile.isFile()) return; final LittleEndianOutputStream idxStream = new LittleEndianOutputStream(new FileOutputStream(Tribble.indexFile(featureFile))); write(idxStream); idxStream.close(); }
/** * Write the index to a file; little endian. * @param idx * @param idxFile * @throws IOException */ public static void writeIndex(final Index idx, final File idxFile) throws IOException { LittleEndianOutputStream stream = null; try { stream = new LittleEndianOutputStream(new BufferedOutputStream(new FileOutputStream(idxFile))); idx.write(stream); } finally { if(stream != null) { stream.close(); } } }
/** * creates a new index, given the feature file and the codec * @param featureFile the feature file (i.e. .vcf, .bed) * @param indexFile the index file; the location we should be writing the index to * @param codec the codec to read features with * @return an index instance */ public static Index createAndWriteNewIndex(File featureFile, File indexFile, FeatureCodec codec) { try { Index index = IndexFactory.createLinearIndex(featureFile, codec); // try to write it to disk LittleEndianOutputStream stream = new LittleEndianOutputStream(new FileOutputStream(indexFile)); index.write(stream); stream.close(); return index; } catch (IOException e) { throw new RuntimeException("Unable to create index from file " + featureFile,e); } }
/** * creates a new index, given the feature file and the codec * @param featureFile the feature file (i.e. .vcf, .bed) * @param indexFile the index file; the location we should be writing the index to * @param codec the codec to read features with * @return an index instance */ public static Index createAndWriteNewIndex(File featureFile, File indexFile, FeatureCodec codec) { try { Index index = IndexFactory.createLinearIndex(featureFile, codec); // try to write it to disk LittleEndianOutputStream stream = new LittleEndianOutputStream(new BufferedOutputStream(new FileOutputStream(indexFile))); index.write(stream); stream.close(); return index; } catch (IOException e) { throw new RuntimeIOException("Unable to create index from file " + featureFile,e); } }
/** * creates a new index, given the feature file and the codec * @param featureFile the feature file (i.e. .vcf, .bed) * @param indexFile the index file; the location we should be writing the index to * @param codec the codec to read features with * @return an index instance */ public static Index createAndWriteNewIndex(File featureFile, File indexFile, FeatureCodec codec) { try { Index index = IndexFactory.createLinearIndex(featureFile, codec); // try to write it to disk LittleEndianOutputStream stream = new LittleEndianOutputStream(new BufferedOutputStream(new FileOutputStream(indexFile))); index.write(stream); stream.close(); return index; } catch (IOException e) { throw new RuntimeIOException("Unable to create index from file " + featureFile,e); } }
/** * attempt to write the index to disk * @param index the index to write to disk * @param indexFile the index file location * @param lock the locking object * @throws IOException when unable to create the new index */ private void writeIndexToDisk( final Index index, final File indexFile, final FSLockWithShared lock ) throws IOException { if ( disableAutoIndexCreation ) { return; } boolean locked = false; try { locked = lock.exclusiveLock(); if (locked) { logger.info("Writing Tribble index to disk for file " + indexFile); LittleEndianOutputStream stream = new LittleEndianOutputStream(new FileOutputStream(indexFile)); index.write(stream); stream.close(); } else // we can't write it to disk, just store it in memory, tell them this logger.warn("Unable to write to " + indexFile + " for the index file, creating index in memory only"); try { logger.info(String.format(" Index for %s has size in bytes %d", indexFile, Sizeof.getObjectGraphSize(index))); } catch ( ReviewedGATKException e) { } } finally { if (locked) lock.unlock(); } }
/** * Writes the index with BGZF. * @param tabixFile Where to write the index. */ public void write(final File tabixFile) { final LittleEndianOutputStream los = new LittleEndianOutputStream(new BlockCompressedOutputStream(tabixFile)); try { write(los); los.close(); } catch (final IOException e) { throw new TribbleException("Exception writing " + tabixFile.getAbsolutePath(), e); } }
private static void createIndex(File idxFile, FeatureCodec codec) throws IOException { if (idxFile.exists()) { idxFile.delete(); } // Create the index Index idx = IndexFactory.createIntervalIndex(new File(testFile), codec, 10); LittleEndianOutputStream stream = null; try { stream = new LittleEndianOutputStream(new BufferedOutputStream(new FileOutputStream(idxFile))); idx.write(stream); } finally { if (stream != null) { stream.close(); } } idxFile.deleteOnExit(); }
static void createTestFile() throws IOException { LittleEndianOutputStream los = new LittleEndianOutputStream(new BufferedOutputStream(new FileOutputStream("les_test.bin"))); los.writeString("Binary test file"); los.writeFloat(Float.MAX_VALUE); los.writeByte(Byte.MAX_VALUE); los.writeShort(Short.MAX_VALUE); los.writeInt(Integer.MAX_VALUE); los.writeLong(Long.MAX_VALUE); los.writeDouble(Double.MAX_VALUE); los.close(); } }
/** * Read an existing index from disk, write it to a temp file, read that in, and assert that both in-memory * representations are identical. Disk representations may not be identical due to arbitrary bin order and * compression differences. */ @Test(dataProvider = "readWriteTestDataProvider") public void readWriteTest(final File tabixFile) throws Exception { final TabixIndex index = new TabixIndex(tabixFile); final File indexFile = File.createTempFile("TabixIndexTest.", TabixUtils.STANDARD_INDEX_EXTENSION); indexFile.deleteOnExit(); final LittleEndianOutputStream los = new LittleEndianOutputStream(new BlockCompressedOutputStream(indexFile)); index.write(los); los.close(); final TabixIndex index2 = new TabixIndex(indexFile); Assert.assertEquals(index, index2); // Unfortunately, can't do byte comparison of original file and temp file, because 1) different compression // levels; and more importantly, arbitrary order of bins in bin list. }