|
| 1 | +/*global TranslateDna: false */ |
| 2 | +/* |
| 3 | + Follwing functions require the script file "TranslateDna.js". |
| 4 | + They can be called in Google spreadsheets as user-defined functions |
| 5 | + Example Invocations as user-defined functions: |
| 6 | + =getTripletsFromDNA(A1, "|") |
| 7 | + =getAminoAcidsFromDNA(A1,"|")). |
| 8 | +
|
| 9 | +Code has been checked in JSLint |
| 10 | +*/ |
| 11 | +// Concatenate the result of breaking up the input sequence into triplets with |
| 12 | +// a user specified concatenation string and return the concatenated output. |
| 13 | +function getTripletsFromDNA(dnaSeq, concatStr) { |
| 14 | + 'use strict'; |
| 15 | + var trans = new TranslateDna(dnaSeq); |
| 16 | + return trans.getTriplets().join(concatStr); |
| 17 | +} |
| 18 | +// Return the amino acid translation of the input sequence as a concatenated string. |
| 19 | +// The array of amino acids can contain inner arrays when a given nucleotide triplet |
| 20 | +// contains ambiguous characters such as "R". These array elements are detected by |
| 21 | +// the "Array.isArray()" check and are processed separately by being concatenated with an empty |
| 22 | +// string and are converted to lower case. |
| 23 | +function getAminoAcidsFromDNA(dnaSeq, concatStr) { |
| 24 | + 'use strict'; |
| 25 | + var trans = new TranslateDna(dnaSeq), |
| 26 | + aminoAcids = trans.getAminoAcids(), |
| 27 | + elementCount = aminoAcids.length, |
| 28 | + i, |
| 29 | + mixedAminoAcids, |
| 30 | + processedAminoAcids = []; |
| 31 | + for (i = 0; i < elementCount; i += 1) { |
| 32 | + if (Array.isArray(aminoAcids[i])) { |
| 33 | + mixedAminoAcids = aminoAcids[i].join('').toLowerCase(); |
| 34 | + processedAminoAcids.push(mixedAminoAcids); |
| 35 | + } else { |
| 36 | + processedAminoAcids.push(aminoAcids[i]); |
| 37 | + } |
| 38 | + } |
| 39 | + return processedAminoAcids.join(concatStr); |
| 40 | +} |
0 commit comments