<commit_before>define( [
            'dojo/_base/declare',
            'JBrowse/Store',
            'JBrowse/Util'],
        function( declare, Store, Util ) {

return declare( null,

/**
 * @lends JBrowse.Store.Sequence.StaticChunked
 * @extends JBrowse.Store
 */
{

/**
 * Storage backend for sequences broken up into chunks, stored and
 * served as static text files.
 * @constructs
 */
    constructor: function(args) {
        this.chunkCache  = {};

        this.compress    = args.compress;
        this.urlTemplate = args.urlTemplate;
        this.baseUrl     = args.baseUrl;
    },

    /**
     * @param {Object} seq object describing the sequence to operate on
     * @param {Number} start start coord, in interbase
     * @param {Number} end end coord, in interbase
     * @param {Function} callback function that takes ( start, end, seq )
     */
    getRange: function( seq, start, end, callback) {

        var seqname    = seq.name;
        var chunkSize  = seq.seqChunkSize;
        var firstChunk = Math.floor( Math.max(0,start) / chunkSize );
        var lastChunk  = Math.floor( (end - 1)         / chunkSize );
        var chunk;

        // if a callback spans more than one chunk, we need to wrap the
        // callback in another one that will be passed to each chunk to
        // concatenate the different pieces from each chunk and *then*
        // call the main callback
        if( firstChunk != lastChunk ) {
            callback = (function() {
                            var chunk_seqs = [],
                            chunks_still_needed = lastChunk-firstChunk+1,
                            orig_callback = callback;
                            return function( start, end, seq, chunkNum) {
                                chunk_seqs[chunkNum] = seq;
                                if( --chunks_still_needed == 0 )
                                    orig_callback( start, end, chunk_seqs.join("") );
                            };
                        })();
        }

        var callbackInfo = { start: start, end: end, callback: callback };

        if( !this.chunkCache[seqname] ) {
            this.chunkCache[seqname] = [];
        }
        var chunkCacheForSeq = this.chunkCache[seqname];

        for (var i = firstChunk; i <= lastChunk; i++) {
            //console.log("working on chunk %d for %d .. %d", i, start, end);

            chunk = chunkCacheForSeq[i];
            if (chunk) {
                if (chunk.loaded) {
                    callback( start,
                              end,
                              chunk.sequence.substring(
                                  start - i*chunkSize,
                                  end - i*chunkSize
                              ),
                              i
                            );
                } else {
                    //console.log("added callback for %d .. %d", start, end);
                    chunk.callbacks.push(callbackInfo);
                }
            } else {
                chunk = {
                    loaded: false,
                    num: i,
                    callbacks: [callbackInfo]
                };
                chunkCacheForSeq[i] = chunk;

                var sequrl = Util.resolveUrl( this.baseUrl,
                                              Util.fillTemplate( this.urlTemplate,
                                                                 {'refseq': seq.name} ));

                dojo.xhrGet({
                                url: sequrl + i + ".txt" + ( this.compress ? 'z' : '' ),
                                load: function (response) {
                                    var ci;
                                    chunk.sequence = response;
                                    for (var c = 0; c < chunk.callbacks.length; c++) {
                                        ci = chunk.callbacks[c];
                                        ci.callback( ci.start,
                                                     ci.end,
                                                     response.substring( ci.start - chunk.num*chunkSize,
                                                                         ci.end   - chunk.num*chunkSize
                                                                       ),
                                                     i
                                                   );
                                    }
                                    chunk.callbacks = undefined;
                                    chunk.loaded = true;
                                }
                            });
            }
        }
    }
});
});<commit_msg>bugfix to sequence store, was not correctly fetching from multiple blocks in one getRange call<commit_after>define( [
            'dojo/_base/declare',
            'JBrowse/Store',
            'JBrowse/Util'],
        function( declare, Store, Util ) {

return declare( null,

/**
 * @lends JBrowse.Store.Sequence.StaticChunked
 * @extends JBrowse.Store
 */
{

/**
 * Storage backend for sequences broken up into chunks, stored and
 * served as static text files.
 * @constructs
 */
    constructor: function(args) {
        this.chunkCache  = {};

        this.compress    = args.compress;
        this.urlTemplate = args.urlTemplate;
        this.baseUrl     = args.baseUrl;
    },

    /**
     * @param {Object} seq object describing the sequence to operate on
     * @param {Number} start start coord, in interbase
     * @param {Number} end end coord, in interbase
     * @param {Function} callback function that takes ( start, end, seq )
     */
    getRange: function( seq, start, end, callback) {

        var seqname    = seq.name;
        var chunkSize  = seq.seqChunkSize;
        var firstChunk = Math.floor( Math.max(0,start) / chunkSize );
        var lastChunk  = Math.floor( (end - 1)         / chunkSize );

        // if a callback spans more than one chunk, we need to wrap the
        // callback in another one that will be passed to each chunk to
        // concatenate the different pieces from each chunk and *then*
        // call the main callback
        if( firstChunk != lastChunk ) {
            callback = (function() {
                            var chunk_seqs = [],
                            chunks_still_needed = lastChunk-firstChunk+1,
                            orig_callback = callback;
                            return function( start, end, seq, chunkNum) {
                                chunk_seqs[chunkNum] = seq;
                                if( --chunks_still_needed == 0 )
                                    orig_callback( start, end, chunk_seqs.join("") );
                            };
                        })();
        }

        var callbackInfo = { start: start, end: end, callback: callback };

        if( !this.chunkCache[seqname] ) {
            this.chunkCache[seqname] = [];
        }
        var chunkCacheForSeq = this.chunkCache[seqname];

        for (var i = firstChunk; i <= lastChunk; i++) {
            //console.log("working on chunk %d for %d .. %d", i, start, end);

            var chunk = chunkCacheForSeq[i];
            if (chunk) {
                if (chunk.loaded) {
                    callback( start,
                              end,
                              chunk.sequence.substring(
                                  start - i*chunkSize,
                                  end - i*chunkSize
                              ),
                              i
                            );
                } else {
                    //console.log("added callback for %d .. %d", start, end);
                    chunk.callbacks.push(callbackInfo);
                }
            } else {
                chunkCacheForSeq[i] = {
                    loaded: false,
                    num: i,
                    callbacks: [callbackInfo]
                };

                var sequrl = Util.resolveUrl( this.baseUrl,
                                              Util.fillTemplate( this.urlTemplate,
                                                                 {'refseq': seq.name} ));

                dojo.xhrGet({
                                url: sequrl + i + ".txt" + ( this.compress ? 'z' : '' ),
                                load: dojo.hitch( this, function( chunkRecord, response ) {
                                    //console.log('response for chunk '+chunkRecord.num);
                                    chunkRecord.sequence = response;
                                    chunkRecord.loaded = true;
                                    dojo.forEach( chunkRecord.callbacks, function(ci) {
                                        ci.callback( ci.start,
                                                     ci.end,
                                                     response.substring( ci.start - chunkRecord.num*chunkSize,
                                                                         ci.end   - chunkRecord.num*chunkSize
                                                                       ),
                                                     i
                                                   );
                                    });
                                    delete chunkRecord.callbacks;

                                }, chunkCacheForSeq[i] )
                            });
            }
        }
    }
});
});
{'fraction_non_alphanumeric': 0.09014830508474576, 'fraction_numerical': 0.0009533898305084746, 'mean_word_length': 0.9290968532897426, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 62, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1073995', 'n_tokens_mistral': 2166, 'n_tokens_neox': 2065, 'n_words': 553}