Results 1 to 5 of 5

Thread: Making a table?

  1. #1
    Join Date
    Apr 2012

    Making a table?

    Hi, i'm trying to built a results table from user input, and I'm not sure where to start.
    User input read from a form is something like this: ataaacccgtgcctgccgata

    This is taken to codes.js file which contains:
    function getGeneticCodeString (type) {
    	if ((type.toLowerCase() == "standard") || (type.toLowerCase() == "transl_table=1")) {
    	    return "/gca|gcc|gcg|gct/=A," +   // This codes for Alanine and accepts codons: GCA, GCC, GCG, GCT,
    	    "/tgc|tgt/=C," +                   // This codes for Cysteine and accepts codons: TGC, TGT
    	    "/gat|gac/=D," +                      // This codes for Aspartate and accepts codons: GAT, GAC
    	    "/gaa|gag/=E," +                       // This codes for Glutamate and accepts codons: GAA, GAG
    	    "/ttt|ttc/=F," +                // This codes for Phenylalanine and accepts codons: TTT, TTC,
    	    "/gga|ggc|ggt|ggg/=G," +          // This codes for Glycine and accepts codons: GGA, GGC, GGG, GGT,
    	    "/cat|cac/=H," +                      // This codes for Histidine and accepts codons: CAT, CAC
    	    "/ata|att|atc/=I," +               // This codes for Isoleucine and accepts codons: ATA, ATT, ATC
    	    "/aaa|aag/=K," +                       //This codes for Lysine and accepts codons: AAA, AAG
    	    "/tta|ttg|ctt|ctc|cta|ctg/=L," + // This codes for Leucine and accepts codons: TTA, TTG, CTT, CTC, CTA, CTG
    	    "/atg/=M," +                   // This codes for Methioine and accepts codons: ATG
    	    "/aat|aac/=N," +                     // This codes for Asparagine and accepts codons: AAT,  AAC
    	    "/cca|ccc|ccg|cct/=P," +             // This codes for Proline and accepts codons: CCA, CCC, CCG, CCT,
    	    "/caa|cag/=Q," +                    // This codes for Glutamine and accepts codons: CAA, CAG
    The above code translates user input into wanted results.

    This is what I need, and I have no code or idea how to do that:
    I need a table, which reads how many times each codon (ata, aac,ccg, etc.) occur, and calculate what is the percentage of the codon occuring in user input.

    So far I have this:
    function CodonTable() {
    	this.a = new AminoAcid("Ala");
    	this.c = new AminoAcid("Cys");
    	this.d = new AminoAcid("Asp");
    	this.e = new AminoAcid("Glu");
    	this.f = new AminoAcid("Phe");
    	this.g = new AminoAcid("Gly");...
    	this.ala = this.a;
    	this.cys = this.c;
    	this.asp = this.d;
    	this.glu = this.e;
    	this.phe = this.f;
    	this.gly = this.g;   ...
            this.aminoAcids = new Array(this.a, this.c, this.d, this.e, this.f, this.g);
    Thank you.

  2. #2
    Join Date
    Feb 2012

    You have three character codes that can be used as indicies of an array and then used to count(intrinsic) how many of each index-type.

    It is best to initialize the array, which in this case is Codes, using the character string meta-description. e.g. Codes['ttc']=0;

    <script type="text/javascript">
    var Codes=new Array(0);
    function addCode(anotherCode){
    var x=Codes[anotherCode]; 
    { Codes[anotherCode]+=1 ;}
    else {Codes['error']+=1 ;}
    var aCode='ccc';
    You can note that in the current versions of javascript Codes['error'] is never incremented, so dont count on counting errors!

  3. #3
    Join Date
    Oct 2010
    Versailles, France
    What is the question ?
    User input : ataaacccgtgcctgccgata
    Wished output ???

    At first, it's possible to walk along the string with a loop
    function getGeneticCodeString (type) {var t=type.toLowerCase(),codon;
       for (i=0;i<t.length;i+=3) {codon=t.substr(i,3);
          alert(codon);// work with codon
    Then it's probably useful to use arrays (or objects for non numerical indexes) to replace codon (with regular expressions to use the function test()), with upper case letters or abbreviations.
    var rgx="/gca|gcc|gcg|gct/,/tgc|tgt/,... ,/caa|cag/".split(',');
    var letters="A,C,... ,Q".split(',');
    var shortCut="Ala,Cys,... ,Glu".split(',');
    // Variant with objects
    var objShort={A:"Ala",C:"Cyr",... Q:"Glu"}

  4. #4
    Join Date
    Apr 2012
    Sorry, the wisheed output is:
    Input: ataaacccgtgcctgccgata

    Results for 21 residue sequence, 7 codons, sequence starting "ataaacc.."

    AmAcid Codon Number /1000 Fraction ..

    Ala ata 2.00 12.32 0.43
    Ala aac 1.00 20.13 0.33
    Ala ccg 2.00 33.56 0.56
    Ala tgc 1.00 6.71 0.11

    Cys ctg 1.00 1.27 0.86
    Cys act 0.00 0.00 0.00
    Asp ggg 0.00 0.00 0.00
    Asp gac 0.00 0.00 0.00

    First two columns are fixed each has 64 rows, followed by Number column, which reads how many times each codon occurrs in the user input, last two are remaining untouched at the moment.

  5. #5
    Join Date
    Oct 2010
    Versailles, France
    Try to work with this kind of objects...
    <script type="text/javascript">
    // An object to use like this : aminoAcid[letter].substr(0,3) (for the shortcut) or aminoAcid[letter].substr(4) (for the full name)
    // Variant aminoAcid.A.substr(0,3) (for the shortcut) or aminoAcid.A.substr(4) (for the full name)
    var aminoAcid={A:"Ala Alamine",C:"Cys Cysterine",D:"Asp Aspartate",E:"Gln Glutamate",F:"Phe Phenylalanine",G:"Gly Glycine",H:"His Histidine",I:"Ile Isoleucine",K:"Lys Lysine",L:"Leu Leucine",M:"Met Methioine",N:"Asn Asparagine",P:"Pro Proline",Q:"Glu Glutamine"};
    // To define an object GeneticCodes key:codon => value: aminoAcid iupacNotation
    var arr="gca|gcc|gcg|gct,A,tgc|tgt,C,gat|gac,D,gaa|gag,E,ttt|ttc,F,gga|ggc|ggt|ggg,G,cat|cac,H,ata|att|atc,I,aaa|aag,K,tta|ttg|ctt|ctc|cta|ctg,L,atg,M,aat|aac,N,cca|ccc|ccg|cct,P,caa|cag,Q".split(',');
    var i,j,cod,cods,GeneticCodes={};
    for (i=0;i<arr.length;i+=2) {cod=arr[i];let=arr[i+1];
    	if(/|/.test(cod)) {cods=cod.split('|');
    		for (j=0;j<cods.length;j++) GeneticCodes[cods[j]]=let;}
    	else GeneticCodes[cod]=let;}
    // Then a value val='gca' give the var let=GeneticCodes[val]; and aminoAcid[let].substr(0,3) (for the shortcut) or aminoAcid[let].substr(4) (for the full name) 
    I do not understand really your problem...
    Last edited by 007Julien; 04-13-2012 at 06:09 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles