-
Notifications
You must be signed in to change notification settings - Fork 5
/
bionode-seq.min.js
1 lines (1 loc) · 9 KB
/
bionode-seq.min.js
1
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);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.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){module.exports=require("./lib/bionode-seq")},{"./lib/bionode-seq":2}],2:[function(require,module,exports){var seq=module.exports;var _baseMatrix={A:"T",C:"G",W:"S",M:"K",R:"Y",B:"V",D:"H"};var _dnaComplementBasesMatrix=Object.create(_baseMatrix);var _rnaComplementBasesMatrix=Object.create(_baseMatrix);var _transcribeBasesMatrix=Object.create(_baseMatrix);var _translateCodonsMatrix={GCU:"A",GCC:"A",GCA:"A",GCG:"A",CGU:"R",CGC:"R",CGA:"R",CGG:"R",AGA:"R",AGG:"R",AAU:"N",AAC:"N",GAU:"D",GAC:"D",UGU:"C",UGC:"C",CAA:"Q",CAG:"Q",GAA:"E",GAG:"E",GGU:"G",GGC:"G",GGA:"G",GGG:"G",CAU:"H",CAC:"H",AUU:"I",AUC:"I",AUA:"I",UUA:"L",UUG:"L",CUU:"L",CUC:"L",CUA:"L",CUG:"L",AAA:"K",AAG:"K",AUG:"M",UUU:"F",UUC:"F",CCU:"P",CCC:"P",CCA:"P",CCG:"P",UCU:"S",UCC:"S",UCA:"S",UCG:"S",AGU:"S",AGC:"S",ACU:"T",ACC:"T",ACA:"T",ACG:"T",UGG:"W",UAU:"Y",UAC:"Y",GUU:"V",GUC:"V",GUA:"V",GUG:"V",UAA:"*",UGA:"*",UAG:"*",XAA:"X",XAC:"X",XAG:"X",XAU:"X",XCA:"X",XCC:"X",XCG:"X",XCU:"X",XGA:"X",XGC:"X",XGG:"X",XGU:"X",XUA:"X",XUC:"X",XUG:"X",XUU:"X",XAX:"X",XCX:"X",XGX:"X",XUX:"X",XXA:"X",XXC:"X",XXG:"X",XXU:"X",XXX:"X",gcu:"a",gcc:"a",gca:"a",gcg:"a",cgu:"r",cgc:"r",cga:"r",cgg:"r",aga:"r",agg:"r",aau:"n",aac:"n",gau:"d",gac:"d",ugu:"c",ugc:"c",caa:"q",cag:"q",gaa:"e",gag:"e",ggu:"g",ggc:"g",gga:"g",ggg:"g",cau:"h",cac:"h",auu:"i",auc:"i",aua:"i",uua:"l",uug:"l",cuu:"l",cuc:"l",cua:"l",cug:"l",aaa:"k",aag:"k",aug:"m",uuu:"f",uuc:"f",ccu:"p",ccc:"p",cca:"p",ccg:"p",ucu:"s",ucc:"s",uca:"s",ucg:"s",agu:"s",agc:"s",acu:"t",acc:"t",aca:"t",acg:"t",ugg:"w",uau:"y",uac:"y",guu:"v",guc:"v",gua:"v",gug:"v",uaa:"*",uga:"*",uag:"*",xaa:"x",xac:"x",xag:"x",xau:"x",xca:"x",xcc:"x",xcg:"x",xcu:"x",xga:"x",xgc:"x",xgg:"x",xgu:"x",xua:"x",xuc:"x",xug:"x",xuu:"x",xax:"x",xcx:"x",xgx:"x",xux:"x",xxa:"x",xxc:"x",xxg:"x",xxu:"x",xxx:"x"};_rnaComplementBasesMatrix["A"]="U";delete _rnaComplementBasesMatrix["T"];_transcribeBasesMatrix["A"]="U";mirrorAndLowerCaseMatrices([_dnaComplementBasesMatrix,_rnaComplementBasesMatrix,_transcribeBasesMatrix]);_transcribeBasesMatrix["T"]="A";_transcribeBasesMatrix["t"]="a";function mirrorAndLowerCaseMatrices(matricesArray){matricesArray.forEach(function(matrix){for(var k in matrix){var v=matrix[k];matrix[k.toLowerCase()]=v.toLowerCase();matrix[v]=k;matrix[v.toLowerCase()]=k.toLowerCase()}})}seq.checkType=function(sequence,threshold,length,index){if(threshold===undefined){threshold=.9}if(length===undefined){length=1e4}if(index===undefined){index=1}var seq=sequence.slice(index-1,length);var dnaSeq=seq.replace(/N/gi,"");var dnaTotal=dnaSeq.length;var acgMatch=(dnaSeq.match(/[ACG]/gi)||[]).length/dnaTotal;var tMatch=(dnaSeq.match(/[T]/gi)||[]).length/dnaTotal;var uMatch=(dnaSeq.match(/[U]/gi)||[]).length/dnaTotal;var proteinSeq=seq.replace(/X/gi,"");var proteinTotal=proteinSeq.length;var proteinMatch=(seq.match(/[ARNDCQEGHILKMFPSTWYV\*]/gi)||[]).length/proteinTotal;if(acgMatch+tMatch>=threshold||acgMatch+uMatch>=threshold){if(tMatch>=uMatch){return"dna"}else if(uMatch>=tMatch){return"rna"}else{return"dna"}}else if(proteinMatch>=threshold){return"protein"}};seq.createComplementBase=function(sequenceType){var complementBasesMatrix=sequenceType==="rna"||sequenceType==="ambiguousRna"?_rnaComplementBasesMatrix:_dnaComplementBasesMatrix;var getComplementBase=function(base){var complement=complementBasesMatrix[base];return complement||base};return getComplementBase};seq.reverse=function(sequence){return sequence.split("").reverse().join("")};seq.complement=function(sequence,reverse){var reverse=reverse||false;var sequenceType=seq.checkType(sequence);var getComplementBase=seq.createComplementBase(sequenceType);if(reverse){return sequence.split("").reverse().map(getComplementBase).join("")}else{return sequence.split("").map(getComplementBase).join("")}};seq.reverseComplement=function(sequence){return seq.complement(sequence,true)};seq.getTranscribedBase=function(base){return _transcribeBasesMatrix[base]||base};seq.getTranslatedAA=function(codon){return _translateCodonsMatrix[codon]};seq.removeIntrons=function(sequence,exonsRanges){var sequenceWithoutIntrons="";var exonsRangesSorted=exonsRanges.sort(function(a,b){return a[0]-b[0]});exonsRangesSorted.forEach(function(exonRange){sequenceWithoutIntrons+=sequence.substring(exonRange[0],exonRange[1])});return sequenceWithoutIntrons};seq.transcribe=function(sequence,exonsRanges){if(exonsRanges){var sequenceWithoutIntrons=seq.removeIntrons(sequence,exonsRanges);sequence=sequenceWithoutIntrons}var sequenceType=seq.checkType(sequence);if(sequenceType==="dna"||sequenceType==="ambiguousDna"){return sequence.replace(/t/g,"u").replace(/T/g,"U")}else if(sequenceType==="rna"||sequenceType==="ambiguousRna"){return sequence.replace(/u/g,"t").replace(/U/g,"T")}};seq.translate=function(sequence,exonsRanges){if(exonsRanges){var sequenceWithoutIntrons=seq.removeIntrons(sequence,exonsRanges);sequence=sequenceWithoutIntrons}var sequenceType=seq.checkType(sequence);var rna;if(sequenceType==="protein"){return sequence}else if(sequenceType==="dna"||sequenceType==="ambiguousDna"){if(sequenceType==="ambiguousDna")sequence.replace(/[wsmkrybdhv]/g,"x").replace(/[WSMKRYBDHV]/g,"X");rna=seq.transcribe(sequence,exonsRanges)}else if(sequenceType==="rna"||sequenceType==="ambiguousRna"){if(sequenceType==="ambiguousRna")sequence.replace(/[wsmkrybdhv]/g,"x").replace(/[WSMKRYBDHV]/g,"X");rna=sequence}return rna.match(/.{1,3}/g).map(seq.getTranslatedAA).join("")};seq.reverseExons=function(exonsRanges,referenceLength){var reversedExonsRanges=[];exonsRanges.forEach(function(exonRange){var start=referenceLength-exonRange[1];var stop=referenceLength-exonRange[0];reversedExonsRanges.push([start,stop])});return reversedExonsRanges};seq.findNonCanonicalSplices=function(sequence,exonsRanges){var nonCanonicalSplices=[];var exonsRangesSorted=exonsRanges.sort(function(a,b){return a[0]-b[0]});exonsRangesSorted.forEach(checkNonCanonicalIntron);function checkNonCanonicalIntron(exonRange,i){var donor=exonRange;var acceptor=exonsRangesSorted[i+1];if(!acceptor)return null;var intronRange=[donor[1],acceptor[0]];var intronStartBases=sequence.slice(intronRange[0],intronRange[0]+2).toLowerCase().replace("t","u");var intronStopBases=sequence.slice(intronRange[1]-2,intronRange[1]).toLowerCase();if(intronStartBases!=="gu")nonCanonicalSplices.push(intronRange[0]);if(intronStopBases!=="ag")nonCanonicalSplices.push(intronRange[1])}return nonCanonicalSplices};seq.checkCanonicalTranslationStartSite=function(sequence){return sequence.substring(0,3).toLowerCase().replace("t","u")==="aug"};seq.getReadingFrames=function(sequence){var reverse=seq.reverseComplement(sequence);return[sequence,sequence.substring(1),sequence.substring(2),reverse,reverse.substring(1),reverse.substring(2)]};seq.getOpenReadingFrames=function(sequence){var sequenceType=seq.checkType(sequence);var stopCodons;if(sequenceType==="dna"||sequenceType==="ambiguousDna"){stopCodons=["TAA","TGA","TAG","taa","tga","tag"]}else if(sequenceType==="rna"||sequenceType==="ambiguousRna"){stopCodons=["UAA","UGA","UAG","uaa","uga","uag"]}var openReadingFrames=[];var openReadingFrame="";sequence.match(/.{1,3}/g).forEach(function(codon){openReadingFrame+=codon;if(stopCodons.indexOf(codon)!==-1&&openReadingFrame.length>0){openReadingFrames.push(openReadingFrame);openReadingFrame=""}});openReadingFrames.push(openReadingFrame);return openReadingFrames};seq.getAllOpenReadingFrames=function(sequence){var readingFrames=seq.getReadingFrames(sequence);var allOpenReadingFrames=readingFrames.map(seq.getOpenReadingFrames);return allOpenReadingFrames};seq.findLongestOpenReadingFrame=function(sequence,frameSymbol){var frameSymbols=["+1","+2","+3","-1","-2","-3"];if(frameSymbol){var framePosition=frameSymbols.indexOf(frameSymbol);var readingFrame=seq.getReadingFrames(sequence)[framePosition];var openReadingFrames=seq.getOpenReadingFrames(readingFrame);var longestOpenReadingFrame=getLongestOpenReadingFrame(openReadingFrames);return longestOpenReadingFrame}else{var longestOpenReadingFrames=seq.getAllOpenReadingFrames(sequence).map(getLongestOpenReadingFrame);var longestOpenReadingFrame=getLongestOpenReadingFrame(longestOpenReadingFrames.slice());var framePosition=longestOpenReadingFrames.indexOf(longestOpenReadingFrame);var frameSymbol=frameSymbols[framePosition];return[longestOpenReadingFrame,frameSymbol]}function sortReadingFrames(a,b){var aSort=a.length;var bSort=b.length;if(bSort-aSort===0){var aStartCodon=a.slice(0,3).toUpperCase().replace("T","U");var bStartCodon=b.slice(0,3).toUpperCase().replace("T","U");if(aStartCodon==="AUG"){aSort++}if(bStartCodon==="AUG"){bSort++}}return bSort-aSort}function getLongestOpenReadingFrame(array){return array.sort(sortReadingFrames)[0]}}},{}]},{},[1]);