benchmarks_game/fasta.fz
# https://benchmarksgame-team.pages.debian.net/benchmarksgame/description/fasta.html#fasta
# this is a port of https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/fasta-java-2.html
# thus it is still rough around the edges
fasta =>
im := f64 139968
ia := f64 3877
ic := f64 29573
last := mut f64 42
line_length := 60
random(max f64) =>
last <- (last.get * ia + ic) % im
max * last.get / im
alu := ("GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" +
"GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" +
"CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT" +
"ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA" +
"GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG" +
"AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC"+
"AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA")
frequency(c String, p f64) is
iub := [
frequency("a", 0.27),
frequency("c", 0.12),
frequency("g", 0.12),
frequency("t", 0.27),
frequency("B", 0.02),
frequency("D", 0.02),
frequency("H", 0.02),
frequency("K", 0.02),
frequency("M", 0.02),
frequency("N", 0.02),
frequency("R", 0.02),
frequency("S", 0.02),
frequency("V", 0.02),
frequency("W", 0.02),
frequency("Y", 0.02)
]
homo_sapiens := [
frequency("a", 0.3029549426680),
frequency("c", 0.1979883004921),
frequency("g", 0.1975473066391),
frequency("t", 0.3015094502008)
]
make_cumulative(a array frequency) =>
a.map frequency (freq ->
cp := a.take_while(f -> !(freq.c = f.c))
.map f64 (f -> f.p)
.fold(f64.type.sum) + freq.p
frequency freq.c cp)
select_random(a array frequency) =>
r := random 1.0
for i := 0, i+1
while i < a.length
until r < a[i].p
a[i].c
else
a.last().c
random_fasta(id, desc String, a array frequency, n i32) =>
m := 0
say (">" + id + " " + desc)
(1..line_length)
.for_each(_ ->
b := (0..line_length-1)
.map String (_ -> select_random(a))
.fold(String.type.concat)
say b
)
repeat_fasta(id, desc, alu String, n i32) =>
m := 0
k := mut 0
kn := alu.byte_length
say (">" + id + " " + desc)
(1..line_length)
.for_each(_ ->
(0..line_length-1)
.for_each(_ ->
if (k.get = kn) then k <- 0
yak alu.substring(k.get, k.get+1)
k <- k.get + 1
)
say
)
homo := make_cumulative homo_sapiens
iub := make_cumulative iub
n := 2500000
repeat_fasta "ONE" "Homo sapiens alu" alu (n * 2)
random_fasta "TWO" "iub ambiguity codes" iub (n * 3)
random_fasta "THREE" "Homo sapiens frequency" homo (n * 5)