The Computer Language
24.11 Benchmarks Game

k-nucleotide Toit #8 program

source code

/* The Computer Language Benchmarks game
   https://salsa.debian.org/benchmarksgame-team/benchmarksgame/

   Naive transliteration from bearophile's program
   contributed by Isaac Gouy 
*/  

import host.pipe
import io
    
seq_lines -> List :  
  lines := []
  in := pipe.stdin.in 
  while line := in.read-line :    
    if line.starts-with ">THREE" : break   
  while line := in.read-line :  
    if line.starts-with ">" : break    
    lines.add line  
  return lines
  
base_counts bases/int seq/string -> Map :  
  counts ::= {:} 
  size ::= seq.size + 1 - bases
  for i := 0; i < size; ++i: 
    nucleo := seq[i..i+bases]
    if v := counts.get nucleo : 
      counts[nucleo] += 1    
    else:
      counts[nucleo] = 1       
  return counts 
  
sorted_freq bases/int seq/string :
  kv ::= base_counts bases seq
  size ::= seq.size + 1 - bases
  items := []; kv.do: | k v | items.add [k,v]
  items.sort --in-place: | a b | a[1] < b[1] ? 1 : -1
  items.do: it[1] = 100.0 * it[1] / size
  return items
  
specific_count code/string seq/string -> int :   
  return (base_counts code.size seq).get code 
      --if-absent=: | _ | 0 
      
main args:
  lines := seq_lines
  seq := (lines.map: it.to-ascii-upper).join ""
  
  [1,2].do: | base |
    (sorted_freq base seq).do: | kv |
      print "$(kv[0]) $(%.3f kv[1])"
    print

  ["GGT", "GGTA", "GGTATT", "GGTATTTTAATT", 
      "GGTATTTTAATTTATAGT"].do: | code |
    print "$(specific_count code seq)\t$(code)"
    
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
v2.0.0-alpha.174



 Fri, 13 Dec 2024 01:53:50 GMT

MAKE:
cp -r Include/toit/.packages .
cp -r Include/toit/package.lock .
cp -r Include/toit/package.yaml .	
/opt/src/toit/bin/toit.compile -O2 --strip -o knucleotide.toit-8.toit_run knucleotide.toit-8.toit 

1.36s to complete and log all make actions

COMMAND LINE:
 ./knucleotide.toit-8.toit_run 0 < knucleotide-input25000000.txt

TIMED OUT after 3600s


PROGRAM OUTPUT:
A 30.295
T 30.151
C 19.800
G 19.754

AA 9.177
TA 9.132
AT 9.131
TT 9.091
CA 6.002
AC 6.001
AG 5.987
GA 5.984
CT 5.971
TC 5.971
GT 5.957
TG 5.956
CC 3.917
GC 3.911
CG 3.909
GG 3.902

1471758	GGT
446535	GGTA
47336	GGTATT