bioinform 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +17 -17
  3. data/Gemfile +16 -16
  4. data/LICENSE +21 -21
  5. data/README.md +35 -35
  6. data/Rakefile +4 -4
  7. data/TODO.txt +37 -37
  8. data/bin/merge_into_collection +3 -3
  9. data/bin/pcm2pwm +3 -3
  10. data/bin/split_motifs +3 -3
  11. data/bioinform.gemspec +19 -19
  12. data/lib/bioinform/cli/convert_motif.rb +107 -107
  13. data/lib/bioinform/cli/merge_into_collection.rb +79 -79
  14. data/lib/bioinform/cli/pcm2pwm.rb +46 -46
  15. data/lib/bioinform/cli/split_motifs.rb +46 -46
  16. data/lib/bioinform/cli.rb +29 -29
  17. data/lib/bioinform/conversion_algorithms/pcm2ppm_converter.rb +18 -18
  18. data/lib/bioinform/conversion_algorithms/pcm2pwm_converter.rb +19 -19
  19. data/lib/bioinform/data_models/collection.rb +74 -74
  20. data/lib/bioinform/data_models/motif.rb +55 -55
  21. data/lib/bioinform/data_models/pcm.rb +23 -23
  22. data/lib/bioinform/data_models/pm.rb +169 -169
  23. data/lib/bioinform/data_models/ppm.rb +9 -9
  24. data/lib/bioinform/data_models/pwm.rb +55 -55
  25. data/lib/bioinform/data_models.rb +10 -10
  26. data/lib/bioinform/formatters/raw_formatter.rb +40 -40
  27. data/lib/bioinform/formatters/transfac_formatter.rb +38 -38
  28. data/lib/bioinform/formatters.rb +1 -1
  29. data/lib/bioinform/parsers/jaspar_parser.rb +34 -34
  30. data/lib/bioinform/parsers/parser.rb +87 -87
  31. data/lib/bioinform/parsers/splittable_parser.rb +56 -56
  32. data/lib/bioinform/parsers/string_fantom_parser.rb +34 -34
  33. data/lib/bioinform/parsers/string_parser.rb +71 -71
  34. data/lib/bioinform/parsers/trivial_parser.rb +33 -33
  35. data/lib/bioinform/parsers/yaml_parser.rb +34 -34
  36. data/lib/bioinform/parsers.rb +6 -6
  37. data/lib/bioinform/support/array_product.rb +5 -5
  38. data/lib/bioinform/support/array_zip.rb +5 -5
  39. data/lib/bioinform/support/collect_hash.rb +6 -6
  40. data/lib/bioinform/support/deep_dup.rb +4 -4
  41. data/lib/bioinform/support/delete_many.rb +13 -13
  42. data/lib/bioinform/support/inverf.rb +12 -12
  43. data/lib/bioinform/support/multiline_squish.rb +5 -5
  44. data/lib/bioinform/support/parameters.rb +27 -27
  45. data/lib/bioinform/support/partial_sums.rb +15 -15
  46. data/lib/bioinform/support/same_by.rb +12 -12
  47. data/lib/bioinform/support/strip_doc.rb +8 -8
  48. data/lib/bioinform/support/third_part/active_support/hash_with_indifferent_access.rb +3 -0
  49. data/lib/bioinform/support.rb +17 -17
  50. data/lib/bioinform/version.rb +3 -3
  51. data/lib/bioinform.rb +10 -10
  52. data/spec/cli/cli_spec.rb +13 -13
  53. data/spec/cli/convert_motif_spec.rb +106 -106
  54. data/spec/cli/data/merge_into_collection/GABPA_f1.pwm +14 -14
  55. data/spec/cli/data/merge_into_collection/KLF4_f2.pwm +11 -11
  56. data/spec/cli/data/merge_into_collection/SP1_f1.pwm +12 -12
  57. data/spec/cli/data/merge_into_collection/collection.txt.result +40 -40
  58. data/spec/cli/data/merge_into_collection/collection.yaml.result +188 -188
  59. data/spec/cli/data/merge_into_collection/collection_pwm.yaml.result +188 -188
  60. data/spec/cli/data/merge_into_collection/pwm_folder/GABPA_f1.pwm +14 -14
  61. data/spec/cli/data/merge_into_collection/pwm_folder/KLF4_f2.pwm +11 -11
  62. data/spec/cli/data/merge_into_collection/pwm_folder/SP1_f1.pwm +12 -12
  63. data/spec/cli/data/pcm2pwm/KLF4 f2 spaced name.pcm +11 -11
  64. data/spec/cli/data/pcm2pwm/KLF4_f2.pcm +11 -11
  65. data/spec/cli/data/pcm2pwm/KLF4_f2.pwm.result +11 -11
  66. data/spec/cli/data/pcm2pwm/SP1_f1.pcm +12 -12
  67. data/spec/cli/data/pcm2pwm/SP1_f1.pwm.result +12 -12
  68. data/spec/cli/data/split_motifs/GABPA_f1.mat.result +14 -14
  69. data/spec/cli/data/split_motifs/KLF4_f2.mat.result +11 -11
  70. data/spec/cli/data/split_motifs/SP1_f1.mat.result +12 -12
  71. data/spec/cli/data/split_motifs/collection.yaml +188 -188
  72. data/spec/cli/data/split_motifs/plain_collection.txt +38 -38
  73. data/spec/cli/merge_into_collection_spec.rb +99 -99
  74. data/spec/cli/pcm2pwm_spec.rb +79 -79
  75. data/spec/cli/shared_examples/convert_motif/motif_list_empty.rb +17 -17
  76. data/spec/cli/shared_examples/convert_motif/several_motifs_specified.rb +14 -14
  77. data/spec/cli/shared_examples/convert_motif/single_motif_specified.rb +49 -49
  78. data/spec/cli/shared_examples/convert_motif/yield_help_string.rb +4 -4
  79. data/spec/cli/shared_examples/convert_motif/yield_motif_conversion_error.rb +3 -3
  80. data/spec/cli/split_motifs_spec.rb +76 -76
  81. data/spec/data_models/collection_spec.rb +97 -97
  82. data/spec/data_models/motif_spec.rb +223 -223
  83. data/spec/data_models/pcm_spec.rb +55 -55
  84. data/spec/data_models/pm_spec.rb +359 -359
  85. data/spec/data_models/ppm_spec.rb +7 -7
  86. data/spec/data_models/pwm_spec.rb +82 -82
  87. data/spec/fabricators/collection_fabricator.rb +7 -7
  88. data/spec/fabricators/motif_fabricator.rb +32 -32
  89. data/spec/fabricators/motif_formats_fabricator.rb +124 -124
  90. data/spec/fabricators/pcm_fabricator.rb +24 -24
  91. data/spec/fabricators/pm_fabricator.rb +51 -51
  92. data/spec/fabricators/ppm_fabricator.rb +13 -13
  93. data/spec/fabricators/pwm_fabricator.rb +16 -16
  94. data/spec/parsers/parser_spec.rb +152 -152
  95. data/spec/parsers/string_fantom_parser_spec.rb +69 -69
  96. data/spec/parsers/string_parser_spec.rb +76 -76
  97. data/spec/parsers/trivial_parser_spec.rb +63 -63
  98. data/spec/parsers/yaml_parser_spec.rb +50 -50
  99. data/spec/spec_helper.rb +10 -10
  100. data/spec/spec_helper_source.rb +59 -59
  101. data/spec/support/advanced_scan_spec.rb +31 -31
  102. data/spec/support/array_product_spec.rb +14 -14
  103. data/spec/support/array_zip_spec.rb +14 -14
  104. data/spec/support/collect_hash_spec.rb +14 -14
  105. data/spec/support/delete_many_spec.rb +43 -43
  106. data/spec/support/inverf_spec.rb +18 -18
  107. data/spec/support/multiline_squish_spec.rb +24 -24
  108. data/spec/support/partial_sums_spec.rb +30 -30
  109. data/spec/support/same_by_spec.rb +35 -35
  110. metadata +3 -3
@@ -1,72 +1,72 @@
1
- require 'strscan'
2
- require_relative '../support'
3
- require_relative '../parsers/parser'
4
-
5
- module Bioinform
6
- class StringParser < Parser
7
- include MultipleMotifsParser
8
- attr_reader :scanner, :row_acgt_markers
9
-
10
- def initialize(input)
11
- raise ArgumentError, 'StringParser should be initialized with a String' unless input.is_a?(String)
12
- super
13
- @scanner = StringScanner.new(input.multiline_squish)
14
- end
15
-
16
- def number_pat
17
- /[+-]?\d+(\.\d+)?([eE][+-]?\d{1,3})?/
18
- end
19
-
20
- def header_pat
21
- />?\s*(?<name>\S+)\n/
22
- end
23
-
24
- def row_pat
25
- /([ACGT]\s*[:|]?\s*)?(?<row>(#{number_pat} )*#{number_pat})\n?/
26
- end
27
-
28
- def scan_row
29
- match = scanner.advanced_scan(row_pat)
30
- match && match[:row]
31
- end
32
-
33
- def split_row(row_string)
34
- row_string.split.map(&:to_f)
35
- end
36
-
37
- def scan_any_spaces
38
- scanner.scan(/\s+/)
39
- end
40
-
41
- def parse_name
42
- match = scanner.advanced_scan(header_pat)
43
- match && match[:name]
44
- end
45
-
46
- def parse_matrix
47
- matrix = []
48
- @row_acgt_markers = true if scanner.check(/A.*\nC.*\nG.*\nT.*\n?/)
49
- while row_string = scan_row
50
- matrix << split_row(row_string)
51
- end
52
- matrix
53
- end
54
-
55
- def parse_acgt_header
56
- scanner.scan(/A\s*C\s*G\s*T\s*\n/i)
57
- end
58
-
59
- def parse!
60
- scan_any_spaces
61
- name = parse_name
62
- parse_acgt_header
63
- matrix = parse_matrix
64
- matrix = matrix.transpose if row_acgt_markers
65
- Parser.parse!(matrix).tap{|result| result.name = name}
66
- end
67
-
68
- def scanner_reset
69
- scanner.reset
70
- end
71
- end
1
+ require 'strscan'
2
+ require_relative '../support'
3
+ require_relative '../parsers/parser'
4
+
5
+ module Bioinform
6
+ class StringParser < Parser
7
+ include MultipleMotifsParser
8
+ attr_reader :scanner, :row_acgt_markers
9
+
10
+ def initialize(input)
11
+ raise ArgumentError, 'StringParser should be initialized with a String' unless input.is_a?(String)
12
+ super
13
+ @scanner = StringScanner.new(input.multiline_squish)
14
+ end
15
+
16
+ def number_pat
17
+ /[+-]?\d+(\.\d+)?([eE][+-]?\d{1,3})?/
18
+ end
19
+
20
+ def header_pat
21
+ />?\s*(?<name>\S+)\n/
22
+ end
23
+
24
+ def row_pat
25
+ /([ACGT]\s*[:|]?\s*)?(?<row>(#{number_pat} )*#{number_pat})\n?/
26
+ end
27
+
28
+ def scan_row
29
+ match = scanner.advanced_scan(row_pat)
30
+ match && match[:row]
31
+ end
32
+
33
+ def split_row(row_string)
34
+ row_string.split.map(&:to_f)
35
+ end
36
+
37
+ def scan_any_spaces
38
+ scanner.scan(/\s+/)
39
+ end
40
+
41
+ def parse_name
42
+ match = scanner.advanced_scan(header_pat)
43
+ match && match[:name]
44
+ end
45
+
46
+ def parse_matrix
47
+ matrix = []
48
+ @row_acgt_markers = true if scanner.check(/A.*\nC.*\nG.*\nT.*\n?/)
49
+ while row_string = scan_row
50
+ matrix << split_row(row_string)
51
+ end
52
+ matrix
53
+ end
54
+
55
+ def parse_acgt_header
56
+ scanner.scan(/A\s*C\s*G\s*T\s*\n/i)
57
+ end
58
+
59
+ def parse!
60
+ scan_any_spaces
61
+ name = parse_name
62
+ parse_acgt_header
63
+ matrix = parse_matrix
64
+ matrix = matrix.transpose if row_acgt_markers
65
+ Parser.parse!(matrix).tap{|result| result.name = name}
66
+ end
67
+
68
+ def scanner_reset
69
+ scanner.reset
70
+ end
71
+ end
72
72
  end
@@ -1,34 +1,34 @@
1
- require_relative '../support'
2
- require_relative '../parsers/parser'
3
- require_relative '../data_models/collection'
4
- require 'yaml'
5
-
6
- module Bioinform
7
- # TrivialParser can be used to parse hashes returned by #parse method of other parsers:
8
- # PM.new({matrix:[[1,2,3,4],[5,6,7,8]], name: 'Name'}, TrivialParser)
9
- # PM.new(StringParser.new("1 2 3 4\n5 6 7 8").parse)
10
- # StringParser.new("First\n1 2 3 4\n5 6 7 8\nSecond\n0 0 0 0").map{|inp| PM.new(inp, TrivialParser)}
11
- class TrivialParser < Parser
12
- def initialize(input)
13
- @input = input
14
- end
15
- def parse!
16
- case input
17
- when PM then input
18
- when Motif then input.pm
19
- when OpenStruct then input
20
- when Hash then OpenStruct.new(input)
21
- end
22
- end
23
- end
24
-
25
- class TrivialCollectionParser < Parser
26
- include MultipleMotifsParser
27
- def initialize(input)
28
- @input = input
29
- end
30
- def parse!
31
- input.container.shift.pm
32
- end
33
- end
1
+ require_relative '../support'
2
+ require_relative '../parsers/parser'
3
+ require_relative '../data_models/collection'
4
+ require 'yaml'
5
+
6
+ module Bioinform
7
+ # TrivialParser can be used to parse hashes returned by #parse method of other parsers:
8
+ # PM.new({matrix:[[1,2,3,4],[5,6,7,8]], name: 'Name'}, TrivialParser)
9
+ # PM.new(StringParser.new("1 2 3 4\n5 6 7 8").parse)
10
+ # StringParser.new("First\n1 2 3 4\n5 6 7 8\nSecond\n0 0 0 0").map{|inp| PM.new(inp, TrivialParser)}
11
+ class TrivialParser < Parser
12
+ def initialize(input)
13
+ @input = input
14
+ end
15
+ def parse!
16
+ case input
17
+ when PM then input
18
+ when Motif then input.pm
19
+ when OpenStruct then input
20
+ when Hash then OpenStruct.new(input)
21
+ end
22
+ end
23
+ end
24
+
25
+ class TrivialCollectionParser < Parser
26
+ include MultipleMotifsParser
27
+ def initialize(input)
28
+ @input = input
29
+ end
30
+ def parse!
31
+ input.container.shift.pm
32
+ end
33
+ end
34
34
  end
@@ -1,35 +1,35 @@
1
- require_relative '../support'
2
- require_relative 'parser'
3
- require_relative '../data_models/collection'
4
- require 'yaml'
5
-
6
- module Bioinform
7
- # YAMLParser can be used to parse hashes returned by #parse method of other parsers:
8
- # yaml_dump_of_pm = PM.new(...).to_yaml
9
- # PM.new(yaml_dump_of_pm, YAMLParser)
10
- class YAMLParser < Parser
11
- def initialize(input)
12
- @input = input
13
- end
14
- def parse!
15
- YAML.load(input)
16
- rescue Psych::SyntaxError
17
- raise 'parsing error'
18
- end
19
- end
20
-
21
- class YAMLCollectionParser < Parser
22
- include MultipleMotifsParser
23
- def initialize(input)
24
- @input = input
25
- end
26
- def collection
27
- @collection ||= YAML.load(input)
28
- end
29
- def parse!
30
- collection.container.shift.pm
31
- rescue Psych::SyntaxError
32
- raise 'parsing error'
33
- end
34
- end
1
+ require_relative '../support'
2
+ require_relative 'parser'
3
+ require_relative '../data_models/collection'
4
+ require 'yaml'
5
+
6
+ module Bioinform
7
+ # YAMLParser can be used to parse hashes returned by #parse method of other parsers:
8
+ # yaml_dump_of_pm = PM.new(...).to_yaml
9
+ # PM.new(yaml_dump_of_pm, YAMLParser)
10
+ class YAMLParser < Parser
11
+ def initialize(input)
12
+ @input = input
13
+ end
14
+ def parse!
15
+ YAML.load(input)
16
+ rescue Psych::SyntaxError
17
+ raise 'parsing error'
18
+ end
19
+ end
20
+
21
+ class YAMLCollectionParser < Parser
22
+ include MultipleMotifsParser
23
+ def initialize(input)
24
+ @input = input
25
+ end
26
+ def collection
27
+ @collection ||= YAML.load(input)
28
+ end
29
+ def parse!
30
+ collection.container.shift.pm
31
+ rescue Psych::SyntaxError
32
+ raise 'parsing error'
33
+ end
34
+ end
35
35
  end
@@ -1,7 +1,7 @@
1
- require_relative 'parsers/parser'
2
- require_relative 'parsers/trivial_parser'
3
- require_relative 'parsers/yaml_parser'
4
- require_relative 'parsers/string_parser'
5
- require_relative 'parsers/string_fantom_parser'
6
- require_relative 'parsers/splittable_parser'
1
+ require_relative 'parsers/parser'
2
+ require_relative 'parsers/trivial_parser'
3
+ require_relative 'parsers/yaml_parser'
4
+ require_relative 'parsers/string_parser'
5
+ require_relative 'parsers/string_fantom_parser'
6
+ require_relative 'parsers/splittable_parser'
7
7
  require_relative 'parsers/jaspar_parser'
@@ -1,6 +1,6 @@
1
- class Array
2
- def self.product(*arrays)
3
- return [] if arrays.empty?
4
- arrays.first.product(*arrays[1..-1])
5
- end
1
+ class Array
2
+ def self.product(*arrays)
3
+ return [] if arrays.empty?
4
+ arrays.first.product(*arrays[1..-1])
5
+ end
6
6
  end
@@ -1,6 +1,6 @@
1
- class Array
2
- def self.zip(*arrays)
3
- return [] if arrays.empty?
4
- arrays.first.zip(*arrays[1..-1])
5
- end
1
+ class Array
2
+ def self.zip(*arrays)
3
+ return [] if arrays.empty?
4
+ arrays.first.zip(*arrays[1..-1])
5
+ end
6
6
  end
@@ -1,7 +1,7 @@
1
- module Enumerable
2
- # %w{A C G T}.collect_hash{|k| [k*2, k*3] }
3
- # # ==> {"AA" => "AAA", "CC" => "CCC", "GG" => "GGG", "TT" => "TTT"}
4
- def collect_hash(&block)
5
- block_given? ? Hash[ collect(&block) ] : Hash[ collect{|k,v| [k,v]} ]
6
- end
1
+ module Enumerable
2
+ # %w{A C G T}.collect_hash{|k| [k*2, k*3] }
3
+ # # ==> {"AA" => "AAA", "CC" => "CCC", "GG" => "GGG", "TT" => "TTT"}
4
+ def collect_hash(&block)
5
+ block_given? ? Hash[ collect(&block) ] : Hash[ collect{|k,v| [k,v]} ]
6
+ end
7
7
  end
@@ -1,5 +1,5 @@
1
- class Object
2
- def deep_dup
3
- Marshal.load(Marshal.dump(self))
4
- end
1
+ class Object
2
+ def deep_dup
3
+ Marshal.load(Marshal.dump(self))
4
+ end
5
5
  end
@@ -1,14 +1,14 @@
1
- class Array
2
- def delete_at_many(*indices)
3
- indices.uniq.sort.reverse.each{|ind| delete_at ind}
4
- end
5
- def delete_many(*elements)
6
- elements.each{|el| delete el}
7
- end
8
- end
9
-
10
- class Hash
11
- def delete_many(*keys)
12
- keys.each{|el| delete el}
13
- end
1
+ class Array
2
+ def delete_at_many(*indices)
3
+ indices.uniq.sort.reverse.each{|ind| delete_at ind}
4
+ end
5
+ def delete_many(*elements)
6
+ elements.each{|el| delete el}
7
+ end
8
+ end
9
+
10
+ class Hash
11
+ def delete_many(*keys)
12
+ keys.each{|el| delete el}
13
+ end
14
14
  end
@@ -1,13 +1,13 @@
1
- module Math
2
- def self.inverf(x)
3
- sign = x < 0 ? -1 : 1
4
- x = x.abs
5
- a = 8 / (3*Math::PI) * (Math::PI-3) / (4-Math::PI)
6
- part0 = ( 2/(Math::PI*a) + (Math.log(1-x*x)) / 2 )**2
7
- part = -2 / (Math::PI * a) - Math.log(1-x*x)/2 + Math.sqrt(-1/a * Math.log(1-x*x) + part0)
8
- sign * Math.sqrt(part)
9
- end
10
- def inverf(x)
11
- Math.inverf(x)
12
- end
1
+ module Math
2
+ def self.inverf(x)
3
+ sign = x < 0 ? -1 : 1
4
+ x = x.abs
5
+ a = 8 / (3*Math::PI) * (Math::PI-3) / (4-Math::PI)
6
+ part0 = ( 2/(Math::PI*a) + (Math.log(1-x*x)) / 2 )**2
7
+ part = -2 / (Math::PI * a) - Math.log(1-x*x)/2 + Math.sqrt(-1/a * Math.log(1-x*x) + part0)
8
+ sign * Math.sqrt(part)
9
+ end
10
+ def inverf(x)
11
+ Math.inverf(x)
12
+ end
13
13
  end
@@ -1,6 +1,6 @@
1
- require_relative 'third_part/active_support/core_ext/string/filters'
2
- class String
3
- def multiline_squish
4
- split("\n").map(&:squish).join("\n").gsub(/\A\n+/,'').gsub(/\n+\z/,'')
5
- end
1
+ require_relative 'third_part/active_support/core_ext/string/filters'
2
+ class String
3
+ def multiline_squish
4
+ split("\n").map(&:squish).join("\n").gsub(/\A\n+/,'').gsub(/\n+\z/,'')
5
+ end
6
6
  end
@@ -1,28 +1,28 @@
1
- require 'ostruct'
2
- module Bioinform
3
- module Parameters
4
- def self.included(base)
5
- base.extend(ClassMethods)
6
- end
7
- module ClassMethods
8
- def make_parameters(*params)
9
- params.each do |param|
10
- define_method(param){ parameters.send(param) }
11
- define_method("#{param}="){|new_value| parameters.send("#{param}=", new_value) }
12
- end
13
- end
14
- end
15
- def parameters; @parameters ||= OpenStruct.new; end
16
- def set_parameters(hsh)
17
- hsh.each{|k,v| send("#{k}=", v) }
18
- self
19
- end
20
- # return hash of parameters
21
- def get_parameters
22
- @parameters.marshal_dump
23
- end
24
- def parameter_defined?(param_name)
25
- get_parameters.has_key?(param_name)
26
- end
27
- end
1
+ require 'ostruct'
2
+ module Bioinform
3
+ module Parameters
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+ module ClassMethods
8
+ def make_parameters(*params)
9
+ params.each do |param|
10
+ define_method(param){ parameters.send(param) }
11
+ define_method("#{param}="){|new_value| parameters.send("#{param}=", new_value) }
12
+ end
13
+ end
14
+ end
15
+ def parameters; @parameters ||= OpenStruct.new; end
16
+ def set_parameters(hsh)
17
+ hsh.each{|k,v| send("#{k}=", v) }
18
+ self
19
+ end
20
+ # return hash of parameters
21
+ def get_parameters
22
+ @parameters.marshal_dump
23
+ end
24
+ def parameter_defined?(param_name)
25
+ get_parameters.has_key?(param_name)
26
+ end
27
+ end
28
28
  end
@@ -1,16 +1,16 @@
1
- require_relative 'collect_hash'
2
-
3
- class Array
4
- def partial_sums(initial = 0.0)
5
- sums = initial
6
- map{|el| sums += el}
7
- end
8
- end
9
-
10
- class Hash
11
- # {1 => 5, 4 => 3, 3 => 2}.partial_sums == {1=>5, 3=>7, 4=>10}
12
- def partial_sums(initial = 0.0)
13
- sums = initial
14
- sort.collect_hash{|k,v| [k, sums += v]}
15
- end
1
+ require_relative 'collect_hash'
2
+
3
+ class Array
4
+ def partial_sums(initial = 0.0)
5
+ sums = initial
6
+ map{|el| sums += el}
7
+ end
8
+ end
9
+
10
+ class Hash
11
+ # {1 => 5, 4 => 3, 3 => 2}.partial_sums == {1=>5, 3=>7, 4=>10}
12
+ def partial_sums(initial = 0.0)
13
+ sums = initial
14
+ sort.collect_hash{|k,v| [k, sums += v]}
15
+ end
16
16
  end
@@ -1,12 +1,12 @@
1
- module Enumerable
2
- def same_by?(&block)
3
- return true if empty?
4
- if block_given?
5
- first_result = yield(first)
6
- all?{|el| first_result == yield(el)}
7
- else
8
- first_result = first
9
- all?{|el| first_result == el}
10
- end
11
- end
12
- end
1
+ module Enumerable
2
+ def same_by?(&block)
3
+ return true if empty?
4
+ if block_given?
5
+ first_result = yield(first)
6
+ all?{|el| first_result == yield(el)}
7
+ else
8
+ first_result = first
9
+ all?{|el| first_result == el}
10
+ end
11
+ end
12
+ end
@@ -1,9 +1,9 @@
1
- def strip_doc(doc)
2
- doc.strip_doc
3
- end
4
-
5
- class String
6
- def strip_doc
7
- gsub(/^#{self[/\A +/]}/,'')
8
- end
1
+ def strip_doc(doc)
2
+ doc.strip_doc
3
+ end
4
+
5
+ class String
6
+ def strip_doc
7
+ gsub(/^#{self[/\A +/]}/,'')
8
+ end
9
9
  end
@@ -3,6 +3,7 @@ require_relative 'core_ext/hash/keys'
3
3
  # This class has dubious semantics and we only have it so that
4
4
  # people can write <tt>params[:key]</tt> instead of <tt>params['key']</tt>
5
5
  # and they get the same value for both keys.
6
+ unless defined? ActiveSupport::HashWithIndifferentAccess
6
7
 
7
8
  module ActiveSupport
8
9
  class HashWithIndifferentAccess < Hash
@@ -176,3 +177,5 @@ module ActiveSupport
176
177
  end
177
178
 
178
179
  HashWithIndifferentAccess = ActiveSupport::HashWithIndifferentAccess
180
+
181
+ end
@@ -1,18 +1,18 @@
1
- require_relative 'support/third_part/active_support/core_ext/string/filters'
2
- require_relative 'support/third_part/active_support/core_ext/hash/indifferent_access'
3
-
4
- require_relative 'support/collect_hash'
5
- require_relative 'support/delete_many'
6
- require_relative 'support/multiline_squish'
7
- require_relative 'support/same_by'
8
- require_relative 'support/inverf'
9
- require_relative 'support/deep_dup'
10
-
11
- require_relative 'support/partial_sums'
12
-
13
- require_relative 'support/array_zip'
14
- require_relative 'support/array_product'
15
-
16
- require_relative 'support/advanced_scan'
17
- require_relative 'support/parameters'
1
+ require_relative 'support/third_part/active_support/core_ext/string/filters'
2
+ require_relative 'support/third_part/active_support/core_ext/hash/indifferent_access'
3
+
4
+ require_relative 'support/collect_hash'
5
+ require_relative 'support/delete_many'
6
+ require_relative 'support/multiline_squish'
7
+ require_relative 'support/same_by'
8
+ require_relative 'support/inverf'
9
+ require_relative 'support/deep_dup'
10
+
11
+ require_relative 'support/partial_sums'
12
+
13
+ require_relative 'support/array_zip'
14
+ require_relative 'support/array_product'
15
+
16
+ require_relative 'support/advanced_scan'
17
+ require_relative 'support/parameters'
18
18
  require_relative 'support/strip_doc'
@@ -1,3 +1,3 @@
1
- module Bioinform
2
- VERSION = "0.1.12"
3
- end
1
+ module Bioinform
2
+ VERSION = "0.1.13"
3
+ end
data/lib/bioinform.rb CHANGED
@@ -1,10 +1,10 @@
1
- require_relative 'bioinform/version'
2
- require_relative 'bioinform/support'
3
- require_relative 'bioinform/parsers'
4
- require_relative 'bioinform/formatters'
5
- require_relative 'bioinform/data_models'
6
- require_relative 'bioinform/cli'
7
-
8
- module Bioinform
9
- # Your code goes here...
10
- end
1
+ require_relative 'bioinform/version'
2
+ require_relative 'bioinform/support'
3
+ require_relative 'bioinform/parsers'
4
+ require_relative 'bioinform/formatters'
5
+ require_relative 'bioinform/data_models'
6
+ require_relative 'bioinform/cli'
7
+
8
+ module Bioinform
9
+ # Your code goes here...
10
+ end
data/spec/cli/cli_spec.rb CHANGED
@@ -1,14 +1,14 @@
1
- require_relative '../spec_helper'
2
- require_relative '../../lib/bioinform/cli'
3
-
4
- describe Bioinform::CLI do
5
- describe '.change_folder_and_extension' do
6
- it 'should change extension and folder' do
7
- extend Bioinform::CLI::Helpers
8
- change_folder_and_extension('test.pcm', 'pwm', '.').should == './test.pwm'
9
- change_folder_and_extension('test.pcm', 'pat', 'pwm_folder').should == 'pwm_folder/test.pat'
10
- change_folder_and_extension('pcm/test.pcm', 'pat', 'pwm_folder').should == 'pwm_folder/test.pat'
11
- change_folder_and_extension('test.pcm', 'pat', '../pwm_folder').should == '../pwm_folder/test.pat'
12
- end
13
- end
1
+ require_relative '../spec_helper'
2
+ require_relative '../../lib/bioinform/cli'
3
+
4
+ describe Bioinform::CLI do
5
+ describe '.change_folder_and_extension' do
6
+ it 'should change extension and folder' do
7
+ extend Bioinform::CLI::Helpers
8
+ change_folder_and_extension('test.pcm', 'pwm', '.').should == './test.pwm'
9
+ change_folder_and_extension('test.pcm', 'pat', 'pwm_folder').should == 'pwm_folder/test.pat'
10
+ change_folder_and_extension('pcm/test.pcm', 'pat', 'pwm_folder').should == 'pwm_folder/test.pat'
11
+ change_folder_and_extension('test.pcm', 'pat', '../pwm_folder').should == '../pwm_folder/test.pat'
12
+ end
13
+ end
14
14
  end