@@ -8,9 +8,9 @@ The notion of "length" is defined
8
8
based on the following two functions, which must be provided for the motifs:
9
9
10
10
* `limits(motif)` : Some function that given the `motif` it returns the
11
- `(start, end )` of the the motif in the same units as `q`.
11
+ `(start, fine )` of the the motif in the same units as `q`.
12
12
Notice that this function establishes a measure of
13
- length, which simply is `end - start`.
13
+ length, which simply is `fine - start`.
14
14
* `translate(motif, t)` : Some function that given the `motif` it returns a *new*
15
15
motif which is translated by `t` (either negative or positive), with
16
16
respect to the same units as `q`.
@@ -32,8 +32,6 @@ Base.showerror(io::IO, e::DeadEndMotifs) = print(io,
32
32
" DeadEndMotifs: Couldn't find a proper sequence with $(e. tries) random tries, " *
33
33
" each with summands up to $(e. summands) (total tailcuts: $(e. tailcut) )." )
34
34
35
- predicate (ℓ, q, δq) = q - δq ≤ ℓ ≤ q + δq
36
-
37
35
38
36
39
37
"""
@@ -51,8 +49,8 @@ and `translate`.
51
49
52
50
## Description & Keywords
53
51
The algorithm works as follows: First a random sequence of motifs is created,
54
- so that it has length of `q ≤ s ≤ q - maximum(motiflengths)`. The possible tries
55
- of random sequences is set by the `tries` keyword (default 5 ).
52
+ so that it has length of `q - δq ≤ ℓ ≤ q - δq + maximum(motiflengths)`.
53
+ The possible tries of random sequences is set by the `tries` keyword (default `5` ).
56
54
57
55
For each random try, it is first check whether the sequence is already correct.
58
56
If not, the last entry of the sequence is dropped. Then, since the sequence is now
@@ -82,7 +80,8 @@ function random_sequence(motifs::Vector{M}, q,
82
80
motifs0, motiflens = _motifs_at_origin (motifs, limits, translate)
83
81
84
82
q - δq < minimum (motiflens) && throw (ArgumentError (
85
- " Minimum length of motifs is greater than `q - δq`. Impossible to make a sequence."
83
+ " Minimum length of motifs is greater than `q - δq`! " *
84
+ " Impossible to make a sequence."
86
85
))
87
86
88
87
worked = false ; count = 0 ; seq = Int[]
121
120
_random_sequence_try(motiflens, q) -> seq, seq_length
122
121
Return a random sequence of motif indices
123
122
so that the total sequence is *guaranteed* to have total length of
124
- `q - δq ≤ ℓ ≤ q - δq - maximum(motiflens)`.
123
+ `q - δq ≤ ℓ ≤ q - δq + maximum(motiflens)`.
125
124
"""
126
125
function _random_sequence_try (motiflens, q, δq)
127
126
seq = Int[]; seq_length = 0 ; idxs = 1 : length (motiflens)
205
204
# Function provided by Mark Birtwistle in stackoverflow
206
205
"""
207
206
all_possible_sums(summands, n)
208
- Compute all possible sums from combining `n` elements from `summands`,
209
- with repetition and using only unique combinations.
207
+ Compute all possible sums from combining `n` elements from `summands`
208
+ ( with repetition), only using unique combinations.
210
209
211
210
Return a vector of tuples: the first
212
211
entry of each tuple is the sum, while the second is the indices of summands
@@ -233,55 +232,5 @@ function _instantiate_sequence(motifs0::Vector{M}, motiflens, seq, translate) wh
233
232
end
234
233
235
234
236
- # Handling with δq = 0
237
- function _complete_sequence!_old (seq, motiflens, q, summands, tailcut)
238
-
239
- remainder = q - sum (motiflens[k] for k in seq)
240
- if remainder == 0
241
- # Case 0: The sequence is already exactly equal to q
242
- return true
243
- elseif remainder < 0 && - remainder ∈ motiflens
244
- # Case 1: There is an extra difference, which is an
245
- # exact length of some motif.
246
- # We find the possible motifs, pick a random one, and pick
247
- # a random position in the sequence that it exists.
248
- # Delete that entry of the sequence.
249
- mi = findall (in (- remainder), motiflens)
250
- possible = findall (in (mi), seq)
251
- if ! isempty (possible)
252
- deleteat! (seq, rand (possible))
253
- return true
254
- end
255
- else
256
- # Case 2: Recursive deletion of last entry of the sequence, and trying to
257
- # see if it can be completed with some combination of existing motifs
258
- tcut = 0
259
- while tcut < tailcut
260
- tcut += 1
261
- pop! (seq)
262
- isempty (seq) && return false
263
- remainder = q - sum (motiflens[k] for k in seq)
264
- if remainder ∈ motiflens
265
- mi = rand (findall (in (remainder), motiflens))
266
- push! (seq, mi)
267
- return true
268
- end
269
- for n in 2 : summands
270
- everything = all_possible_sums (motiflens, n)
271
- sums = [e[1 ] for e in everything]
272
- if remainder ∈ sums
273
- cases = findall (in (remainder), sums)
274
- if ! isempty (cases)
275
- idxs_of_vals = shuffle! (everything[rand (cases)][2 ])
276
- push! (seq, idxs_of_vals... )
277
- return true
278
- end
279
- end
280
- end
281
- end
282
- end
283
- return false
284
- end
285
-
286
235
287
236
end # Module
0 commit comments