UNPKG

biojs-rest-ensembl

Version:
1 lines 5.87 kB
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){if(typeof biojs==="undefined"){module.exports=biojs={}}if(typeof biojs.rest==="undefined"){module.exports=biojs.rest={}}biojs.rest.ensembl=require("./")},{"./":2}],2:[function(require,module,exports){module.exports=require("./rest")},{"./rest":7}],3:[function(require,module,exports){var req=require("request");module.exports=Nets;function Nets(uri,opts,cb){req(uri,opts,cb)}},{request:4}],4:[function(require,module,exports){var window=require("global/window");var once=require("once");var messages={0:"Internal XMLHttpRequest Error",4:"4xx Client Error",5:"5xx Server Error"};var XHR=window.XMLHttpRequest||noop;var XDR="withCredentials"in new XHR?XHR:window.XDomainRequest;module.exports=createXHR;function createXHR(options,callback){if(typeof options==="string"){options={uri:options}}options=options||{};callback=once(callback);var xhr=options.xhr||null;if(!xhr){if(options.cors||options.useXDR){xhr=new XDR}else{xhr=new XHR}}var uri=xhr.url=options.uri||options.url;var method=xhr.method=options.method||"GET";var body=options.body||options.data;var headers=xhr.headers=options.headers||{};var sync=!!options.sync;var isJson=false;var key;if("json"in options){isJson=true;headers["Accept"]="application/json";if(method!=="GET"&&method!=="HEAD"){headers["Content-Type"]="application/json";body=JSON.stringify(options.json)}}xhr.onreadystatechange=readystatechange;xhr.onload=load;xhr.onerror=error;xhr.onprogress=function(){};xhr.ontimeout=noop;xhr.open(method,uri,!sync);if(options.withCredentials||options.cors&&options.withCredentials!==false){xhr.withCredentials=true}if(!sync){xhr.timeout="timeout"in options?options.timeout:5e3}if(xhr.setRequestHeader){for(key in headers){if(headers.hasOwnProperty(key)){xhr.setRequestHeader(key,headers[key])}}}else if(options.headers){throw new Error("Headers cannot be set on an XDomainRequest object")}if("responseType"in options){xhr.responseType=options.responseType}if("beforeSend"in options&&typeof options.beforeSend==="function"){options.beforeSend(xhr)}xhr.send(body);return xhr;function readystatechange(){if(xhr.readyState===4){load()}}function load(){var error=null;var status=xhr.statusCode=xhr.status;var body=null;if(xhr.response){body=xhr.body=xhr.response}else if(xhr.responseType==="text"||!xhr.responseType){body=xhr.body=xhr.responseText||xhr.responseXML}if(status===1223){status=204}if(status===0||status>=400&&status<600){var message=(typeof body==="string"?body:false)||messages[String(status).charAt(0)];error=new Error(message);error.statusCode=status}xhr.status=xhr.statusCode=status;if(isJson){try{body=xhr.body=JSON.parse(body)}catch(e){}}callback(error,xhr,body)}function error(evt){callback(evt,xhr)}}function noop(){}},{"global/window":5,once:6}],5:[function(require,module,exports){(function(global){if(typeof window!=="undefined"){module.exports=window}else if(typeof global!=="undefined"){module.exports=global}else{module.exports={}}}).call(this,typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{}],6:[function(require,module,exports){module.exports=once;once.proto=once(function(){Object.defineProperty(Function.prototype,"once",{value:function(){return once(this)},configurable:true})});function once(fn){var called=false;return function(){if(called)return;called=true;return fn.apply(this,arguments)}}},{}],7:[function(require,module,exports){var xhr=require("nets");var eRest=function(){var prefix="http://beta.rest.ensembl.org";var prefix_region=prefix+"/feature/region/";var prefix_ensgene=prefix+"/lookup/id/";var prefix_xref=prefix+"/xrefs/symbol/";var prefix_homologues=prefix+"/homology/id/";var prefix_chr_info=prefix+"/assembly/info/";var prefix_aln_region=prefix+"/alignment/block/region/";var prefix_gene_tree=prefix+"/genetree/id/";var connections=0;var eRest=function(){};eRest.limits={region:5e6};eRest.localREST=function(){prefix="http://127.0.0.1:3000";prefix_region=prefix+"/feature/region/";prefix_ensgene=prefix+"/lookup/id/";prefix_xref=prefix+"/xrefs/symbol/";prefix_homologues=prefix+"/homology/id/";return eRest};eRest.call=function(obj){var url=obj.url;var on_success=obj.success;var on_error=obj.error;connections++;xhr({uri:url,method:"GET",json:true},function(error,xhrc,resp){connections--;if(error!==null&&on_error!==undefined){on_error(error)}else if(resp!==undefined){if(resp.error!==undefined){on_error(resp.error)}else if(on_success!==undefined){on_success(resp)}}})};eRest.url={};eRest.url.region=function(obj){return prefix_region+obj.species+"/"+obj.chr+":"+obj.from+"-"+obj.to+".json?feature=gene"};eRest.url.xref=function(obj){return prefix_xref+obj.species+"/"+obj.name+".json?object_type=gene"};eRest.url.homologues=function(obj){return prefix_homologues+obj.id+".json?format=condensed;sequence=none;type=all"};eRest.url.gene=function(obj){return prefix_ensgene+obj.id+".json?format=full"};eRest.url.chr_info=function(obj){return prefix_chr_info+obj.species+"/"+obj.chr+".json?format=full"};eRest.url.aln_block=function(obj){var url=prefix_aln_region+obj.species+"/"+obj.chr+":"+obj.from+"-"+obj.to+".json?method="+obj.method;for(var i=0;i<obj.species_set.length;i++){url+="&species_set="+obj.species_set[i]}return url};eRest.url.gene_tree=function(obj){return prefix_gene_tree+obj.id+".json?sequence="+(obj.sequence||obj.aligned?1:"none")+(obj.aligned?"&aligned=1":"")};eRest.connections=function(){return connections};return eRest};module.exports=eRest},{nets:3}]},{},[1]);