Team:Aberdeen Scotland/DNA/JS
From 2014.igem.org
(4 intermediate revisions not shown) | |||
Line 73: | Line 73: | ||
var dna = ""; | var dna = ""; | ||
+ | if (txt == "") { // check of string is empty | ||
+ | return dna; | ||
+ | }; | ||
+ | |||
if (separator !== "none") { | if (separator !== "none") { | ||
var re = new RegExp(separator, "g"); | var re = new RegExp(separator, "g"); | ||
Line 80: | Line 84: | ||
// add start codon | // add start codon | ||
- | dna += this.char[start]; | + | dna += this.char["start"]; |
// translate to dna | // translate to dna | ||
for (var i=0; i<txt.length; i++) { | for (var i=0; i<txt.length; i++) { | ||
if (typeof this.char[txt[i]] !== 'undefined') { | if (typeof this.char[txt[i]] !== 'undefined') { | ||
+ | if (txt[i] == ".") { // cut protein and go to next sentence | ||
+ | dna += this.char["stop"]; | ||
+ | dna += this.char[" "]; | ||
+ | dna += this.char["start"]; | ||
+ | continue; | ||
+ | }; | ||
dna += this.char[txt[i]]; | dna += this.char[txt[i]]; | ||
} | } | ||
- | } | + | } |
+ | |||
+ | //put a stop codon | ||
+ | dna += this.char["stop"]; | ||
+ | |||
+ | //return | ||
return dna; | return dna; | ||
+ | } | ||
+ | |||
+ | dna.prototype.colorBlock = function(letter) { | ||
+ | return '<div class="'+letter+'">'+letter+'</div>'; | ||
+ | } | ||
+ | |||
+ | dna.prototype.colorDNA = function(f) { | ||
+ | var txt = f.text; | ||
+ | var canvas = ""; | ||
+ | |||
+ | if (txt == "") { // check for dna | ||
+ | return canvas; | ||
+ | }; | ||
+ | |||
+ | txt = txt.toUpperCase(); | ||
+ | |||
+ | for (var i = 0; i < txt.length; i++) { | ||
+ | canvas += '<div class="'+txt[i]+'">'+txt[i]+'</div>'; | ||
+ | }; | ||
+ | |||
+ | return canvas; | ||
} | } |
Latest revision as of 21:38, 12 August 2014
function dna(f) {
this.char = new Object;
// ALPHABET
// ACCORDING TO E.COLI CODON BIAS
this.char.start = 'ATG'; this.char.stop = 'TGA';
this.char.A = "GCC"; this.char.B = "AAG"; // "BOOK" - K(2) this.char.C = "TGC"; this.char.D = "GAT";
this.char.E = "GAA"; this.char.F = "TTT"; this.char.G = "GGC"; this.char.H = "CAT";
this.char.I = "ATT"; this.char.J = "CCA"; // "JUMP" - P(2) this.char.K = "AAA"; this.char.L = "CTG";
this.char.M = "ATG"; this.char.N = "AAT"; this.char.O = "CGT"; // "ORANGE" - R(2) this.char.P = "CCG";
this.char.Q = "CAG"; this.char.R = "CGC"; this.char.S = "AGC"; this.char.T = "ACC";
this.char.U = "AGA"; // "UMBRELLA" - R(4) this.char.V = "GTG"; this.char.W = "TGG"; this.char.X = "TAC"; // "XYLOPHONE" - Y(2)
this.char.Y = "TAT"; this.char.Z = "CGA"; // "ZEBRA" - R(3)
this.char["0"] = "AGG"; // "ZERO" - R(4) this.char["1"] = "AAC"; // "ONE" - N(2) this.char["2"] = "ACG"; // "TWO" - T(2) this.char["3"] = "ACT"; // "THREE" - T(3) this.char["4"] = "TTC"; // "FOUR" - F(2)
this.char["5"] = "ATC"; // "FIVE" - I(2) this.char["6"] = "TCG"; // "SIX" - S(2) this.char["7"] = "AGT"; // "SEVEN" - S(3) this.char["8"] = "GAG"; // "EIGHT" - E(2) this.char["9"] = "ATA"; // "NINE" - I(3)
this.char[" "] = "GGT"; // GLYCINE SPACER PROTEIN this.char["."] = "TGA"; // STOP
this.nchars = 40;
this.color_codes = { A: "red", C: "green", G: "blue", T: "yellow", };
};
dna.prototype.toDNA = function(f) { var txt = f.text; var separator = typeof f.separator !== 'undefined' ? f.separator : "none"; var dna = "";
if (txt == "") { // check of string is empty return dna; };
if (separator !== "none") { var re = new RegExp(separator, "g"); txt = txt.replace(re, " "); } txt = txt.toUpperCase();
// add start codon dna += this.char["start"];
// translate to dna for (var i=0; i<txt.length; i++) { if (typeof this.char[txt[i]] !== 'undefined') { if (txt[i] == ".") { // cut protein and go to next sentence dna += this.char["stop"]; dna += this.char[" "]; dna += this.char["start"]; continue; }; dna += this.char[txt[i]]; } }
//put a stop codon dna += this.char["stop"];
//return return dna; }
dna.prototype.colorBlock = function(letter) {
return '}
dna.prototype.colorDNA = function(f) { var txt = f.text; var canvas = "";
if (txt == "") { // check for dna return canvas; };
txt = txt.toUpperCase();
for (var i = 0; i < txt.length; i++) {
canvas += '};
return canvas; }