/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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 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); }
/** * 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); } }
@Override protected Index doInBackground() throws Exception { int binSize = IgvTools.LINEAR_BIN_SIZE; FeatureCodec codec = CodecFactory.getCodec(file.getAbsolutePath(), GenomeManager.getInstance().getCurrentGenome()); if (codec != null) { try { Index index = IndexFactory.createLinearIndex(file, codec, binSize); if (index != null) { IgvTools.writeTribbleIndex(index, idxFile.getAbsolutePath()); } return index; } catch (TribbleException.MalformedFeatureFile e) { StringBuffer buf = new StringBuffer(); buf.append("<html>Files must be sorted by start position prior to indexing.<br>"); buf.append(e.getMessage()); buf.append("<br><br>Note: igvtools can be used to sort the file, select \"File > Run igvtools...\"."); MessageUtils.showMessage(buf.toString()); } } else { throw new DataLoadException("Unknown File Type", file.getAbsolutePath()); } return null; } }
AbstractIndex idx = null; if (indexType == LINEAR_INDEX) { idx = IndexFactory.createLinearIndex(inputFile, codec, binSize); } else { idx = IndexFactory.createIntervalIndex(inputFile, codec, binSize);
@Test(dataProvider = "bedDataProvider") public void testCreateLinearIndexFromBED(final File inputBEDFIle) throws Exception { Index index = IndexFactory.createLinearIndex(inputBEDFIle, new BEDCodec()); String chr = "chr2"; Assert.assertTrue(index.getSequenceNames().contains(chr)); Assert.assertTrue(index.containsChromosome(chr)); Assert.assertEquals(1, index.getSequenceNames().size()); List<Block> blocks = index.getBlocks(chr, 1, 50); Assert.assertEquals(1, blocks.size()); Block block = blocks.get(0); Assert.assertEquals(78, block.getSize()); }
@Test public void oneEntryFirstChr() { final BEDCodec code = new BEDCodec(); final Index index = IndexFactory.createLinearIndex(fakeBed, code); final AbstractFeatureReader reader = AbstractFeatureReader.getFeatureReader(fakeBed.getAbsolutePath(), code, index); try { final CloseableTribbleIterator it = reader.iterator(); int count = 0; while (it.hasNext()) { it.next(); count++; } Assert.assertEquals(51, count); } catch (final IOException e) { Assert.fail("Unable to get iterator due to " + e.getMessage()); } }
Index idx = IndexFactory.createLinearIndex(new File(bedFile), new BEDCodec(), binSize); idx = IndexFactory.createLinearIndex(new File(bedFile), new BEDCodec(), binSize);
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"); } } }
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"); } } }