Last active
August 29, 2015 14:05
-
-
Save wilzbach/3d961da653a8fd44e68d to your computer and use it in GitHub Desktop.
Clustal example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// load the module | |
var Clustal = require("biojs-io-clustal"); | |
// console | |
var current = document.createElement('p'); | |
document.body.appendChild(current); | |
Clustal.read("http://dev.biojs-msa.org/v1/dummy/samples/p53.clustalo.clustal", function(seqs){ | |
current.innerHTML = seqs.length + " seqs have been loaded"; | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require=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}({c0FT7R:[function(require,module,exports){var Clustal,GenericReader,Seq,Str,__hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key]}function ctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=new ctor;child.__super__=parent.prototype;return child};Str=require("./strings");GenericReader=require("./generic_reader");Seq=require("./seq");module.exports=Clustal=function(_super){__extends(Clustal,_super);function Clustal(){return Clustal.__super__.constructor.apply(this,arguments)}Clustal.parse=function(text){var blockstate,k,label,line,lines,match,regex,seqCounter,seqs,sequence;seqs=[];lines=text.split("\n");if(lines[0].slice(0,6)===!"CLUSTAL"){throw new Error("Invalid CLUSTAL Header")}k=0;blockstate=1;seqCounter=0;while(k<lines.length){k++;line=lines[k];if(line==null||line.length===0){blockstate=1;continue}if(line.trim().length===0){blockstate=1;continue}else{if(Str.contains(line,"*")){continue}if(blockstate===1){seqCounter=0;blockstate=0}regex=/^(?:\s*)(\S+)(?:\s+)(\S+)(?:\s*)(\d*)(?:\s*|$)/g;match=regex.exec(line);if(match!=null){label=match[1];sequence=match[2];if(seqCounter>=seqs.length){seqs.push(new Seq(sequence,label,seqCounter))}else{seqs[seqCounter].seq+=sequence}seqCounter++}else{console.log(line)}}}return seqs};return Clustal}(GenericReader)},{"./generic_reader":3,"./seq":4,"./strings":5}],"biojs-io-clustal":[function(require,module,exports){module.exports=require("c0FT7R")},{}],3:[function(require,module,exports){var GenericReader,xhr;xhr=require("nets");module.exports=GenericReader=function(){function GenericReader(){}GenericReader.read=function(url,callback){var onret;onret=function(_this){return function(err,response,text){return _this._onRetrieval(text,callback)}}(this);return xhr(url,onret)};GenericReader._onRetrieval=function(text,callback){var rText;rText=this.parse(text);return callback(rText)};return GenericReader}()},{nets:6}],4:[function(require,module,exports){var Seq;module.exports=Seq=function(){function Seq(seq,name,id){var meta;this.seq=seq;this.name=name;this.id=id;meta={}}return Seq}()},{}],5:[function(require,module,exports){var strings;strings={contains:function(text,search){return"".indexOf.call(text,search,0)!==-1}};module.exports=strings},{}],6:[function(require,module,exports){var req=require("request");module.exports=Nets;function Nets(uri,opts,cb){req(uri,opts,cb)}},{request:7}],7:[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":8,once:9}],8:[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:{})},{}],9:[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)}}},{}]},{},[]);var Clustal=require("biojs-io-clustal");var current=document.createElement("p");document.body.appendChild(current);Clustal.read("http://dev.biojs-msa.org/v1/dummy/samples/p53.clustalo.clustal",function(seqs){current.innerHTML=seqs.length+" seqs have been loaded"}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "requirebin-sketch", | |
"version": "1.0.0", | |
"dependencies": { | |
"biojs-io-clustal": "0.0.6" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style type='text/css'>html, body { margin: 0; padding: 0; border: 0; } | |
body, html { height: 100%; width: 100%; }</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment