Skip to content

Instantly share code, notes, and snippets.

@lindenb
Created September 13, 2012 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lindenb/3716137 to your computer and use it in GitHub Desktop.
Save lindenb/3716137 to your computer and use it in GitHub Desktop.
Test Google App Script
/** class GeneticCode */
function GeneticCode(name,ncbiString)
{
this.name=name;
this.ncbiString=ncbiString;
};
/** std genetic code */
GeneticCode.STANDARD=new GeneticCode(
"standard",
"FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG"
);
GeneticCode.prototype.base2index=function(c)
{
switch(c)
{
case 'T':case 't': return 0;
case 'C':case 'c': return 1;
case 'A':case 'a': return 2;
case 'G':case 'g': return 3;
default: return -1;
}
};
GeneticCode.prototype.translate=function( b1, b2, b3)
{
if(arguments.length==1)
{
var prot="";
for(var i=0;i+2 < b1.length;i+=3)
{
prot+= this.translate(b1[i],b1[i+1],b1[i+2]);
}
return prot;
}
var base1= this.base2index(b1);
var base2= this.base2index(b2);
var base3= this.base2index(b3);
if(base1==-1 || base2==-1 || base3==-1)
{
return '?';
}
else
{
return this.ncbiString[base1*16+base2*4+base3];
}
}
function translateDna(dna)
{
return GeneticCode.STANDARD.translate(dna);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment