Module: Bioinform::Support

Defined in:
lib/bioinform/support.rb

Class Method Summary collapse

Class Method Details

.element_indices(arr) ⇒ Object

element_indices() ==> :C=>1, :G=>2, :T=>3



6
7
8
# File 'lib/bioinform/support.rb', line 6

def self.element_indices(arr)
  arr.each_with_index.inject({}) {|hsh, (letter, index)| hsh.merge(letter => index) }
end

.hash_keys_permuted(key, value) ⇒ Object

hash_keys_permuted(, :A) ==> => :A, [1,0] => :A



11
12
13
# File 'lib/bioinform/support.rb', line 11

def self.hash_keys_permuted(key, value)
  key.permutation.inject({}){|hsh, perm| hsh.merge(perm => value) }
end

.various_key_case_types(hash) ⇒ Object



31
32
33
# File 'lib/bioinform/support.rb', line 31

def self.various_key_case_types(hash)
  various_key_types(various_key_cases(hash))
end

.various_key_cases(hash) ⇒ Object

various_key_cases(=> 2, ‘C’ => 3, :g =>5, :T => 8) ==> => 2, ‘A’ => 2, ‘c’ => 3, ‘C’ => 3, :g =>5, :G => 5, :T => 8, :t=>8



22
23
24
# File 'lib/bioinform/support.rb', line 22

def self.various_key_cases(hash)
  hash.inject({}){|h,(k,v)| h.merge(k.downcase => v, k.upcase => v) }
end

.various_key_types(hash) ⇒ Object

various_key_types(=> 2, ‘C’ => 3, :g =>5, :T => 8) ==> => 2, :a => 2, ‘C’ => 3, :C => 3, :g =>5, ‘g’ => 5, :T => 8, ‘T’=>8



27
28
29
# File 'lib/bioinform/support.rb', line 27

def self.various_key_types(hash)
  hash.inject({}){|h,(k,v)| h.merge(k.to_s => v, k.to_sym => v) }
end

.various_key_value_case_types(hash) ⇒ Object



46
47
48
# File 'lib/bioinform/support.rb', line 46

def self.various_key_value_case_types(hash)
  various_key_value_types(various_key_value_cases(hash))
end

.various_key_value_cases(hash) ⇒ Object

various_key_value_cases(=> :T) ==> => :T, :a => :t



37
38
39
# File 'lib/bioinform/support.rb', line 37

def self.various_key_value_cases(hash)
  hash.inject({}){|h,(k,v)| h.merge(k.upcase => v.upcase, k.downcase => v.downcase) }
end

.various_key_value_types(hash) ⇒ Object

various_key_value_types(=> :T) ==> => :T, ‘A’ => ‘T’



42
43
44
# File 'lib/bioinform/support.rb', line 42

def self.various_key_value_types(hash)
  hash.inject({}){|h,(k,v)| h.merge(k.to_s => v.to_s, k.to_sym => v.to_sym) }
end

.with_key_permutations(hash) ⇒ Object

with_key_permutations(=> :A, [0,2] => :T) ==> => :A, [1,0] => :A, [0,2] => :T, [2,0]=>:T



16
17
18
# File 'lib/bioinform/support.rb', line 16

def self.with_key_permutations(hash)
  hash.inject({}) {|h, (indices, letter)| h.merge( hash_keys_permuted(indices, letter) ) }
end