The Computer Language
Benchmarks Game

k-nucleotide F# .NET Core program

source code

(* The Computer Language Benchmarks Game
 * http://benchmarksgame.alioth.debian.org/
 *
 * contributed by Jimmy Tang
 *)
open System
open System.IO
open System.Collections.Generic

// make our hashtable using System.Collections.Generic.Dictionary
let maketable (dna:string) (length:int) =
   let d = new Dictionary<_,_>()
   for start in 0..(dna.Length - length) do
      let substr = dna.Substring(start, length)
      let x = ref (ref 0)
      if d.TryGetValue(substr, x) then x.Value := ! !x + 1
      else d.[substr] <- ref 1
   d

// frequency for all substrings of a given length
let frequencies (dna:string) (length:int) = [
   let d = maketable dna length
   let total = d.Values |> Seq.map (!) |> Seq.sum
   yield! [ for pair in d ->
             pair.Key.ToUpper(), (float(pair.Value.Value) * 100.0 /float(total))]
         |> List.sortBy (snd >> (~-))
         |> List.map (fun (s,c) -> sprintf "%s %.3f" s c)
   yield ""
]

// frequency of occurrence for a particular substring
let countSubstring dna (substring:string) = [
   let d = maketable dna (substring.Length)
   yield (sprintf "%d\t%s"
      (if d.ContainsKey(substring) then !d.[substring] else 0)
      (substring.ToUpper()))
]

let input = Console.In
let dna = seq { while true do yield input.ReadLine() }
        |> Seq.takeWhile (fun x -> x <> null)
        |> Seq.skipWhile (fun x -> not(x.StartsWith(">THREE")))
        |> Seq.skip 1
        |> String.concat ""

[for len in [1;2] -> async { return frequencies dna len }] @
[for str in ["ggt";"ggta";"ggtatt";"ggtattttaatt";"ggtattttaatttatagt"]
 -> async { return countSubstring dna str }]
|> List.rev
|> Async.Parallel
|> Async.RunSynchronously
|> Array.rev
|> Seq.concat
|> Seq.iter (printfn "%s")
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
2.0.0-preview1-005977
"System.GC.Server": true


Fri, 09 Jun 2017 16:28:43 GMT

MAKE:
cp knucleotide.fsharpcore Program.fs
cp Include/fsharpcore/tmp.fsproj .
cp Include/fsharpcore/runtimeconfig.template.json .
mkdir obj
cp Include/fsharpcore/project.assets.json ./obj
cp Include/fsharpcore/tmp.fsproj.nuget.g.props ./obj
cp Include/fsharpcore/tmp.fsproj.nuget.g.targets ./obj
/usr/bin/dotnet build -c Release
Microsoft (R) Build Engine version 15.3.117.23532
Copyright (C) Microsoft Corporation. All rights reserved.

/home/dunham/.nuget/packages/fsharp.net.sdk/1.0.5/build/FSharp.NET.Core.Sdk.targets(170,9): error MSB6006: "dotnet" exited with code 131. [/home/dunham/benchmarksgame_quadcore/knucleotide/tmp/tmp.fsproj]

Build FAILED.

/home/dunham/.nuget/packages/fsharp.net.sdk/1.0.5/build/FSharp.NET.Core.Sdk.targets(170,9): error MSB6006: "dotnet" exited with code 131. [/home/dunham/benchmarksgame_quadcore/knucleotide/tmp/tmp.fsproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:02.98
/home/dunham/benchmarksgame/nanobench/makefiles/u64q.programs.Makefile:189: recipe for target 'knucleotide.fsharpcore_run' failed
make: [knucleotide.fsharpcore_run] Error 1 (ignored)

3.60s to complete and log all make actions

COMMAND LINE:
/usr/bin/dotnet ./bin/Release/netcoreapp2.0/tmp.dll 0 < knucleotide-input250000.txt

PROGRAM FAILED 


PROGRAM OUTPUT:

No executable found matching command "dotnet-./bin/Release/netcoreapp2.0/tmp.dll"