/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2016-2017 The Regents of the University of California
 * Author: Jim Robinson
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

var igv = (function (igv) {

    igv.UCSCServiceReader = function (config) {
        this.config = config;
    };

    igv.UCSCServiceReader.prototype.readFeatures = function (chr, start, end) {
        var self = this,
            url = this.config.url + '&table=' + this.config.tableName + '&chr=' + chr + '&start=' + start + '&end=' + end;

        return new Promise(function (fulfill, reject) {
            igv.xhr.loadJson(url, self.config)
                .then(function (data) {
                    if (data) {
                        fulfill(data);
                    } else {
                        fulfill(null);
                    }
                })
                .catch(function (error) {
                    reject(error);
                });
        });
    };


    return igv;
})(igv || {});

@@ -1749,247 +1749,1503 @@
     
-fulfill(data);%0A                    %7D else %7B%0A                        fulfill(null);%0A                    %7D%0A                %7D)%0A                .catch(function (error) %7B%0A                    reject(error);%0A                %7D);%0A        %7D);%0A    %7D;
+data.forEach(function(sample) %7B%0A                            if (sample.hasOwnProperty('exonStarts') && sample.hasOwnProperty('exonEnds') && sample.hasOwnProperty('exonCount')%0A                                && sample.hasOwnProperty('cdsStart') && sample.hasOwnProperty('cdsEnd')) %7B%0A%0A                                addExons(sample);%0A                            %7D%0A                        %7D);%0A                        fulfill(data);%0A                    %7D else %7B%0A                        fulfill(null);%0A                    %7D%0A                %7D)%0A                .catch(function (error) %7B%0A                    reject(error);%0A                %7D);%0A        %7D);%0A    %7D;%0A%0A    function addExons(sample) %7B%0A        var exonCount, exonStarts, exonEnds, exons, eStart, eEnd;%0A        exonCount = sample%5B'exonCount'%5D;%0A        exonStarts = sample%5B'exonStarts'%5D.split(',');%0A        exonEnds = sample%5B'exonEnds'%5D.split(',');%0A        exons = %5B%5D;%0A%0A        for (var i = 0; i %3C exonCount; i++) %7B%0A            eStart = parseInt(exonStarts%5Bi%5D);%0A            eEnd = parseInt(exonEnds%5Bi%5D);%0A            var exon = %7Bstart: eStart, end: eEnd%7D;%0A%0A            if (sample.cdsStart %3E eEnd %7C%7C sample.cdsEnd %3C sample.cdsStart) exon.utr = true;   // Entire exon is UTR%0A            if (sample.cdsStart %3E= eStart && sample.cdsStart %3C= eEnd) exon.cdStart = sample.cdsStart;%0A            if (sample.cdsEnd %3E= eStart && sample.cdsEnd %3C= eEnd) exon.cdEnd = sample.cdsEnd;%0A%0A            exons.push(exon);%0A        %7D%0A%0A        sample.exons = exons;%0A    %7D
 %0A%0A%0A 

add exons to ucsc gene track (#437)