Package htsjdk.tribble.index

Examples of htsjdk.tribble.index.Index


        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();
            }
        }
View Full Code Here


        String bedFile = TestUtils.DATA_DIR + "bed/test.bed";

        String idxPath = doStandardIndex(bedFile, "idx");

        Index idx = IndexFactory.loadIndex(idxPath);

        List<Block> blocks = idx.getBlocks("chr1", 100, 200);
        Block block = blocks.get(0);
        assertEquals("Unexpected start position ", 0, block.getStartPosition());

    }
View Full Code Here

     * @param binSize
     * @throws IOException
     */
    private void createTribbleIndex(String ifile, File outputFile, int indexType, int binSize, FeatureCodec codec) throws IOException {
        File inputFile = new File(ifile);
        Index idx = null;
        if (indexType == LINEAR_INDEX) {
            idx = IndexFactory.createLinearIndex(inputFile, codec, binSize);
        } else {
            idx = IndexFactory.createIntervalIndex(inputFile, codec, binSize);
        }
View Full Code Here

        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) {
View Full Code Here

        // Detect whether or not this source should be indexed.
        boolean canBeIndexed = (storageType == RMDStorageType.FILE);

        if(canBeIndexed) {
            try {
                Index index = loadIndex(inputFile, createCodec(descriptor, name, inputFile));
                try { logger.info(String.format("  Index for %s has size in bytes %d", inputFile, Sizeof.getObjectGraphSize(index))); }
                catch (ReviewedGATKException e) { }

                sequenceDictionary = IndexDictionaryUtils.getSequenceDictionaryFromProperties(index);
View Full Code Here

     * @throws IOException if we cannot write the index file
     */
    public synchronized Index loadIndex( final File inputFile, final FeatureCodec codec) throws IOException {
        final File indexFile = Tribble.indexFile(inputFile);
        final FSLockWithShared lock = new FSLockWithShared(indexFile);
        Index idx = null;

        // If the index file exists and is readable, attempt to load it from disk. We'll get null back
        // if a problem was discovered with the index file when it was inspected, and we'll get an
        // in-memory index back in the case where the index file could not be locked.
        if (indexFile.canRead()) {
View Full Code Here

     * @return an index, or null if we couldn't load one
     * @throws IOException if we fail for FS issues
     */
    protected Index attemptToLockAndLoadIndexFromDisk( final File inputFile, final FeatureCodec codec, final File indexFile, final FSLockWithShared lock ) throws IOException {
        boolean locked = false;
        Index idx = null;

        try {
            locked = lock.sharedLock();

            if ( ! locked ) { // can't lock file
View Full Code Here

     * @param indexFile the input file, plus the index extension
     * @return an Index, or null if we're unable to load
     */
    protected Index loadFromDisk( final File inputFile, final File indexFile ) {
        logger.debug("Loading Tribble index from disk for file " + inputFile);
        Index index = IndexFactory.loadIndex(indexFile.getAbsolutePath());

        // check if the file is up-to date (filestamp and version check)
        if (index.isCurrentVersion() && indexFile.lastModified() >= inputFile.lastModified())
            return index;
        else if (indexFile.lastModified() < inputFile.lastModified())
            logger.warn("Index file " + indexFile + " is out of date (index older than input file), " +
                        (disableAutoIndexCreation ? "falling back to an in-memory index" : "deleting and updating the index file"));
        else // we've loaded an old version of the index, we want to remove it <-- currently not used, but may re-enable
View Full Code Here

     * @throws IOException when unable to create the index in memory
     */
    protected Index createIndexInMemory(File inputFile, FeatureCodec codec) {
        // this can take a while, let them know what we're doing
        logger.debug("Creating Tribble index in memory for file " + inputFile);
        Index idx = IndexFactory.createDynamicIndex(inputFile, codec, IndexFactory.IndexBalanceApproach.FOR_SEEK_TIME);
        validateAndUpdateIndexSequenceDictionary(inputFile, idx, dict);
        return idx;
    }
View Full Code Here

                // todo -- currently we only understand VCF files! Blow up since we can't test them
                throw new GATKException("Found an index created for file " + resultFile + " but we can only validate VCF files.  Extend this code!");
            }

            System.out.println("Verifying on-the-fly index " + indexFile + " for test " + name + " using file " + resultFile);
            Index indexFromOutputFile = IndexFactory.createDynamicIndex(resultFile, new VCFCodec());
            Index dynamicIndex = IndexFactory.loadIndex(indexFile.getAbsolutePath());

            if ( ! indexFromOutputFile.equalsIgnoreProperties(dynamicIndex) ) {
                Assert.fail(String.format("Index on disk from indexing on the fly not equal to the index created after the run completed.  FileIndex %s vs. on-the-fly %s%n",
                        indexFromOutputFile.getProperties(),
                        dynamicIndex.getProperties()));
            }
        }
    }
View Full Code Here

TOP

Related Classes of htsjdk.tribble.index.Index

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.