/** * Write the index to a file; little endian. * @param idx * @param idxFile * @throws IOException * @deprecated use {@link Index#write(File)} instead */ @Deprecated public static void writeIndex(final Index idx, final File idxFile) throws IOException { idx.write(idxFile); }
/** * Write the index to a file; little endian. * @param idx * @param idxFile * @throws IOException * @deprecated use {@link Index#write(File)} instead */ @Deprecated public static void writeIndex(final Index idx, final File idxFile) throws IOException { idx.write(idxFile); }
/** * Writes the index into a file. * * Default implementation delegates to {@link #write(Path)} * * @param idxFile Where to write the index. * @throws IOException if the index is unable to write to the specified file */ public default void write(final File idxFile) throws IOException { write(IOUtil.toPath(idxFile)); }
/** * Writes the index into a file. * * Default implementation delegates to {@link #write(Path)} * * @param idxFile Where to write the index. * @throws IOException if the index is unable to write to the specified file */ public default void write(final File idxFile) throws IOException { write(IOUtil.toPath(idxFile)); }
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(); } } }
/** * 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(); } }
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(); }
@Test(dataProvider = "writeIndexData") public void testWriteIndex(final File inputFile, final IndexFactory.IndexType type, final FeatureCodec codec) throws Exception { // temp index file for this test final File tempIndex = File.createTempFile("index", (type == IndexFactory.IndexType.TABIX) ? TabixUtils.STANDARD_INDEX_EXTENSION : Tribble.STANDARD_INDEX_EXTENSION); tempIndex.delete(); tempIndex.deleteOnExit(); // create the index final Index index = IndexFactory.createIndex(inputFile, codec, type); Assert.assertFalse(tempIndex.exists()); // write the index to a file index.write(tempIndex); Assert.assertTrue(tempIndex.exists()); // load the generated index final Index loadedIndex = IndexFactory.loadIndex(tempIndex.getAbsolutePath()); //TODO: This is just a smoke test; it can pass even if the generated index is unusable for queries. // test that the sequences and properties are the same Assert.assertEquals(loadedIndex.getSequenceNames(), index.getSequenceNames()); Assert.assertEquals(loadedIndex.getProperties(), index.getProperties()); // test that write to a stream does not blows ip index.write(new LittleEndianOutputStream(nullOutputStrem)); }
private static <FEATURE extends Feature, SOURCE extends LocationAware> AbstractFeatureReader<FEATURE, SOURCE> getReader(final File featureFile, final IndexFactory.IndexType indexType, final FeatureCodec<FEATURE, SOURCE> codec) throws IOException { if (indexType.canCreate()) { // for types we can create make a new index each time final File idxFile = Tribble.indexFile(featureFile); // delete an already existing index if (idxFile.exists()) { idxFile.delete(); } final Index idx = IndexFactory.createIndex(featureFile, codec, indexType); idx.write(idxFile); idxFile.deleteOnExit(); } // else let's just hope the index exists, and if so use it return AbstractFeatureReader.getFeatureReader(featureFile.getAbsolutePath(), codec); }
@Test(dataProvider = "writeIndexData") public void testWritePathIndex(final File inputFile, final IndexFactory.IndexType type, final FeatureCodec codec) throws Exception { try (final FileSystem fs = Jimfs.newFileSystem("test", Configuration.unix())) { // create the index final Index index = IndexFactory.createIndex(inputFile, codec, type); final Path path = fs.getPath(inputFile.getName() + ".index"); // write the index to a file index.write(path); // test if the index does not blow up with the path constructor switch (type) { case TABIX: new TabixIndex(path); break; case LINEAR: new LinearIndex(path); break; case INTERVAL_TREE: new IntervalTreeIndex(path); break; } } }