UNPKG

biojs-vis-wigexplorer

Version:
1 lines 17.3 kB
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;"undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self),e.biojsVisWigexplorer=t()}}(function(){var t;return function e(t,r,n){function i(a,s){if(!r[a]){if(!t[a]){var l="function"==typeof require&&require;if(!s&&l)return l(a,!0);if(o)return o(a,!0);var p=new Error("Cannot find module '"+a+"'");throw p.code="MODULE_NOT_FOUND",p}var c=r[a]={exports:{}};t[a][0].call(c.exports,function(e){var r=t[a][1][e];return i(r?r:e)},c,c.exports,e,t,r,n)}return r[a].exports}for(var o="function"==typeof require&&require,a=0;a<n.length;a++)i(n[a]);return i}({1:[function(t,e,r){var n,i=t("js-class");e.exports=n=i({zoomSlider:"",slider_stop:0,slider_start:0,track:[],width:1,height:1,data_last_start:1,data_first_start:1,max:0,span:null,chrom:[],data:[],main_data:[],constructor:function(e){var r=this;r.vis=null,r.color=null,r.foci=[],this.track,t("js-extend").extend(this.opt,e),this._container=$("#wigFeaturePainter-holder"),$(this._container).addClass("graph"),this._container.css({"font-family":r.opt.fontFamily,"background-color":r.opt.selectionBackgroundColor,color:r.opt.fontColor,"font-size":"36px","text-align":"center","vertical-align":"middle",width:"700px",height:"100px",bottom:"0px"}),this._container.css({"-moz-user-select":"none","-webkit-user-select":"none","user-select":"none"}),this.color=r.opt.selectionBackgroundColor,this.paintFeatures(r.opt.dataSet)},opt:{target:"YourOwnDivId",dataSet:"",fontFamily:'"Andale mono", courier, monospace',fontColor:"white",backgroundColor:"",selectionFontColor:"black",selectionBackgroundColor:"yellow",width:"100%",height:"130",radius:10,reference:null},eventTypes:[],_updateDraw:function(t,e,r){var n=this;t&&e&&(this.slider_start=t,this.slider_stop=e),r||(r=n.opt.target),parseFloat(this.slider_start)<parseFloat(this.slider_stop)&&this.paintWig(this.slider_start,this.slider_stop,r)},paintFeatures:function(t){void 0!=t?(this._setDataSource(t),this._init()):alert("Dataset not defined ")},_init:function(){n.myself=this;var t=this,e=jQuery("#"+this.opt.target);e.text(""),e.append(this._withSliderOnly(100)),e.append("<div id="+this.opt.target+"_wigFeaturePainter-holder></div>");var r=document.getElementById(this.opt.target+"_wigFeaturePainter-holder");if(!r)throw this.jQueryerrorMsg=jQuery('<div id="wigFeaturePainter-errorInit"></div>').html("There was an unexpected failure, the image cannot be displayed.").dialog({autoOpen:!0,title:"Error",modal:!0}),"Error";if(r.innerHTML="",r.style.height="250px",r.style.width=t.opt.width?t.opt.width:"700px",this.width=jQuery("#"+t.opt.target+"_wigFeaturePainter-holder").width(),this.height=this.height=jQuery("#"+t.opt.target+"_wigFeaturePainter-holder").height(),this.r=t.opt.radius,t.opt.width=t.opt.width.toString(),t.opt.width.indexOf("%")>=1?t.opt.width=jQuery(this.opt.target).width*parseInt(t.opt.width.toString())/100:t.opt.width=parseInt(this.width),t.opt.height=t.opt.height.toString(),t.opt.height.indexOf("%")>=1&&(t.opt.height=t.opt.height.toString()),t.opt.height.indexOf("%")!=-1?this.height=this.height*(1*t.opt.height.substring(0,t.opt.height.length-1))/100:this.height=1*t.opt.height,t.opt.height=parseInt(this.height),t.color=function(){return d3.scale.ordinal().range(t.colors)}(),t.opt.dataSet.indexOf(".")>=0&&t.opt.dataSet.length<100)jQuery.ajax({type:"GET",url:t.opt.dataSet,dataType:"text",success:function(e){var r=e.split("\n"),n=r.length;if(e.indexOf("variableStep")>=0||e.indexOf("fixedStep")>=0){t.chrom=[];for(var i=0;i<n;i++)if(r[i].indexOf("chrom")>=0){var o=r[i].split(/\s+/)[1].split("=")[1];t.chrom.indexOf(o)<0&&t.chrom.push(o)}t._buildReferenceSelector()}else alert("Unknown format detected")},error:function(t,e,r){alert(e)}});else{var i=t.opt.dataSet,o=i.split("\n"),a=o.length;if(i.indexOf("variableStep")>=0||i.indexOf("fixedStep")>=0){t.chrom=[];for(var s=0;s<a;s++)if(o[s].indexOf("chrom")>=0){var l=o[s].split(/\s+/)[1].split("=")[1];t.chrom.indexOf(l)<0&&t.chrom.push(l)}t._buildReferenceSelector()}else alert("Unknown format detected")}},_buildReferenceSelector:function(){var t=this;this._headerDiv=jQuery("#"+t.opt.target+"_selectorMenu"),this._headerDiv.css({"font-family":'"Heveltica Neue", Arial, "sans serif"',"font-size":"14px"}).append("Reference: ");for(var e="<select id="+t.opt.target+"ref_selector>",r=0;r<this.chrom.length;r++)e+="<option value='"+this.chrom[r]+"'>"+this.chrom[r]+"</option>";e+="/<select>",this._formatSelector=jQuery(e).appendTo(t._headerDiv),this._formatSelector.change(function(e){t.opt.reference=jQuery(this).val(),t.setReference(t.opt.reference,t.opt.target)}),t.setReference(this._formatSelector.val())},_withSliderOnly:function(t){var e=this,r='<table width="100%"><tr><td width="75%"><div id="'+e.opt.target+'_wigFeaturePainter-slider" style="margin-left: 10px; text-align:left"></div></td><td><div id="'+e.opt.target+'_selectorMenu" style="margin-left: 10px;text-align:right"> </div></td></tr></table><br/>';return r},_paintSlider:function(){var t=this;if(document.getElementById(t.opt.target+"_wigFeaturePainter-slider")){var e=jQuery("#"+t.opt.target+"_wigFeaturePainter-slider");e.text(""),e.append('<label for="wigFeaturePainter-slider-values"></label>'),e.append('<div type="text" id="wigFeaturePainter-slider-values" style="margin-bottom:5px" />');var r=this.track.length-1,n=parseInt(this.track[r][0])-parseInt(this.track[0][0]);parseInt(n/20);this.zoomSlider=jQuery('<div id="wigFeaturePainter-slider-bar" style="width:300px"></div>').appendTo(e);var i=t.opt.dataSet;i.indexOf(" ")&&(i=t.opt.dataSet.split(" ")[0]);var o="<button id = "+i+" class=zoomin>+</button><button id = "+i+" class=zoomout>-</button><button id = "+i+" class=left><</button><button id = "+i+" class=right >></button>";jQuery(e).html(""),this._updateSelector=jQuery(o).appendTo(e),this._updateSelector.click(function(e){jQuery(this).hasClass("left")?t._moveleft():jQuery(this).hasClass("right")?t._moveright():jQuery(this).hasClass("zoomin")?t._zoomin():jQuery(this).hasClass("zoomout")&&t._zoomout()})}},_zoomin:function(){var t=this,e=(t.slider_stop-t.slider_start)/10;t._updateDraw(t.slider_start+e,t.slider_stop-e,t.opt.target)},_zoomout:function(){var t=this,e=(t.slider_stop-t.slider_start)/10;t._updateDraw(t.slider_start-e,t.slider_stop+e,t.opt.target)},_moveleft:function(){var t=this,e=(t.slider_stop-t.slider_start)/10;t._updateDraw(t.slider_start-e,t.slider_stop-e,t.opt.target)},_moveright:function(){var t=this,e=(t.slider_stop-t.slider_start)/10;t._updateDraw(t.slider_start+e,t.slider_stop+e,t.opt.target)},setReference:function(t){function e(e,r){var i=[],o=0,a=e.split("\n"),s=a.length,l=null,p=!1;if(e.indexOf("variableStep")>=0){for(var a=e.split("\n"),s=a.length,c=0;c<s;c++)if(a[c].indexOf("chrom")>=0){var f=a[c].split(/\s+/)[1].split("=")[1];n=!1,f==t&&(a[c].indexOf("span")>=0&&(l=a[c].split(/\s+/)[2].split("=")[1]),n=!0,p=!0)}else{if(a[c].indexOf("#")>=0)continue;if(n&&a[c].length>0){var h=a[c].split(/\s+/);i.push([h[0],h[1],l]),parseInt(h[1])>parseInt(o)&&(o=h[1])}}if(r.max=o,r.track=i,0==p)alert("Selected reference not found");else if(i.length>0){var u=parseInt(i[0][0]),d=parseInt(i[i.length-1][0]);r.slider_start=u,r.slider_stop=d,r.data_last_start=d,r.data_first_start=u}else alert("No data for selected reference")}else if(e.indexOf("fixedStep")>=0){for(var a=e.split("\n"),s=a.length,u=null,g=null,p=!1,c=0;c<s;c++)if(a[c].indexOf("chrom")>=0){var v=a[c].split(/\s+/),f=a[c].split(/\s+/)[1].split("=")[1];n=!1,f==t&&(u=v[2].split("=")[1],g=v[3].split("=")[1],a[c].indexOf("span")>=0&&(l=v[4].split("=")[1]),n=!0,p=!0)}else{if(a[c].indexOf("#")>=0)continue;if(n&&a[c].length>0){var h=a[c];u=parseInt(u)+parseInt(g),i.push([u,h,l]),parseInt(h)>parseInt(o)&&(o=h)}}if(r.max=o,r.track=i,0==p)alert("Selected reference not found");else if(i.length>0){var u=parseInt(i[0][0]),d=parseInt(i[i.length-1][0]);r.slider_start=u,r.slider_stop=d,r.data_last_start=d,r.data_first_start=u}else null==u||null==g?alert("Unknown format detected"):alert("No data for selected reference")}else alert("Unknown format detected")}var r=this,n=!1;if(r.opt.dataSet.indexOf(".")>=0&&r.opt.dataSet.length<100)jQuery.ajax({type:"GET",url:r.opt.dataSet,dataType:"text",success:function(t){e(t,r)},error:function(t,e,r){alert(e)}}).done(function(){r._paintSlider(),r._updateDraw()});else{var i=r.opt.dataSet;e(i,r),r._paintSlider(),r._updateDraw()}},paintWig:function(t,e,r){if(this.track.length>0){var n=this.opt.selectionBackgroundColor,i="50px",o="0px",a=[],s=this.height,l=this.width,p=this.max;if(t&&e)a=this.track,a=jQuery.grep(a,function(r){return r[0]>=t&&r[0]<=e});else{a=this.track;var c=this.track.length-1;e=parseInt(this.track[c][0]),t=parseInt(this.track[0][0])}var f=parseInt(l)/(e-t),c=a.length-1;if(c>0){this._clear(r);var h=d3.select("#"+r+"_wigFeaturePainter-holder").append("svg").attr("width",this.width+20).attr("height",$("#"+r+"_wigFeaturePainter-holder").height()).append("g").attr("transform","translate("+i+","+o+")");this._container=jQuery("#"+r+"_wigFeaturePainter-holder");var u=d3.svg.line().x(function(t){return t.x}).y(function(t){return t.y}).interpolate("linear"),d=parseInt(a[c][0])+parseInt(a[1][0]-a[0][0]),g=parseInt(a[0][0])-parseInt(a[1][0]-a[0][0]);g<0&&(g=0),a.splice(0,0,[g,0]),t<0&&a.splice(0,0,[t,0]),a.splice(e,0,[d,0]),a.splice(a.length-1,0,[e,0]);var v=[],_=0,y=parseInt(a[1][0]-a[0][0]);(y>parseInt(a[2][0]-a[1][0])||y>parseInt(a[3][0]-a[2][0]))&&(y=y>parseInt(a[2][0]-a[1][0])?parseInt(a[2][0]-a[1][0]):parseInt(a[3][0]-a[2][0]));for(var x=0;x<a.length-1;){var m;m=(a[x][0]-t)*f;var b=s-a[x][1]*s/p;if(v.push({x:m,y:b}),x++,_<a[x][0]-y){m=(parseInt(_)+parseInt(y)-t)*f;var b=s;v.push({x:m,y:b}),m=(parseInt(a[x][0])-parseInt(y)-t)*f;var b=s;v.push({x:m,y:b})}_=a[x][0]}m=(a[a.length-1][0]-t)*f;var b=s-a[a.length-1][1]*s/p;v.push({x:m,y:b});var w=h.selectAll("path").data([1]),j=[],I=a[0][0],y=(a[a.length-1][0]-a[0][0])/10;for(x=0;x<10;x++)a[x][2]?j.push([[parseInt(I)+parseInt(x*y)],[a[x][2]]]):j.push([[parseInt(I)+parseInt(x*y)]]);var k=h.selectAll("text.day").data(j);k.enter().append("svg:text").attr("x",40).attr("y",155).attr("transform",function(e,r){return"translate("+((e[0]-t)*f+150)+",100)rotate(90)"}).text(function(t){return t[0]>1e6?parseFloat(t[0]/1e6).toFixed(2)+"M":t[0]>1e3?parseFloat(t[0]/1e3).toFixed(2)+"K":t[1]?parseInt(t[0])+" - "+(parseInt(t[0])+parseInt(t[1])):parseInt(t[0])});var O=h.selectAll("line.bottom").data(j);O.enter().insert("svg:line").attr("class","line").attr("x1",function(e){return parseInt((e[0]-t)*f)}).attr("y1",130).attr("x2",function(e){return parseInt((e[0]-t)*f)}).attr("y2",140).attr("stroke",function(){return"black"}),w.enter().append("svg:path").attr("width",200).attr("height",200).attr("class","path").attr("stroke",function(){return"steelblue"}).attr("stroke-width",function(){return"1px"}).attr("fill",function(){return n}).attr("d",u(v))}else this._clear(r)}else alert("Reference not set: use instance.setReference")},_clear:function(t){jQuery("#"+t+"_wigFeaturePainter-holder").html("")},_setDataSource:function(t){this.opt.dataSet=t},_addSimpleClickTrigger:function(){var t=this;this._container.find("span").click(function(e){var r=jQuery(e.target).text(),n={selected:r};t.trigger("onClick",n)})}},{myself:void 0});var o=t("biojs-events");o.mixin(n.prototype)},{"biojs-events":4,"js-class":5,"js-extend":6}],2:[function(e,r,n){!function(){function e(){return{keys:Object.keys||function(t){if("object"!=typeof t&&"function"!=typeof t||null===t)throw new TypeError("keys() called on a non-object");var e,r=[];for(e in t)t.hasOwnProperty(e)&&(r[r.length]=e);return r},uniqueId:function(t){var e=++p+"";return t?t+e:e},has:function(t,e){return s.call(t,e)},each:function(t,e,r){if(null!=t)if(a&&t.forEach===a)t.forEach(e,r);else if(t.length===+t.length)for(var n=0,i=t.length;n<i;n++)e.call(r,t[n],n,t);else for(var o in t)this.has(t,o)&&e.call(r,t[o],o,t)},once:function(t){var e,r=!1;return function(){return r?e:(r=!0,e=t.apply(this,arguments),t=null,e)}}}}var i,o=this,a=Array.prototype.forEach,s=Object.prototype.hasOwnProperty,l=Array.prototype.slice,p=0,c=e();i={on:function(t,e,r){if(!h(this,"on",t,[e,r])||!e)return this;this._events||(this._events={});var n=this._events[t]||(this._events[t]=[]);return n.push({callback:e,context:r,ctx:r||this}),this},once:function(t,e,r){if(!h(this,"once",t,[e,r])||!e)return this;var n=this,i=c.once(function(){n.off(t,i),e.apply(this,arguments)});return i._callback=e,this.on(t,i,r)},off:function(t,e,r){var n,i,o,a,s,l,p,f;if(!this._events||!h(this,"off",t,[e,r]))return this;if(!t&&!e&&!r)return this._events={},this;for(a=t?[t]:c.keys(this._events),s=0,l=a.length;s<l;s++)if(t=a[s],o=this._events[t]){if(this._events[t]=n=[],e||r)for(p=0,f=o.length;p<f;p++)i=o[p],(e&&e!==i.callback&&e!==i.callback._callback||r&&r!==i.context)&&n.push(i);n.length||delete this._events[t]}return this},trigger:function(t){if(!this._events)return this;var e=l.call(arguments,1);if(!h(this,"trigger",t,e))return this;var r=this._events[t],n=this._events.all;return r&&u(r,e),n&&u(n,arguments),this},stopListening:function(t,e,r){var n=this._listeners;if(!n)return this;var i=!e&&!r;"object"==typeof e&&(r=this),t&&((n={})[t._listenerId]=t);for(var o in n)n[o].off(e,r,this),i&&delete this._listeners[o];return this}};var f=/\s+/,h=function(t,e,r,n){if(!r)return!0;if("object"==typeof r){for(var i in r)t[e].apply(t,[i,r[i]].concat(n));return!1}if(f.test(r)){for(var o=r.split(f),a=0,s=o.length;a<s;a++)t[e].apply(t,[o[a]].concat(n));return!1}return!0},u=function(t,e){var r,n=-1,i=t.length,o=e[0],a=e[1],s=e[2];switch(e.length){case 0:for(;++n<i;)(r=t[n]).callback.call(r.ctx);return;case 1:for(;++n<i;)(r=t[n]).callback.call(r.ctx,o);return;case 2:for(;++n<i;)(r=t[n]).callback.call(r.ctx,o,a);return;case 3:for(;++n<i;)(r=t[n]).callback.call(r.ctx,o,a,s);return;default:for(;++n<i;)(r=t[n]).callback.apply(r.ctx,e)}},d={listenTo:"on",listenToOnce:"once"};c.each(d,function(t,e){i[e]=function(e,r,n){var i=this._listeners||(this._listeners={}),o=e._listenerId||(e._listenerId=c.uniqueId("l"));return i[o]=e,"object"==typeof r&&(n=this),e[t](r,n,this),this}}),i.bind=i.on,i.unbind=i.off,i.mixin=function(t){var e=["on","once","off","trigger","stopListening","listenTo","listenToOnce","bind","unbind"];return c.each(e,function(e){t[e]=this[e]},this),t},"undefined"!=typeof n?("undefined"!=typeof r&&r.exports&&(n=r.exports=i),n.BackboneEvents=i):"function"==typeof t&&"object"==typeof t.amd?t(function(){return i}):o.BackboneEvents=i}(this)},{}],3:[function(t,e,r){e.exports=t("./backbone-events-standalone")},{"./backbone-events-standalone":2}],4:[function(t,e,r){var n=t("backbone-events-standalone");n.onAll=function(t,e){return this.on("all",t,e),this},n.oldMixin=n.mixin,n.mixin=function(t){n.oldMixin(t);for(var e=["onAll"],r=0;r<e.length;r++){var i=e[r];t[i]=this[i]}return t},e.exports=n},{"backbone-events-standalone":3}],5:[function(t,e,r){(function(t){function r(t,e,r){for(;e&&e!==Object.prototype&&(Object.getOwnPropertyNames(e).forEach(function(r){if(".class"!=r&&!t.hasOwnProperty(r)){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n)}}),!r);)e=e.__proto__;return t}function n(t,e){for(;t;){if(t.type.prototype===e.prototype)return!0;for(var r in t["implements"]){var i=t["implements"][r],o=i[".class.meta"];if(o){if(n(o,e))return!0}else for(var a=i.prototype;a;a=a.__proto__)if(a===e.prototype)return!0}t=t.base?t.base[".class.meta"]:void 0}return!1}var i=function(t,e,r){"function"!=typeof t&&(r=e,e=t,t=Object),e||(e={}),r||(r={});var n={name:r.name,base:t,"implements":[]},o=i.clone(e);r["implements"]&&(Array.isArray(r["implements"])?r["implements"]:[r["implements"]]).forEach(function(t){"function"==typeof t&&t.prototype&&(n["implements"].push(t),i.extend(o,t.prototype))}),o.__proto__=t.prototype;var a=function(){"function"==typeof this.constructor&&this.constructor.apply(this,arguments)};return n.type=a,a.prototype=o,Object.defineProperty(a,".class.meta",{value:n,enumerable:!1,configurable:!1,writable:!1}),Object.defineProperty(o,".class",{value:a,enumerable:!1,configurable:!1,writable:!1}),r.statics&&i.extend(a,r.statics),a};i.extend=r,i.clone=function(t){return r({},t)};var o=i({constructor:function(t){this.object=t},typeOf:function(t){if(this.object instanceof t)return!0;var e=i.typeInfo(this.object);return e&&n(e,t)}});o.prototype.a=o.prototype.typeOf,o.prototype.an=o.prototype.typeOf,i.is=function(t){return new o(t)},i.typeInfo=function(t){var e=t.__proto__[".class"];return e?e[".class.meta"]:void 0},i.VERSION=[0,0,2],e?e.exports=i:t.Class=i}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],6:[function(t,e,r){(function(){var t=Array.prototype.slice,e=Array.prototype.forEach,r=function(n){if("object"!=typeof n)throw n+" is not an object";var i=t.call(arguments,1);return e.call(i,function(t){if(t)for(var e in t)"object"==typeof t[e]&&n[e]?r.call(n,n[e],t[e]):n[e]=t[e]}),n};this.extend=r}).call(this)},{}],"biojs-vis-wigexplorer":[function(t,e,r){e.exports=t("./lib/Biojs.wigExplorer")},{"./lib/Biojs.wigExplorer":1}]},{},["biojs-vis-wigexplorer"])("biojs-vis-wigexplorer")});