Team:Dundee/proteins.js

From 2011.igem.org

Revision as of 09:11, 12 July 2011 by Dzgibson (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

var dnaCodonTable2 = { // TT TTT: "F", TTC: "F", TTA: "L", TTG: "L", // TC CTT: "L", CTC: "L", CTA: "L", CTG: "L", // TA ATT: "I", ATC: "I", ATA: "I", ATG: "M", // TG GTT: "V", GTC: "V", GTA: "V", GTG: "V", // CT TCT: "S", TCC: "S", TCA: "S", TCG: "S", // CC CCT: "P", CCC: "P", CCA: "P", CCG: "P", // CA ACT: "T", ACC: "T", ACA: "T", ACG: "T", // CG GCT: "A", GCC: "A", GCA: "A", GCG: "A", // AT TAT: "Y", TAC: "Y", TAA: "Stop (Ochre)", TAG: "Stop (Amber)", // AC CAT: "H", CAC: "H", CAA: "Q", CAG: "Q", // AA AAT: "N", AAC: "N", AAA: "K", AAG: "K", // AG GAT: "D", GAC: "D", GAA: "E", GAG: "E", // GT TGT: "C", TGC: "C", TGA: "Stop (Opal)", TGG: "W", // GC CGT: "R", CGC: "R", CGA: "R", CGG: "R", // GA AGT: "S", AGC: "S", AGA: "R", AGG: "R", // GG GGT: "G", GGC: "G", GGA: "G", GGG: "G" };

function getAminoChain(sequence) { // Split into codons (length == 3) var codons = sequence.match(/.{1,3}/g); // Look up against codon table and reduce to a string var aminoChain = codons.reduce(function(chain, codon) { return chain + dnaCodonTable2[codon]; }, ""); return aminoChain; }

function lookup() { var sequence = document.getElementById("sequence").value.toUpperCase().substr(sequenceFrame - 1);

/* Doesn't take framing into account // Extract genes sequence = sequence.replace(/(TAA|TAG|TGA)/g, "|"); var tempGenes = sequence.split("|"); alert(tempGenes); var genes = []; for(var i = 0; i < tempGenes.length; i++) { var index = tempGenes[i].indexOf("ATG"); if(index != -1) { genes.push(tempGenes[i].substr(index)); } }

var chains = []; // Translate codons to amino chain for(var i = 0; i < genes.length; i++) { chains.push(getAminoChain(genes[i])); } // Display results document.getElementById("dnaToProteinResults").innerHTML = ""; for(var i = 0; i < chains.length; i++) { var p = document.createElement("p"); p.innerHTML = chains[i]; document.getElementById("dnaToProteinResults").appendChild(p); } */

// Split into codons var codons = sequence.match(/.{1,3}/g);

// Replace start and end tags and reduce to string var geneStarted = false; sequence = codons.reduce(function(previousValue, currentValue) { if(currentValue == "ATG" && !geneStarted) { currentValue = "(start)"; geneStarted = true; } else if(currentValue == "TAA" || currentValue == "TAG" || currentValue == "TGA") { currentValue = "(end)"; geneStarted = false; } return previousValue += currentValue; }, "");

// Identify start and end and replace (start) with ATG var genes = sequence.match(/\(start\)[ACTG]+\(end\)/g); genes = genes.map(function(gene) { return gene.replace(/\(start\)([GATC]+)\(end\)/, "ATG$1"); });

var chains = []; // Translate codons to amino chain for(var i = 0; i < genes.length; i++) { chains.push(getAminoChain(genes[i])); } // Display results document.getElementById("dnaToProteinResults").innerHTML = ""; for(var i = 0; i < chains.length; i++) { var p = document.createElement("p"); p.innerHTML = i + 1 + ": " + chains[i]; document.getElementById("dnaToProteinResults").appendChild(p); } }