/** * Load in index from the specified file. The type of index (LinearIndex or IntervalTreeIndex) is determined * at run time by reading the type flag in the file. * * @param indexFile from which to load the index */ public static Index loadIndex(final String indexFile) { return loadIndex(indexFile, (Function<SeekableByteChannel, SeekableByteChannel>) null); }
/** * Create a dynamic index with the default balancing approach * * @param inputFile the input file to load features from * @param codec the codec to use for decoding records */ public static <FEATURE_TYPE extends Feature, SOURCE_TYPE> Index createDynamicIndex(final File inputFile, final FeatureCodec<FEATURE_TYPE, SOURCE_TYPE> codec) { return createDynamicIndex(inputFile, codec, IndexBalanceApproach.FOR_SEEK_TIME); }
/** * Create an index of the specified type with default binning parameters * * @param inputFile the input file to load features from * @param codec the codec to use for decoding records * @param type the type of index to create * @param sequenceDictionary May be null, but if present may reduce memory footprint for tabix index creation */ public static <FEATURE_TYPE extends Feature, SOURCE_TYPE> Index createIndex(final File inputFile, final FeatureCodec<FEATURE_TYPE, SOURCE_TYPE> codec, final IndexType type, final SAMSequenceDictionary sequenceDictionary) { switch (type) { case INTERVAL_TREE: return createIntervalIndex(inputFile, codec); case LINEAR: return createLinearIndex(inputFile, codec); case TABIX: return createTabixIndex(inputFile, codec, sequenceDictionary); } throw new IllegalArgumentException("Unrecognized IndexType " + type); }
/** * Create a index of the specified type with default binning parameters * * @param inputFile the input file to load features from * @param codec the codec to use for decoding records * @param type the type of index to create */ public static <FEATURE_TYPE extends Feature, SOURCE_TYPE> Index createIndex(final File inputFile, final FeatureCodec<FEATURE_TYPE, SOURCE_TYPE> codec, final IndexType type) { switch (type) { case INTERVAL_TREE: return createIntervalIndex(inputFile, codec); case LINEAR: return createLinearIndex(inputFile, codec); // Tabix index initialization requires additional information, so this construction method won't work. case TABIX: throw new UnsupportedOperationException("Tabix indices cannot be created through a generic interface"); } throw new IllegalArgumentException("Unrecognized IndexType " + type); }
/** * Load in index from the specified file. The type of index (LinearIndex or IntervalTreeIndex) is determined * at run time by reading the type flag in the file. * * @param indexFile from which to load the index * @param indexWrapper a wrapper to apply to the raw byte stream of the index file, only applied to uri's loaded as * {@link java.nio.file.Path} */ public static Index loadIndex(final String indexFile, Function<SeekableByteChannel, SeekableByteChannel> indexWrapper) { try { return loadIndex(indexFile, indexFileInputStream(indexFile, indexWrapper)); } catch (final IOException ex) { throw new TribbleException.UnableToReadIndexFile("Unable to read index file", indexFile, ex); } }
public Index getIndex(final File vcfFile) { switch (type) { case DYNAMIC_SEEK : return IndexFactory.createDynamicIndex(vcfFile, new VCFCodec(), IndexFactory.IndexBalanceApproach.FOR_SEEK_TIME); case DYNAMIC_SIZE : return IndexFactory.createDynamicIndex(vcfFile, new VCFCodec(), IndexFactory.IndexBalanceApproach.FOR_SIZE); case LINEAR : return IndexFactory.createLinearIndex(vcfFile, new VCFCodec(), parameter); case INTERVAL : return IndexFactory.createIntervalIndex(vcfFile, new VCFCodec(), parameter); default : throw new TestException("Invalid index type"); } } }
/** * a helper method for creating a linear binned index with default bin size * * @param inputFile the input file to load features from * @param codec the codec to use for decoding records */ public static LinearIndex createLinearIndex(final File inputFile, final FeatureCodec codec) { return createLinearIndex(inputFile, codec, LinearIndexCreator.DEFAULT_BIN_WIDTH); }
@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)); }
/** * Create a index of the specified type with default binning parameters * * @param inputFile the input file to load features from * @param codec the codec to use for decoding records * @param type the type of index to create */ public static <FEATURE_TYPE extends Feature, SOURCE_TYPE> Index createIndex(final File inputFile, final FeatureCodec<FEATURE_TYPE, SOURCE_TYPE> codec, final IndexType type) { return createIndex(inputFile, codec, type, null); }
/** * create an interval-tree index with the default features per bin count * * @param inputFile the file containing the features * @param codec to decode the features */ public static <FEATURE_TYPE extends Feature, SOURCE_TYPE> IntervalTreeIndex createIntervalIndex(final File inputFile, final FeatureCodec<FEATURE_TYPE, SOURCE_TYPE> codec) { return createIntervalIndex(inputFile, codec, IntervalIndexCreator.DEFAULT_FEATURE_COUNT); }
/** * @param inputFile The file to be indexed. * @param codec the codec to use for decoding records * @param sequenceDictionary May be null, but if present may reduce memory footprint for index creation. Features * in inputFile must be in the order defined by sequenceDictionary, if it is present. * */ public static <FEATURE_TYPE extends Feature, SOURCE_TYPE> TabixIndex createTabixIndex(final File inputFile, final FeatureCodec<FEATURE_TYPE, SOURCE_TYPE> codec, final SAMSequenceDictionary sequenceDictionary) { return createTabixIndex(inputFile, codec, codec.getTabixFormat(), sequenceDictionary); }
private static Index createIndex(final File inputFile, final FeatureIterator iterator, final IndexCreator creator) { Feature lastFeature = null; Feature currentFeature; final Map<String, Feature> visitedChromos = new HashMap<String, Feature>(40); while (iterator.hasNext()) { final long position = iterator.getPosition(); currentFeature = iterator.next(); checkSorted(inputFile, lastFeature, currentFeature); //should only visit chromosomes once final String curChr = currentFeature.getContig(); final String lastChr = lastFeature != null ? lastFeature.getContig() : null; if(!curChr.equals(lastChr)){ if(visitedChromos.containsKey(curChr)){ String msg = "Input file must have contiguous chromosomes."; msg += " Saw feature " + featToString(visitedChromos.get(curChr)); msg += " followed later by " + featToString(lastFeature); msg += " and then " + featToString(currentFeature); throw new TribbleException.MalformedFeatureFile(msg, inputFile.getAbsolutePath()); }else{ visitedChromos.put(curChr, currentFeature); } } creator.addFeature(currentFeature, position); lastFeature = currentFeature; } // Get the end position of the last feature before closing the iterator long finalPosition = iterator.getPosition(); iterator.close(); return creator.finalizeIndex(finalPosition); }
public Index getIndex(final File vcfFile) { switch (type) { case DYNAMIC_SEEK : return IndexFactory.createDynamicIndex(vcfFile, new VCFCodec(), IndexFactory.IndexBalanceApproach.FOR_SEEK_TIME); case DYNAMIC_SIZE : return IndexFactory.createDynamicIndex(vcfFile, new VCFCodec(), IndexFactory.IndexBalanceApproach.FOR_SIZE); case LINEAR : return IndexFactory.createLinearIndex(vcfFile, new VCFCodec(), parameter); case INTERVAL : return IndexFactory.createIntervalIndex(vcfFile, new VCFCodec(), parameter); default : throw new TestException("Invalid index type"); } } }
/** * a helper method for creating a linear binned index with default bin size * * @param inputFile the input file to load features from * @param codec the codec to use for decoding records */ public static LinearIndex createLinearIndex(final File inputFile, final FeatureCodec codec) { return createLinearIndex(inputFile, codec, LinearIndexCreator.DEFAULT_BIN_WIDTH); }
AbstractIndex idx = null; if (indexType == LINEAR_INDEX) { idx = IndexFactory.createLinearIndex(inputFile, codec, binSize); } else { idx = IndexFactory.createIntervalIndex(inputFile, codec, binSize);
/** * Create a index of the specified type with default binning parameters * * @param inputFile the input file to load features from * @param codec the codec to use for decoding records * @param type the type of index to create */ public static <FEATURE_TYPE extends Feature, SOURCE_TYPE> Index createIndex(final File inputFile, final FeatureCodec<FEATURE_TYPE, SOURCE_TYPE> codec, final IndexType type) { return createIndex(inputFile, codec, type, null); }
/** * create an interval-tree index with the default features per bin count * * @param inputFile the file containing the features * @param codec to decode the features */ public static <FEATURE_TYPE extends Feature, SOURCE_TYPE> IntervalTreeIndex createIntervalIndex(final File inputFile, final FeatureCodec<FEATURE_TYPE, SOURCE_TYPE> codec) { return createIntervalIndex(inputFile, codec, IntervalIndexCreator.DEFAULT_FEATURE_COUNT); }
/** * Load in index from the specified file. The type of index (LinearIndex or IntervalTreeIndex) is determined * at run time by reading the type flag in the file. * * @param indexFile from which to load the index * @param indexWrapper a wrapper to apply to the raw byte stream of the index file, only applied to uri's loaded as * {@link java.nio.file.Path} */ public static Index loadIndex(final String indexFile, Function<SeekableByteChannel, SeekableByteChannel> indexWrapper) { try { return loadIndex(indexFile, indexFileInputStream(indexFile, indexWrapper)); } catch (final IOException ex) { throw new TribbleException.UnableToReadIndexFile("Unable to read index file", indexFile, ex); } }
/** * @param inputFile The file to be indexed. * @param codec the codec to use for decoding records * @param sequenceDictionary May be null, but if present may reduce memory footprint for index creation. Features * in inputFile must be in the order defined by sequenceDictionary, if it is present. * */ public static <FEATURE_TYPE extends Feature, SOURCE_TYPE> TabixIndex createTabixIndex(final File inputFile, final FeatureCodec<FEATURE_TYPE, SOURCE_TYPE> codec, final SAMSequenceDictionary sequenceDictionary) { return createTabixIndex(inputFile, codec, codec.getTabixFormat(), sequenceDictionary); }
private static Index createIndex(final File inputFile, final FeatureIterator iterator, final IndexCreator creator) { Feature lastFeature = null; Feature currentFeature; final Map<String, Feature> visitedChromos = new HashMap<String, Feature>(40); while (iterator.hasNext()) { final long position = iterator.getPosition(); currentFeature = iterator.next(); checkSorted(inputFile, lastFeature, currentFeature); //should only visit chromosomes once final String curChr = currentFeature.getChr(); final String lastChr = lastFeature != null ? lastFeature.getChr() : null; if(!curChr.equals(lastChr)){ if(visitedChromos.containsKey(curChr)){ String msg = "Input file must have contiguous chromosomes."; msg += " Saw feature " + featToString(visitedChromos.get(curChr)); msg += " followed later by " + featToString(lastFeature); msg += " and then " + featToString(currentFeature); throw new TribbleException.MalformedFeatureFile(msg, inputFile.getAbsolutePath()); }else{ visitedChromos.put(curChr, currentFeature); } } creator.addFeature(currentFeature, position); lastFeature = currentFeature; } iterator.close(); return creator.finalizeIndex(iterator.getPosition()); }