shuffle 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +18 -1
  2. data/lib/shuffle.rb +8 -2
  3. metadata +1 -1
data/README.md CHANGED
@@ -1 +1,18 @@
1
- http://www.youtube.com/watch?v=xFZYJIwfUbo
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 validate(size)
29
- frequency(sequence.each_cons(size)) == frequency(shuffler(size).each_cons(size))
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shuffle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: