-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move code common used for benchmarks and tests into Utilities.jl
- Loading branch information
1 parent
481fe0d
commit c10623f
Showing
3 changed files
with
35 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Utilities | ||
|
||
using Distributions | ||
using GenomicFeatures | ||
using Random | ||
|
||
# Generate an array of n random Interval{Int} object. With sequence names | ||
# samples from seqnames, and intervals drawn to lie in [1, maxpos]. | ||
function random_intervals(seqnames::Vector{String}, maxpos::Int, n::Int) | ||
seq_dist = Categorical(length(seqnames)) | ||
strand_dist = Categorical(2) | ||
length_dist = Normal(1000, 1000) | ||
intervals = Vector{Interval{Int}}(undef, n) | ||
for i in 1:n | ||
intlen = maxpos | ||
while intlen >= maxpos || intlen <= 0 | ||
intlen = ceil(Int, rand(length_dist)) | ||
end | ||
first = rand(1:maxpos-intlen) | ||
last = first + intlen - 1 | ||
strand = rand(strand_dist) == 1 ? STRAND_POS : STRAND_NEG | ||
intervals[i] = Interval{Int}(seqnames[rand(seq_dist)], first, last, strand, i) | ||
end | ||
return intervals | ||
end | ||
|
||
function random_intervals(seqnames::Vector{String}, maxpos::Int, n::Int, seed::Int) | ||
Random.seed!(seed) | ||
return random_intervals(seqnames, maxpos, n) | ||
end | ||
|
||
end # module Utilities |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters