1 // The Great Computer Language Shootout 2 // http://shootout.alioth.debian.org 3 // 4 // Contributed by Ian Osgood 5 6 var last = 42, A = 3877, C = 29573, M = 139968; 7 8 function rand(max) { 9 last = (last * A + C) % M; 10 return max * last / M; 11 } 12 13 var ALU = 14 "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" + 15 "GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" + 16 "CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT" + 17 "ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA" + 18 "GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG" + 19 "AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC" + 20 "AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA"; 21 22 var IUB = { 23 a:0.27, c:0.12, g:0.12, t:0.27, 24 B:0.02, D:0.02, H:0.02, K:0.02, 25 M:0.02, N:0.02, R:0.02, S:0.02, 26 V:0.02, W:0.02, Y:0.02 27 } 28 29 var HomoSap = { 30 a: 0.3029549426680, 31 c: 0.1979883004921, 32 g: 0.1975473066391, 33 t: 0.3015094502008 34 } 35 36 function makeCumulative(table) { 37 var last = null; 38 for (var c in table) { 39 if (last) table[c] += table[last]; 40 last = c; 41 } 42 } 43 44 function fastaRepeat(n, seq) { 45 var seqi = 0, lenOut = 60; 46 while (n>0) { 47 if (n<lenOut) lenOut = n; 48 if (seqi + lenOut < seq.length) { 49 ret = seq.substring(seqi, seqi+lenOut); 50 seqi += lenOut; 51 } else { 52 var s = seq.substring(seqi); 53 seqi = lenOut - s.length; 54 ret = s + seq.substring(0, seqi); 55 } 56 n -= lenOut; 57 } 58 } 59 60 function fastaRandom(n, table) { 61 var line = new Array(60); 62 makeCumulative(table); 63 while (n>0) { 64 if (n<line.length) line = new Array(n); 65 for (var i=0; i<line.length; i++) { 66 var r = rand(1); 67 for (var c in table) { 68 if (r < table[c]) { 69 line[i] = c; 70 break; 71 } 72 } 73 } 74 ret = line.join(''); 75 n -= line.length; 76 } 77 } 78 79 var ret; 80 81 var count = 7; 82 ret = fastaRepeat(2*count*100000, ALU); 83 ret = fastaRandom(3*count*1000, IUB); 84 ret = fastaRandom(5*count*1000, HomoSap); 85 86