1 # The Computer Language Shootout
\r
2 # http://shootout.alioth.debian.org/
\r
3 # Contributed by Sokolov Yura
\r
6 def gen_random (max,im=139968,ia=3877,ic=29573)
\r
7 (max * ($last = ($last * ia + ic) % im)) / im
\r
11 "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG"+
\r
12 "GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA"+
\r
13 "CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT"+
\r
14 "ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA"+
\r
15 "GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG"+
\r
16 "AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC"+
\r
17 "AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA"
\r
38 ["a", 0.3029549426680],
\r
39 ["c", 0.1979883004921],
\r
40 ["g", 0.1975473066391],
\r
41 ["t", 0.3015094502008],
\r
44 def make_repeat_fasta(id, desc, src, n)
\r
45 puts ">#{id} #{desc}"
\r
49 s = src * ((n / l) + 1)
\r
51 puts(s.scan(/.{1,#{width}}/).join("\n"))
\r
54 def make_random_fasta(id, desc, table, n)
\r
55 puts ">#{id} #{desc}"
\r
60 table.each{|v| v[1]= (prob += v[1])}
\r
61 for i in 1..(n/width)
\r
62 puts((1..width).collect{
\r
63 rand = gen_random(1.0)
\r
64 table.find{|v| v[1]>rand}[0]
\r
68 puts((1..(n%width)).collect{
\r
69 rand = gen_random(1.0)
\r
70 table.find{|v| v[1]>rand}[0]
\r
76 n = (ARGV[0] or 250_000).to_i
\r
78 make_repeat_fasta('ONE', 'Homo sapiens alu', alu, n*2)
\r
79 make_random_fasta('TWO', 'IUB ambiguity codes', iub, n*3)
\r
80 make_random_fasta('THREE', 'Homo sapiens frequency', homosapiens, n*5)
\r