string-fasta.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <!DOCTYPE html>
  2. <head>
  3. <!--
  4. Copyright (C) 2007 Apple Inc. All rights reserved.
  5. Redistribution and use in source and binary forms, with or without
  6. modification, are permitted provided that the following conditions
  7. are met:
  8. 1. Redistributions of source code must retain the above copyright
  9. notice, this list of conditions and the following disclaimer.
  10. 2. Redistributions in binary form must reproduce the above copyright
  11. notice, this list of conditions and the following disclaimer in the
  12. documentation and/or other materials provided with the distribution.
  13. THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
  14. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
  17. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  21. OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. -->
  25. <title>SunSpider string-fasta</title>
  26. </head>
  27. <body>
  28. <h3>string-fasta</h3>
  29. <div id="console">
  30. </div>
  31. <script>
  32. var _sunSpiderStartDate = new Date();
  33. // The Great Computer Language Shootout
  34. // http://shootout.alioth.debian.org
  35. //
  36. // Contributed by Ian Osgood
  37. var last = 42, A = 3877, C = 29573, M = 139968;
  38. function rand(max) {
  39. last = (last * A + C) % M;
  40. return max * last / M;
  41. }
  42. var ALU =
  43. "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" +
  44. "GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" +
  45. "CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT" +
  46. "ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA" +
  47. "GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG" +
  48. "AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC" +
  49. "AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA";
  50. var IUB = {
  51. a:0.27, c:0.12, g:0.12, t:0.27,
  52. B:0.02, D:0.02, H:0.02, K:0.02,
  53. M:0.02, N:0.02, R:0.02, S:0.02,
  54. V:0.02, W:0.02, Y:0.02
  55. }
  56. var HomoSap = {
  57. a: 0.3029549426680,
  58. c: 0.1979883004921,
  59. g: 0.1975473066391,
  60. t: 0.3015094502008
  61. }
  62. function makeCumulative(table) {
  63. var last = null;
  64. for (var c in table) {
  65. if (last) table[c] += table[last];
  66. last = c;
  67. }
  68. }
  69. function fastaRepeat(n, seq) {
  70. var seqi = 0, lenOut = 60;
  71. while (n>0) {
  72. if (n<lenOut) lenOut = n;
  73. if (seqi + lenOut < seq.length) {
  74. ret = seq.substring(seqi, seqi+lenOut);
  75. seqi += lenOut;
  76. } else {
  77. var s = seq.substring(seqi);
  78. seqi = lenOut - s.length;
  79. ret = s + seq.substring(0, seqi);
  80. }
  81. n -= lenOut;
  82. }
  83. }
  84. function fastaRandom(n, table) {
  85. var line = new Array(60);
  86. makeCumulative(table);
  87. while (n>0) {
  88. if (n<line.length) line = new Array(n);
  89. for (var i=0; i<line.length; i++) {
  90. var r = rand(1);
  91. for (var c in table) {
  92. if (r < table[c]) {
  93. line[i] = c;
  94. break;
  95. }
  96. }
  97. }
  98. ret = line.join('');
  99. n -= line.length;
  100. }
  101. }
  102. var ret;
  103. var count = 7;
  104. ret = fastaRepeat(2*count*100000, ALU);
  105. ret = fastaRandom(3*count*1000, IUB);
  106. ret = fastaRandom(5*count*1000, HomoSap);
  107. var _sunSpiderInterval = new Date() - _sunSpiderStartDate;
  108. document.getElementById("console").innerHTML = _sunSpiderInterval;
  109. </script>
  110. </body>
  111. </html>