Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
BioinformnaticsFrequentWords
let frequentWords (text:string) (k:int) =
let patternCounts =
text
|> Seq.windowed k
|> Seq.map(fun c -> new string(c))
|> Seq.countBy(fun s -> s)
|> Seq.sortByDescending(fun (s,c) -> c)
let maxCount = patternCounts |> Seq.head |> snd
patternCounts
|> Seq.filter(fun (s,c) -> c = maxCount)
|> Seq.map(fun (s,c) -> s)
let getRandomNuclotide () =
let dictionary = ["A";"C";"G";"T"]
let random = new Random()
dictionary.[random.Next(4)]
let getRandomSequence (length:int) =
let nuclotides = [ for i in 0 .. length -> getRandomNuclotide() ]
String.Join("", nuclotides)
let largerText = getRandomSequence 1000000
let currentFrequentWords = frequentWords largerText 9
currentFrequentWords
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment