Skip to content

Commit f5a4184

Browse files
committed
Imrpove docs, add changelog
1 parent b71fb82 commit f5a4184

File tree

2 files changed

+18
-60
lines changed

2 files changed

+18
-60
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
All notable changes to this project will be documented in this file.
2+
3+
This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
4+
5+
# master
6+
work in progress changes are contained in this section.
7+
8+
# v0.1.0 - Initial Release
9+
Changelog is kept with respect to this release.

src/MotifSequenceGenerator.jl

+9-60
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ The notion of "length" is defined
88
based 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
5351
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`).
5654
5755
For each random try, it is first check whether the sequence is already correct.
5856
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,
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[]
@@ -121,7 +120,7 @@ end
121120
_random_sequence_try(motiflens, q) -> seq, seq_length
122121
Return a random sequence of motif indices
123122
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)`.
125124
"""
126125
function _random_sequence_try(motiflens, q, δq)
127126
seq = Int[]; seq_length = 0; idxs = 1:length(motiflens)
@@ -205,8 +204,8 @@ end
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
211210
Return a vector of tuples: the first
212211
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
233232
end
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

287236
end#Module

0 commit comments

Comments
 (0)