shuffle 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +18 -1
- data/lib/shuffle.rb +8 -2
- metadata +1 -1
data/README.md
CHANGED
@@ -1 +1,18 @@
|
|
1
|
-
|
1
|
+
#Shuffle
|
2
|
+
###Evan Senter
|
3
|
+
|
4
|
+
_Altschul, S. F., & Erickson, B. W. (1985). Significance of nucleotide sequence alignments: a method for random sequence permutation that preserves dinucleotide and codon usage. Molecular biology and evolution, 2(6), 526–38. Retrieved from http://www.ncbi.nlm.nih.gov/pubmed/3870875_
|
5
|
+
|
6
|
+
shuffler = Shuffle.new("AGACATAAAGTTCCGTACTGCCGGGAT")
|
7
|
+
puts (dishuffled_sequence = shuffler.dishuffle)
|
8
|
+
#=> AGAAGTACAATCGGTACGATTGGCCCT
|
9
|
+
shuffler.valid?(dishuffled_sequence, 2)
|
10
|
+
#=> true (Shuffler preserved the di-token frequency)
|
11
|
+
shuffler.valid?(dishuffled_sequence, 3)
|
12
|
+
#=> false-ish (Shuffler does not guarantee to preserve the tri-token frequency)
|
13
|
+
puts (trishuffled_sequence = shuffler.shuffle(3))
|
14
|
+
#=> AGTACTGCCGTTCCGGGATAAAGACAT
|
15
|
+
shuffler.valid?(trishuffled_sequence, 3)
|
16
|
+
#=> true
|
17
|
+
|
18
|
+
[motivation.](http://www.youtube.com/watch?v=xFZYJIwfUbo)
|
data/lib/shuffle.rb
CHANGED
@@ -25,8 +25,14 @@ class Shuffle
|
|
25
25
|
rejoin ? shuffled_sequence.join : shuffled_sequence
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
29
|
-
|
28
|
+
def valid?(other_sequence, size)
|
29
|
+
split_other_sequence = other_sequence.is_a?(String) && sequence !~ /\s/ ? other_sequence.split(//) : other_sequence
|
30
|
+
|
31
|
+
frequency(sequence.each_cons(size)) == frequency(split_other_sequence.each_cons(size))
|
32
|
+
end
|
33
|
+
|
34
|
+
def validate_random(size)
|
35
|
+
valid?(shuffler(size), size)
|
30
36
|
end
|
31
37
|
|
32
38
|
private
|