2
2
MotifSequenceGenerator
3
3
This module generates random sequences of motifs, under the constrain that the
4
4
sequence has some total length ℓ so that `q - δq ≤ ℓ ≤ q + δq`.
5
-
6
- The motifs are contained in a vector, and they can be *anything*.
7
- The notion of "length" is defined
8
- based on the following two functions, which must be provided for the motifs:
9
-
10
- * `limits(motif)` : Some function that given the `motif` it returns the
11
- `(start, fine)` of the the motif in the same units as `q`.
12
- Notice that this function establishes a measure of
13
- length, which simply is `fine - start`.
14
- * `translate(motif, t)` : Some function that given the `motif` it returns a *new*
15
- motif which is translated by `t` (either negative or positive), with
16
- respect to the same units as `q`.
17
-
18
5
All main functionality is given by the function [`random_sequence`](@ref).
19
6
"""
20
7
module MotifSequenceGenerator
@@ -32,22 +19,7 @@ Base.showerror(io::IO, e::DeadEndMotifs) = print(io,
32
19
" DeadEndMotifs: Couldn't find a proper sequence with $(e. tries) random tries, " *
33
20
" each with summands up to $(e. summands) (total tailcuts: $(e. tailcut) )." )
34
21
35
-
36
-
37
- """
38
- random_sequence(motifs::Vector{M}, q, limits, translate, δq = 0; kwargs...)
39
- Create a random sequence of motifs of type `M`, under the constraint that the
40
- sequence has "length" ℓ **exactly** within `q - δq ≤ ℓ ≤ q + δq`.
41
- Return the sequence itself as well as the
42
- sequence of indices of `motifs` used to create it.
43
-
44
- "length" here means an abstracted length defined by the struct `M`,
45
- based on the `limits` and `translate` functions.
46
- It does **not** refer to the amount of elements!
47
- Please see [`MotifSequenceGenerator`](@ref) for defining `limits`
48
- and `translate`.
49
-
50
- ## Description & Keywords
22
+ #= Algorithm description
51
23
The algorithm works as follows: First a random sequence of motifs is created,
52
24
so that it has length of `q - δq ≤ ℓ ≤ q - δq + maximum(motiflengths)`.
53
25
The possible tries of random sequences is set by the `tries` keyword (default `5`).
@@ -71,6 +43,34 @@ skyrockets for large `summands`!).
71
43
72
44
If after going though all these combinations of possible sequences we do not find
73
45
a proper one, an error is thrown.
46
+ =#
47
+
48
+ """
49
+ random_sequence(motifs::Vector{M}, q, limits, translate, δq = 0; kwargs...)
50
+ Create a random sequence of motifs of type `M`, under the constraint that the
51
+ sequence has "length" `ℓ` **exactly** within `q - δq ≤ ℓ ≤ q + δq`.
52
+ Return the sequence itself as well as the
53
+ sequence of indices of `motifs` used to create it.
54
+
55
+ "length" here means an abstracted length defined by the struct `M`,
56
+ based on the `limits` and `translate` functions.
57
+ It does **not** refer to the amount of elements!
58
+
59
+ `M` can be anything, given the two functions
60
+ * `limits(motif)` : Some function that given the `motif` it returns the
61
+ `(start, fine)` of the the motif in the same units as `q`.
62
+ This function establishes a measure of length, which simply is `fine - start`.
63
+ * `translate(motif, t)` : Some function that given the `motif` it returns a *new*
64
+ motif which is translated by `t` (either negative or positive), with
65
+ respect to the same units as `q`.
66
+
67
+ ## Keywords
68
+ Please see the source code (use `@which`) for a full description of the algorithm.
69
+
70
+ * `tries = 5` : Up to how many initial random sequences are accepted.
71
+ * `taulcut = 2` : Up to how times an element is dropped from the initial guess.
72
+ * `summands = 3` : Up to how many motifs may be combined as a sum to
73
+ complete a sequence.
74
74
"""
75
75
function random_sequence (motifs:: Vector{M} , q,
76
76
limits, translate, δq = 0 ;
@@ -84,6 +84,12 @@ function random_sequence(motifs::Vector{M}, q,
84
84
" Impossible to make a sequence."
85
85
))
86
86
87
+ eltype (motiflens) <: AbstractFloat && δq == 0 && throw (ArgumentError (
88
+ " Due to finite precision of floating values, it is almost always impossible " *
89
+ " to create a sequence of *exact* amount of floating length. Please provide " *
90
+ " a δq > 0."
91
+ ))
92
+
87
93
worked = false ; count = 0 ; seq = Int[]
88
94
while worked == false
89
95
count > tries && throw (DeadEndMotifs (tries, summands, tailcut))
0 commit comments