Skip to content

Instantly share code, notes, and snippets.

@jamessdixon
Created September 15, 2020 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamessdixon/19fc09c55c2f31ceb853aae08236a71e to your computer and use it in GitHub Desktop.
Save jamessdixon/19fc09c55c2f31ceb853aae08236a71e to your computer and use it in GitHub Desktop.
Bioinformatics: Pattern Count
let patternCount (text:string) (pattern:string) =
text
|> Seq.windowed pattern.Length
|> Seq.map(fun c -> new string(c))
|> Seq.filter(fun s -> s = pattern)
|> Seq.length
let text = "ACAACTCTGCATACTATCGGGAACTATCCT"
let pattern = "ACTAT"
patternCount text pattern
//For a larger test
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 1000000000
let functionalCounts = patternCount largerText pattern
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment