bioinform 0.1.17 → 0.2.0
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.
- checksums.yaml +4 -4
- data/Gemfile +3 -3
- data/LICENSE +0 -1
- data/README.md +1 -1
- data/TODO.txt +23 -30
- data/bin/convert_motif +4 -0
- data/bin/pcm2pwm +1 -1
- data/bin/split_motifs +1 -1
- data/bioinform.gemspec +0 -2
- data/lib/bioinform.rb +54 -16
- data/lib/bioinform/alphabet.rb +85 -0
- data/lib/bioinform/background.rb +90 -0
- data/lib/bioinform/cli.rb +1 -2
- data/lib/bioinform/cli/convert_motif.rb +52 -17
- data/lib/bioinform/cli/pcm2pwm.rb +32 -26
- data/lib/bioinform/cli/split_motifs.rb +31 -30
- data/lib/bioinform/conversion_algorithms.rb +6 -0
- data/lib/bioinform/conversion_algorithms/pcm2ppm_converter.rb +13 -11
- data/lib/bioinform/conversion_algorithms/pcm2pwm_converter.rb +39 -11
- data/lib/bioinform/conversion_algorithms/pcm2pwm_mara_converter.rb +26 -0
- data/lib/bioinform/conversion_algorithms/ppm2pcm_converter.rb +30 -0
- data/lib/bioinform/conversion_algorithms/pwm2iupac_pwm_converter.rb +23 -0
- data/lib/bioinform/conversion_algorithms/pwm2pcm_converter.rb +85 -0
- data/lib/bioinform/data_models.rb +1 -7
- data/lib/bioinform/data_models/named_model.rb +38 -0
- data/lib/bioinform/data_models/pcm.rb +18 -28
- data/lib/bioinform/data_models/pm.rb +73 -170
- data/lib/bioinform/data_models/ppm.rb +11 -24
- data/lib/bioinform/data_models/pwm.rb +30 -56
- data/lib/bioinform/errors.rb +17 -0
- data/lib/bioinform/formatters.rb +4 -2
- data/lib/bioinform/formatters/consensus_formatter.rb +35 -0
- data/lib/bioinform/formatters/motif_formatter.rb +69 -0
- data/lib/bioinform/formatters/pretty_matrix_formatter.rb +36 -0
- data/lib/bioinform/formatters/transfac_formatter.rb +29 -37
- data/lib/bioinform/parsers.rb +1 -8
- data/lib/bioinform/parsers/matrix_parser.rb +44 -36
- data/lib/bioinform/parsers/motif_splitter.rb +45 -0
- data/lib/bioinform/support.rb +46 -14
- data/lib/bioinform/support/strip_doc.rb +1 -1
- data/lib/bioinform/version.rb +1 -1
- data/spec/alphabet_spec.rb +79 -0
- data/spec/background_spec.rb +57 -0
- data/spec/cli/cli_spec.rb +6 -6
- data/spec/cli/convert_motif_spec.rb +88 -88
- data/spec/cli/data/pcm2pwm/KLF4_f2.pwm.result +9 -9
- data/spec/cli/data/pcm2pwm/SP1_f1.pwm.result +11 -11
- data/spec/cli/pcm2pwm_spec.rb +22 -23
- data/spec/cli/shared_examples/convert_motif/motif_list_empty.rb +1 -1
- data/spec/cli/shared_examples/convert_motif/several_motifs_specified.rb +1 -1
- data/spec/cli/shared_examples/convert_motif/single_motif_specified.rb +5 -5
- data/spec/cli/shared_examples/convert_motif/yield_help_string.rb +2 -2
- data/spec/cli/shared_examples/convert_motif/yield_motif_conversion_error.rb +3 -3
- data/spec/cli/split_motifs_spec.rb +6 -21
- data/spec/converters/pcm2ppm_converter_spec.rb +32 -0
- data/spec/converters/pcm2pwm_converter_spec.rb +71 -0
- data/spec/converters/ppm2pcm_converter_spec.rb +32 -0
- data/spec/converters/pwm2iupac_pwm_converter_spec.rb +65 -0
- data/spec/converters/pwm2pcm_converter_spec.rb +57 -0
- data/spec/data_models/named_model_spec.rb +41 -0
- data/spec/data_models/pcm_spec.rb +114 -45
- data/spec/data_models/pm_spec.rb +132 -333
- data/spec/data_models/ppm_spec.rb +47 -44
- data/spec/data_models/pwm_spec.rb +85 -77
- data/spec/fabricators/motif_formats_fabricator.rb +116 -116
- data/spec/formatters/consensus_formatter_spec.rb +26 -0
- data/spec/formatters/raw_formatter_spec.rb +169 -0
- data/spec/parsers/matrix_parser_spec.rb +216 -0
- data/spec/parsers/motif_splitter_spec.rb +87 -0
- data/spec/spec_helper.rb +2 -2
- data/spec/spec_helper_source.rb +25 -5
- data/spec/support_spec.rb +31 -0
- metadata +43 -124
- data/bin/merge_into_collection +0 -4
- data/lib/bioinform/cli/merge_into_collection.rb +0 -80
- data/lib/bioinform/conversion_algorithms/ppm2pwm_converter.rb +0 -0
- data/lib/bioinform/data_models/collection.rb +0 -75
- data/lib/bioinform/data_models/motif.rb +0 -56
- data/lib/bioinform/formatters/raw_formatter.rb +0 -41
- data/lib/bioinform/parsers/jaspar_parser.rb +0 -35
- data/lib/bioinform/parsers/parser.rb +0 -92
- data/lib/bioinform/parsers/splittable_parser.rb +0 -57
- data/lib/bioinform/parsers/string_fantom_parser.rb +0 -35
- data/lib/bioinform/parsers/string_parser.rb +0 -72
- data/lib/bioinform/parsers/trivial_parser.rb +0 -34
- data/lib/bioinform/parsers/yaml_parser.rb +0 -35
- data/lib/bioinform/support/advanced_scan.rb +0 -8
- data/lib/bioinform/support/array_product.rb +0 -6
- data/lib/bioinform/support/array_zip.rb +0 -6
- data/lib/bioinform/support/collect_hash.rb +0 -7
- data/lib/bioinform/support/deep_dup.rb +0 -5
- data/lib/bioinform/support/delete_many.rb +0 -14
- data/lib/bioinform/support/inverf.rb +0 -13
- data/lib/bioinform/support/multiline_squish.rb +0 -6
- data/lib/bioinform/support/parameters.rb +0 -28
- data/lib/bioinform/support/partial_sums.rb +0 -16
- data/lib/bioinform/support/same_by.rb +0 -12
- data/lib/bioinform/support/third_part/active_support/core_ext/array/extract_options.rb +0 -29
- data/lib/bioinform/support/third_part/active_support/core_ext/hash/indifferent_access.rb +0 -23
- data/lib/bioinform/support/third_part/active_support/core_ext/hash/keys.rb +0 -54
- data/lib/bioinform/support/third_part/active_support/core_ext/module/attribute_accessors.rb +0 -64
- data/lib/bioinform/support/third_part/active_support/core_ext/object/try.rb +0 -57
- data/lib/bioinform/support/third_part/active_support/core_ext/string/access.rb +0 -99
- data/lib/bioinform/support/third_part/active_support/core_ext/string/behavior.rb +0 -6
- data/lib/bioinform/support/third_part/active_support/core_ext/string/filters.rb +0 -49
- data/lib/bioinform/support/third_part/active_support/core_ext/string/multibyte.rb +0 -72
- data/lib/bioinform/support/third_part/active_support/hash_with_indifferent_access.rb +0 -181
- data/lib/bioinform/support/third_part/active_support/multibyte.rb +0 -44
- data/lib/bioinform/support/third_part/active_support/multibyte/chars.rb +0 -476
- data/lib/bioinform/support/third_part/active_support/multibyte/exceptions.rb +0 -8
- data/lib/bioinform/support/third_part/active_support/multibyte/unicode.rb +0 -393
- data/lib/bioinform/support/third_part/active_support/multibyte/utils.rb +0 -60
- data/spec/cli/data/merge_into_collection/GABPA_f1.pwm +0 -14
- data/spec/cli/data/merge_into_collection/KLF4_f2.pwm +0 -11
- data/spec/cli/data/merge_into_collection/SP1_f1.pwm +0 -12
- data/spec/cli/data/merge_into_collection/collection.txt.result +0 -40
- data/spec/cli/data/merge_into_collection/collection.yaml.result +0 -188
- data/spec/cli/data/merge_into_collection/collection_pwm.yaml.result +0 -188
- data/spec/cli/data/merge_into_collection/pwm_folder/GABPA_f1.pwm +0 -14
- data/spec/cli/data/merge_into_collection/pwm_folder/KLF4_f2.pwm +0 -11
- data/spec/cli/data/merge_into_collection/pwm_folder/SP1_f1.pwm +0 -12
- data/spec/cli/data/split_motifs/collection.yaml +0 -188
- data/spec/cli/merge_into_collection_spec.rb +0 -100
- data/spec/data_models/collection_spec.rb +0 -98
- data/spec/data_models/motif_spec.rb +0 -224
- data/spec/fabricators/collection_fabricator.rb +0 -8
- data/spec/fabricators/motif_fabricator.rb +0 -33
- data/spec/fabricators/pcm_fabricator.rb +0 -25
- data/spec/fabricators/pm_fabricator.rb +0 -52
- data/spec/fabricators/ppm_fabricator.rb +0 -14
- data/spec/fabricators/pwm_fabricator.rb +0 -16
- data/spec/parsers/parser_spec.rb +0 -152
- data/spec/parsers/string_fantom_parser_spec.rb +0 -70
- data/spec/parsers/string_parser_spec.rb +0 -77
- data/spec/parsers/trivial_parser_spec.rb +0 -64
- data/spec/parsers/yaml_parser_spec.rb +0 -50
- data/spec/support/advanced_scan_spec.rb +0 -32
- data/spec/support/array_product_spec.rb +0 -15
- data/spec/support/array_zip_spec.rb +0 -15
- data/spec/support/collect_hash_spec.rb +0 -15
- data/spec/support/delete_many_spec.rb +0 -44
- data/spec/support/inverf_spec.rb +0 -19
- data/spec/support/multiline_squish_spec.rb +0 -25
- data/spec/support/partial_sums_spec.rb +0 -30
- data/spec/support/same_by_spec.rb +0 -36
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
require_relative '../spec_helper'
|
|
2
|
-
require_relative '../../lib/bioinform/parsers/parser'
|
|
3
|
-
require_relative '../../lib/bioinform/data_models/collection'
|
|
4
|
-
|
|
5
|
-
module Bioinform
|
|
6
|
-
describe TrivialParser do
|
|
7
|
-
context '.new' do
|
|
8
|
-
it 'should take the only input argument' do
|
|
9
|
-
TrivialParser.instance_method(:initialize).arity.should == 1
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
context '#parse!' do
|
|
14
|
-
it 'should return OpenStruct based on input of that was passed to initialize when input is a Hash' do
|
|
15
|
-
TrivialParser.new(matrix: 'stub matrix', name: 'stub name').parse!.should == OpenStruct.new(matrix: 'stub matrix', name: 'stub name')
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it 'should return OpenStruct based on input of that was passed to initialize when input is a OpenStruct' do
|
|
19
|
-
TrivialParser.new(OpenStruct.new(matrix: 'stub matrix', name: 'stub name')).parse!.should == OpenStruct.new(matrix: 'stub matrix', name: 'stub name')
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
context '.split_on_motifs' do
|
|
24
|
-
it 'should be able to get a single PM' do
|
|
25
|
-
TrivialParser.split_on_motifs({matrix: [[1,2,3,4],[5,6,7,8]], name: 'Name'}, PM).should == [ PM.new(matrix: [[1,2,3,4],[5,6,7,8]], name:'Name') ]
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it 'can be used to create PM with {matrix: ..., name: ...} form' do
|
|
30
|
-
pm = PM.new({matrix: [[1,2,3,4],[5,6,7,8]], name: 'Name'}, TrivialParser)
|
|
31
|
-
pm.matrix.should == [[1,2,3,4],[5,6,7,8]]
|
|
32
|
-
pm.name.should == 'Name'
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
it 'can be used to create PM from PM (make copy)' do
|
|
36
|
-
pm = Fabricate(:pm)
|
|
37
|
-
pm_copy = PM.new(pm, TrivialParser)
|
|
38
|
-
pm_copy.should == pm
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
describe TrivialCollectionParser do
|
|
43
|
-
let(:collection){ Fabricate(:three_elements_collection) }
|
|
44
|
-
let(:pm_1){ Fabricate(:pm_1) }
|
|
45
|
-
let(:pm_2){ Fabricate(:pm_2) }
|
|
46
|
-
let(:pm_3){ Fabricate(:pm_3) }
|
|
47
|
-
|
|
48
|
-
describe '#parse!' do
|
|
49
|
-
it 'can be used to obtain PMs from Collection' do
|
|
50
|
-
@parser = TrivialCollectionParser.new(collection)
|
|
51
|
-
@parser.parse!.should == pm_1
|
|
52
|
-
@parser.parse!.should == pm_2
|
|
53
|
-
@parser.parse!.should == pm_3
|
|
54
|
-
expect{ @parser.parse! }.to raise_error
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
describe '.split_on_motifs' do
|
|
59
|
-
it 'should be able to split collection into PMs' do
|
|
60
|
-
TrivialCollectionParser.split_on_motifs(collection).should == [pm_1, pm_2, pm_3]
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
require 'yaml'
|
|
2
|
-
require_relative '../spec_helper'
|
|
3
|
-
require_relative '../../lib/bioinform/parsers/yaml_parser'
|
|
4
|
-
require_relative '../../lib/bioinform/data_models/collection'
|
|
5
|
-
|
|
6
|
-
module Bioinform
|
|
7
|
-
describe YAMLParser do
|
|
8
|
-
context '#parse!' do
|
|
9
|
-
it 'should return PM that was encoded in YAML format' do
|
|
10
|
-
pm = Fabricate(:pm)
|
|
11
|
-
parser = YAMLParser.new(pm.to_yaml)
|
|
12
|
-
parser.parse!.should == pm
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
it 'can be used to create PM from yaml-string' do
|
|
16
|
-
pm = Fabricate(:pm)
|
|
17
|
-
pm_copy = PM.new(pm.to_yaml, YAMLParser)
|
|
18
|
-
pm_copy.should == pm
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
context '::split_on_motifs' do
|
|
22
|
-
it 'should be able to get a single PM' do
|
|
23
|
-
pm = Fabricate(:pm)
|
|
24
|
-
YAMLParser.split_on_motifs(pm.to_yaml, PM).should == [ pm ]
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
describe YAMLCollectionParser do
|
|
30
|
-
let(:yamled_collection){ Fabricate(:three_elements_collection).to_yaml }
|
|
31
|
-
let(:pm_1){ Fabricate(:pm_1) }
|
|
32
|
-
let(:pm_2){ Fabricate(:pm_2) }
|
|
33
|
-
let(:pm_3){ Fabricate(:pm_3) }
|
|
34
|
-
|
|
35
|
-
context '::split_on_motifs' do
|
|
36
|
-
it 'should be able to split yamled collection into PMs' do
|
|
37
|
-
YAMLCollectionParser.split_on_motifs(yamled_collection).should == [pm_1, pm_2, pm_3]
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
context '#parse!' do
|
|
41
|
-
it 'should return PMs which were in encoded YAML format' do
|
|
42
|
-
@parser = YAMLCollectionParser.new(yamled_collection)
|
|
43
|
-
@parser.parse!.should == pm_1
|
|
44
|
-
@parser.parse!.should == pm_2
|
|
45
|
-
@parser.parse!.should == pm_3
|
|
46
|
-
expect{ @parser.parse! }.to raise_error
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
require_relative '../spec_helper'
|
|
2
|
-
require_relative '../../lib/bioinform/support/advanced_scan'
|
|
3
|
-
|
|
4
|
-
describe StringScanner do
|
|
5
|
-
context '#advanced_scan' do
|
|
6
|
-
before do
|
|
7
|
-
@scanner = StringScanner.new('abcde fghIJKLmnop')
|
|
8
|
-
end
|
|
9
|
-
it 'should return nil if text doesn\'t match. Pointer should not move' do
|
|
10
|
-
@scanner.advanced_scan(/\s\s\s/).should be_nil
|
|
11
|
-
@scanner.pos.should == 0
|
|
12
|
-
end
|
|
13
|
-
it 'should return MatchData if string Matches. Pointer should move' do
|
|
14
|
-
@scanner.advanced_scan(/\w\w\w/).should be_kind_of MatchData
|
|
15
|
-
@scanner.pos.should == 3
|
|
16
|
-
end
|
|
17
|
-
it 'should return have the same groups as regexp has' do
|
|
18
|
-
result = @scanner.advanced_scan(/(\w+)(\s+)([a-z]+)([A-Z]+)/)
|
|
19
|
-
result[0].should == 'abcde fghIJKL'
|
|
20
|
-
result[1].should == 'abcde'
|
|
21
|
-
result[2].should == ' '
|
|
22
|
-
result[3].should == 'fgh'
|
|
23
|
-
result[4].should == 'IJKL'
|
|
24
|
-
end
|
|
25
|
-
it 'should return have the same named groups as regexp has' do
|
|
26
|
-
result = @scanner.advanced_scan(/(\w+)(\s+)(?<word_downcase>[a-z]+)(?<word_upcase>[A-Z]+)/)
|
|
27
|
-
result[0].should == 'abcde fghIJKL'
|
|
28
|
-
result[:word_downcase].should == 'fgh'
|
|
29
|
-
result[:word_upcase].should == 'IJKL'
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
require_relative '../spec_helper'
|
|
2
|
-
require_relative '../../lib/bioinform/support/array_product'
|
|
3
|
-
|
|
4
|
-
describe Array do
|
|
5
|
-
context '::product' do
|
|
6
|
-
it 'should take any number of arrays and product them as if #product was made to first and others' do
|
|
7
|
-
Array.product([1,2,3]).should == [1,2,3].product()
|
|
8
|
-
Array.product([1,2,3],[4,5,6]).should == [1,2,3].product([4,5,6])
|
|
9
|
-
Array.product([1,2,3],[4,5,6],[7,8,9]).should == [1,2,3].product([4,5,6],[7,8,9])
|
|
10
|
-
end
|
|
11
|
-
it 'should return empty array if no arrays\'re given' do
|
|
12
|
-
Array.product().should == []
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
require_relative '../spec_helper'
|
|
2
|
-
require_relative '../../lib/bioinform/support/array_zip'
|
|
3
|
-
|
|
4
|
-
describe Array do
|
|
5
|
-
context '::zip' do
|
|
6
|
-
it 'should take any number of arrays and zip them as if #zip was made to first and others' do
|
|
7
|
-
Array.zip([1,2,3]).should == [1,2,3].zip()
|
|
8
|
-
Array.zip([1,2,3],[4,5,6]).should == [1,2,3].zip([4,5,6])
|
|
9
|
-
Array.zip([1,2,3],[4,5,6],[7,8,9]).should == [1,2,3].zip([4,5,6],[7,8,9])
|
|
10
|
-
end
|
|
11
|
-
it 'should return empty array if no arrays\'re given' do
|
|
12
|
-
Array.zip().should == []
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
require_relative '../spec_helper'
|
|
2
|
-
require_relative '../../lib/bioinform/support/collect_hash'
|
|
3
|
-
|
|
4
|
-
describe Enumerable do
|
|
5
|
-
# %w{A C G T}.collect_hash{|k| [k*2, k*3] }
|
|
6
|
-
# # ==> {"AA" => "AAA", "CC" => "CCC", "GG" => "GGG", "TT" => "TTT"}
|
|
7
|
-
context '#collect_hash' do
|
|
8
|
-
it 'should take a block and create a hash from collected [k,v] pairs' do
|
|
9
|
-
%w{A C G T}.collect_hash{|k| [k*2, k*3] }.should == {"AA" => "AAA", "CC" => "CCC", "GG" => "GGG", "TT" => "TTT"}
|
|
10
|
-
end
|
|
11
|
-
it 'should create a hash from yielded [k,v] pairs if block not given' do
|
|
12
|
-
%w{A C G T}.each_with_index.collect_hash.should == {"A" => 0, "C" => 1, "G" => 2, "T" => 3}
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
require_relative '../spec_helper'
|
|
2
|
-
require_relative '../../lib/bioinform/support/delete_many'
|
|
3
|
-
|
|
4
|
-
describe Array do
|
|
5
|
-
before :each do
|
|
6
|
-
@arr = %w{a b c d e f g h i j b b}
|
|
7
|
-
end
|
|
8
|
-
describe '#delete_at_many' do
|
|
9
|
-
it 'should delete elements at specified indices when indices in ascending order' do
|
|
10
|
-
@arr.delete_at_many(1,3,7)
|
|
11
|
-
@arr.should == %w{a c e f g i j b b}
|
|
12
|
-
end
|
|
13
|
-
it 'should delete elements at specified indices when indices in descending order' do
|
|
14
|
-
@arr.delete_at_many(7,3,1)
|
|
15
|
-
@arr.should == %w{a c e f g i j b b}
|
|
16
|
-
end
|
|
17
|
-
it 'should delete elements at specified indices when indices in arbitrary order' do
|
|
18
|
-
@arr.delete_at_many(3,1,7)
|
|
19
|
-
@arr.should == %w{a c e f g i j b b}
|
|
20
|
-
end
|
|
21
|
-
it 'should delete at each index once' do
|
|
22
|
-
@arr.delete_at_many(0,0,0,2,0)
|
|
23
|
-
@arr.should == %w{b d e f g h i j b b}
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
describe '#delete_many' do
|
|
27
|
-
it 'should delete multiple elements with specified values' do
|
|
28
|
-
@arr.delete_many('b', 'd', 'h', 'b')
|
|
29
|
-
@arr.should == %w{a c e f g i j}
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
describe Hash do
|
|
35
|
-
before :each do
|
|
36
|
-
@arr = {A: 3, T: 6, G: 4, C: 5}
|
|
37
|
-
end
|
|
38
|
-
describe '#delete_many' do
|
|
39
|
-
it 'should delete specified keys' do
|
|
40
|
-
@arr.delete_many(:T, :C, :F, :T, :T)
|
|
41
|
-
@arr.should == {A: 3, G: 4}
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
data/spec/support/inverf_spec.rb
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
require_relative '../spec_helper'
|
|
2
|
-
require_relative '../../lib/bioinform/support/inverf'
|
|
3
|
-
|
|
4
|
-
describe 'Math#inverf' do
|
|
5
|
-
it 'should be erf(inverf(x)) == x' do
|
|
6
|
-
rng = (-0.9..0.9).step(0.1)
|
|
7
|
-
arr = rng.to_a
|
|
8
|
-
arr2 = rng.map{|x| Math.inverf(x)}.map{|x| Math.erf(x)}
|
|
9
|
-
delta = arr.each_index.map{|i| (arr[i] - arr2[i]).abs }
|
|
10
|
-
delta.each{|el| el.should <= 0.001}
|
|
11
|
-
end
|
|
12
|
-
it 'should be erf(inverf(x)) == x' do
|
|
13
|
-
rng = (-5..5).step(1)
|
|
14
|
-
arr = rng.to_a
|
|
15
|
-
arr2 = rng.map{|x| Math.erf(x)}.map{|x| Math.inverf(x)}
|
|
16
|
-
delta = arr.each_index.map{|i| (arr[i] - arr2[i]).abs }
|
|
17
|
-
delta.each{|el| el.should <= 0.01}
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
require_relative '../spec_helper'
|
|
2
|
-
require_relative '../../lib/bioinform/support/multiline_squish'
|
|
3
|
-
|
|
4
|
-
describe String do
|
|
5
|
-
describe '#multiline_squish' do
|
|
6
|
-
it 'should replace multiple spaces with one space' do
|
|
7
|
-
"abc def ghi\n jk lmn".multiline_squish.should == "abc def ghi\njk lmn"
|
|
8
|
-
end
|
|
9
|
-
it 'should replace tabs with a space' do
|
|
10
|
-
"abc\tdef ghi \t jk".multiline_squish.should == 'abc def ghi jk'
|
|
11
|
-
end
|
|
12
|
-
it 'should replace \r\n with \n' do
|
|
13
|
-
"abc def ghi\r\njk lmn".multiline_squish.should == "abc def ghi\njk lmn"
|
|
14
|
-
end
|
|
15
|
-
it 'should preserve rows pagination' do
|
|
16
|
-
"abc def ghi\njk lmn".multiline_squish.should == "abc def ghi\njk lmn"
|
|
17
|
-
end
|
|
18
|
-
it 'should preserve empty lines in the middle of text' do
|
|
19
|
-
"abc def\n\nghi\n \t \njk lmn \n\n\n zzz".multiline_squish.should == "abc def\n\nghi\n\njk lmn\n\n\nzzz"
|
|
20
|
-
end
|
|
21
|
-
it 'should drop empty lines at begin and at end of string' do
|
|
22
|
-
"\n \t\n\nabc def\n\nghi\n \t \njk lmn \n\n\n zzz\n\n \t \n".multiline_squish.should == "abc def\n\nghi\n\njk lmn\n\n\nzzz"
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
require_relative '../spec_helper'
|
|
2
|
-
require_relative '../../lib/bioinform/support/partial_sums'
|
|
3
|
-
|
|
4
|
-
describe 'Array#partial_sums' do
|
|
5
|
-
context 'when no initial value given' do
|
|
6
|
-
it 'should return an array of the same size with partial sums of elements 0..ind inclusive with float elements' do
|
|
7
|
-
[2,3,4,5].partial_sums.should == [2, 5, 9, 14]
|
|
8
|
-
[2,3,4,5].partial_sums.last.should be_kind_of(Float)
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
it 'should start counting from argument when it\'s given. Type of values depends on type of initial value' do
|
|
12
|
-
[2,3,4,5].partial_sums(100).should == [102,105,109,114]
|
|
13
|
-
[2,3,4,5].partial_sums(100).last.should be_kind_of(Integer)
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
{1 => 5, 4 => 3, 3 => 2}.partial_sums == {1=>5, 3=>7, 4=>10}
|
|
18
|
-
|
|
19
|
-
describe 'Hash#partial_sums' do
|
|
20
|
-
context 'when no initial value given' do
|
|
21
|
-
it 'should return a hash with float values of the same size with partial sums of elements that has keys <= than argument' do
|
|
22
|
-
{1 => 5, 4 => 3, 3 => 2}.partial_sums.should == {1=>5, 3=>7, 4=>10}
|
|
23
|
-
{1 => 5, 4 => 3, 3 => 2}.partial_sums.values.last.should be_kind_of(Float)
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
it 'should start counting from argument when it\'s given. Type of values depends on type of initial value' do
|
|
27
|
-
{1 => 5, 4 => 3, 3 => 2}.partial_sums(100).should == {1=>105, 3=>107, 4=>110}
|
|
28
|
-
{1 => 5, 4 => 3, 3 => 2}.partial_sums(100).values.last.should be_kind_of(Integer)
|
|
29
|
-
end
|
|
30
|
-
end
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
require_relative '../spec_helper'
|
|
2
|
-
require_relative '../../lib/bioinform/support/same_by'
|
|
3
|
-
|
|
4
|
-
describe Enumerable do
|
|
5
|
-
describe '#same_by?' do
|
|
6
|
-
it 'should be work with both hashes and arrays' do
|
|
7
|
-
['a','b','c'].same_by?{|k| k.length}
|
|
8
|
-
{'a'=>13,'b'=>12,'c'=>14}.same_by?{|k,v| v < 20}
|
|
9
|
-
end
|
|
10
|
-
it 'should be true for empty collections' do
|
|
11
|
-
[].same_by?(&:length).should be_true
|
|
12
|
-
[].same_by?.should be_true
|
|
13
|
-
end
|
|
14
|
-
context 'without block' do
|
|
15
|
-
it 'should compare if all elements of collection are the same' do
|
|
16
|
-
%w{cat cat cat}.same_by?.should be_true
|
|
17
|
-
%w{cat dog rat}.same_by?.should be_false
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
context 'with a block' do
|
|
21
|
-
it 'should compare enumerables by a value of block' do
|
|
22
|
-
%w{cat dog rat}.same_by?(&:length).should be_true
|
|
23
|
-
%w{cat dog rabbit}.same_by?(&:length).should be_false
|
|
24
|
-
end
|
|
25
|
-
it 'should be true if all elements are true' do
|
|
26
|
-
[4,8,2,2].same_by?(&:even?).should be_true
|
|
27
|
-
end
|
|
28
|
-
it 'should be true if all elements are false' do
|
|
29
|
-
[1,3,9,7].same_by?(&:even?).should be_true
|
|
30
|
-
end
|
|
31
|
-
it 'should be false if some elements are true and some are false' do
|
|
32
|
-
[1,8,3,2].same_by?(&:even?).should be_false
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|