@@ -8,9 +8,9 @@ The notion of "length" is defined
88based on the following two functions, which must be provided for the motifs:
99
1010* `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`.
1212 Notice that this function establishes a measure of
13- length, which simply is `end - start`.
13+ length, which simply is `fine - start`.
1414* `translate(motif, t)` : Some function that given the `motif` it returns a *new*
1515 motif which is translated by `t` (either negative or positive), with
1616 respect to the same units as `q`.
@@ -32,8 +32,6 @@ Base.showerror(io::IO, e::DeadEndMotifs) = print(io,
3232" DeadEndMotifs: Couldn't find a proper sequence with $(e. tries) random tries, " *
3333" each with summands up to $(e. summands) (total tailcuts: $(e. tailcut) )." )
3434
35- predicate (ℓ, q, δq) = q - δq ≤ ℓ ≤ q + δq
36-
3735
3836
3937"""
@@ -51,8 +49,8 @@ and `translate`.
5149
5250## Description & Keywords
5351The 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` ).
5654
5755For each random try, it is first check whether the sequence is already correct.
5856If 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,
8280 motifs0, motiflens = _motifs_at_origin (motifs, limits, translate)
8381
8482 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."
8685 ))
8786
8887 worked = false ; count = 0 ; seq = Int[]
121120 _random_sequence_try(motiflens, q) -> seq, seq_length
122121Return a random sequence of motif indices
123122so 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)`.
125124"""
126125function _random_sequence_try (motiflens, q, δq)
127126 seq = Int[]; seq_length = 0 ; idxs = 1 : length (motiflens)
205204# Function provided by Mark Birtwistle in stackoverflow
206205"""
207206 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.
210209
211210Return a vector of tuples: the first
212211entry 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
233232end
234233
235234
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-
286235
287236end # Module
0 commit comments