macroape 3.2.2 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +28 -7
- data/lib/macroape.rb +14 -26
- data/lib/macroape/aligned_pair_intersection.rb +24 -24
- data/lib/macroape/collection.rb +1 -2
- data/lib/macroape/count_by_threshold.rb +8 -26
- data/lib/macroape/exec/eval_alignment.rb +19 -19
- data/lib/macroape/exec/eval_similarity.rb +18 -16
- data/lib/macroape/exec/find_pvalue.rb +8 -6
- data/lib/macroape/exec/find_threshold.rb +7 -5
- data/lib/macroape/exec/preprocess_collection.rb +10 -7
- data/lib/macroape/exec/scan_collection.rb +13 -10
- data/lib/macroape/pwm_compare.rb +33 -2
- data/lib/macroape/pwm_compare_aligned.rb +38 -2
- data/lib/macroape/threshold_by_pvalue.rb +48 -43
- data/lib/macroape/version.rb +3 -3
- data/macroape.gemspec +2 -0
- data/test/data/test_collection.yaml +70 -4
- data/test/eval_alignment_similarity_test.rb +19 -0
- data/test/eval_similarity_test.rb +26 -0
- data/test/find_pvalue_test.rb +25 -0
- data/test/find_threshold_test.rb +29 -0
- data/test/preprocess_collection_test.rb +9 -0
- data/test/scan_collection_test.rb +17 -0
- data/test/test_helper.rb +10 -0
- metadata +33 -16
- data/lib/macroape/aligned_pair_metrics.rb +0 -24
- data/lib/macroape/aligned_pair_transformations.rb +0 -23
- data/lib/macroape/extract_pwm.rb +0 -32
- data/lib/macroape/gauss_estimation.rb +0 -30
- data/lib/macroape/matrix_information.rb +0 -29
- data/lib/macroape/matrix_on_background.rb +0 -16
- data/lib/macroape/matrix_transformations.rb +0 -29
- data/lib/macroape/pair_metrics.rb +0 -9
- data/lib/macroape/pair_transformations.rb +0 -28
- data/lib/macroape/single_matrix.rb +0 -45
- data/lib/macroape/support.rb +0 -34
- data/test/macroape_test.rb +0 -125
@@ -1,45 +0,0 @@
|
|
1
|
-
module PWM
|
2
|
-
class SingleMatrix
|
3
|
-
attr_reader :matrix
|
4
|
-
attr_accessor :name
|
5
|
-
def initialize(matrix)
|
6
|
-
@matrix = matrix
|
7
|
-
end
|
8
|
-
include MatrixTransformations, MatrixInformation
|
9
|
-
|
10
|
-
def self.build_matrix(lines, name = nil)
|
11
|
-
pwm_name = name
|
12
|
-
begin
|
13
|
-
lines.first.split.each{|x| Float(x) }
|
14
|
-
start_line = 0
|
15
|
-
rescue
|
16
|
-
start_line = 1
|
17
|
-
pwm_name = lines.first.chomp.match(/(?:>\s)?(.*)$/)[1]
|
18
|
-
end
|
19
|
-
|
20
|
-
if lines[start_line].split.length == 4
|
21
|
-
pwm = SingleMatrix.new(lines[start_line..-1].map{|str| str.split.map(&:to_f)})
|
22
|
-
else
|
23
|
-
pwm = SingleMatrix.new(lines[start_line..-1].map{|str| str.split.map(&:to_f)}.transpose)
|
24
|
-
end
|
25
|
-
raise "PWM::SingleMatrix.build_matrix can't create matrix using this input" unless pwm.matrix.all?{|l| l.length == 4}
|
26
|
-
pwm.name = pwm_name
|
27
|
-
pwm
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.load_from_stdin(input_stream, name = nil)
|
31
|
-
build_matrix(input_stream.readlines, name)
|
32
|
-
end
|
33
|
-
def self.load_from_line_array(lines, name = nil)
|
34
|
-
build_matrix(lines, name)
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.load_pat(filename)
|
38
|
-
build_matrix( File.open(filename,'r'){|f| f.readlines}, File.basename_wo_ext(filename))
|
39
|
-
end
|
40
|
-
|
41
|
-
def with_background(background)
|
42
|
-
type_cast(MatrixOnBackground){@probabilities = background}.depth_dup
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
data/lib/macroape/support.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
module Kernel
|
2
|
-
def type_cast(new_class, &block)
|
3
|
-
new_obj = new_class.allocate
|
4
|
-
instance_variables.each do |varname|
|
5
|
-
new_obj.instance_variable_set(varname, self.instance_variable_get(varname))
|
6
|
-
end
|
7
|
-
new_obj.instance_eval(&block) if block_given?
|
8
|
-
new_obj
|
9
|
-
end
|
10
|
-
|
11
|
-
def depth_dup
|
12
|
-
begin
|
13
|
-
new_obj = self.dup
|
14
|
-
rescue
|
15
|
-
return self
|
16
|
-
end
|
17
|
-
new_obj.instance_variables.each do |varname|
|
18
|
-
begin
|
19
|
-
new_obj.instance_variable_set(varname, new_obj.instance_variable_get(varname).depth_dup)
|
20
|
-
rescue
|
21
|
-
end
|
22
|
-
end
|
23
|
-
new_obj
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
def File.filename_wo_ext(filename)
|
29
|
-
filename[0..-(1+File.extname(filename).length)]
|
30
|
-
end
|
31
|
-
|
32
|
-
def File.basename_wo_ext(filename)
|
33
|
-
File.basename(filename)[0..-(1+File.extname(filename).length)]
|
34
|
-
end
|
data/test/macroape_test.rb
DELETED
@@ -1,125 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
|
3
|
-
module Helpers
|
4
|
-
def self.obtain_pvalue_by_threshold(args)
|
5
|
-
IO.popen("find_pvalue #{args}",&:read).strip.split.last
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
class FindThresholdTest < Test::Unit::TestCase
|
10
|
-
def test_process_several_pvalues
|
11
|
-
pvalues = []
|
12
|
-
IO.popen('find_threshold test/data/KLF4_f2.pat -p 0.001 0.0005', &:read).lines.each{|line|
|
13
|
-
pvalue, threshold, real_pvalue = line.strip.split("\t")
|
14
|
-
pvalues << pvalue
|
15
|
-
assert_equal Helpers.obtain_pvalue_by_threshold("test/data/KLF4_f2.pat #{threshold}"), real_pvalue
|
16
|
-
}
|
17
|
-
assert_equal pvalues, ['0.0005', '0.001']
|
18
|
-
end
|
19
|
-
def test_process_one_pvalue
|
20
|
-
pvalue, threshold, real_pvalue = IO.popen('find_threshold test/data/KLF4_f2.pat -p 0.001', &:read).strip.split("\t")
|
21
|
-
assert_equal '0.001', pvalue
|
22
|
-
assert_equal Helpers.obtain_pvalue_by_threshold("test/data/KLF4_f2.pat #{threshold}"), real_pvalue
|
23
|
-
end
|
24
|
-
def test_process_default_pvalue
|
25
|
-
pvalue, threshold, real_pvalue = IO.popen('find_threshold test/data/KLF4_f2.pat', &:read).strip.split("\t")
|
26
|
-
assert_equal '0.0005', pvalue
|
27
|
-
assert_equal Helpers.obtain_pvalue_by_threshold("test/data/KLF4_f2.pat #{threshold}"), real_pvalue
|
28
|
-
end
|
29
|
-
def test_custom_discretization
|
30
|
-
pvalue, threshold, real_pvalue = IO.popen('find_threshold test/data/KLF4_f2.pat -d 100',&:read).strip.split("\t")
|
31
|
-
assert_equal '0.0005', pvalue
|
32
|
-
assert_equal Helpers.obtain_pvalue_by_threshold("test/data/KLF4_f2.pat #{threshold} -d 100"), real_pvalue
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
class FindPvalueTest < Test::Unit::TestCase
|
37
|
-
def test_process_one_threshold
|
38
|
-
IO.popen('find_pvalue test/data/KLF4_f2.pat 4.1719'){|f|
|
39
|
-
assert_equal "4.1719\t1048.0\t0.00099945068359375\n", f.read
|
40
|
-
}
|
41
|
-
end
|
42
|
-
def test_process_several_thresholds
|
43
|
-
IO.popen('find_pvalue test/data/KLF4_f2.pat 4.1719 5.2403'){|f|
|
44
|
-
assert_equal "4.1719\t1048.0\t0.00099945068359375\n5.2403\t524.0\t0.000499725341796875\n", f.read
|
45
|
-
}
|
46
|
-
end
|
47
|
-
def test_process_several_thresholds_result_is_ordered
|
48
|
-
IO.popen('find_pvalue test/data/KLF4_f2.pat 5.2403 4.1719'){|f|
|
49
|
-
assert_equal "5.2403\t524.0\t0.000499725341796875\n4.1719\t1048.0\t0.00099945068359375\n", f.read
|
50
|
-
}
|
51
|
-
end
|
52
|
-
def test_custom_discretization
|
53
|
-
IO.popen('find_pvalue test/data/KLF4_f2.pat 5.2403 -d 100'){|f|
|
54
|
-
assert_equal "5.2403\t527.0\t0.0005025863647460938\n", f.read
|
55
|
-
}
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
class TestEvalSimilarity < Test::Unit::TestCase
|
61
|
-
def test_process_pair_of_pwms
|
62
|
-
IO.popen('eval_similarity test/data/KLF4_f2.pat test/data/SP1_f1.pat'){|f|
|
63
|
-
assert_equal "0.2420758234928527\n779.0\t11\n.>>>>>>>>>>\n>>>>>>>>>>>\n-1\tdirect\n", f.read
|
64
|
-
}
|
65
|
-
end
|
66
|
-
def test_process_another_pair_of_pwms
|
67
|
-
IO.popen('eval_similarity test/data/SP1_f1.pat test/data/AHR_si.pat'){|f|
|
68
|
-
assert_equal "0.0037332005973120955\n15.0\t11\n>>>>>>>>>>>\n.>>>>>>>>>.\n1\tdirect\n", f.read
|
69
|
-
}
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_recognize_orientation_of_alignment
|
73
|
-
IO.popen('eval_similarity test/data/SP1_f1_revcomp.pat test/data/SP1_f1.pat'){|f|
|
74
|
-
assert_equal "1.0\n2033.0\t11\n>>>>>>>>>>>\n<<<<<<<<<<<\n0\trevcomp\n", f.read
|
75
|
-
}
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_process_custom_discretization
|
79
|
-
IO.popen('eval_similarity test/data/SP1_f1.pat test/data/KLF4_f2.pat -d 1'){|f|
|
80
|
-
assert_equal "0.22754919499105544\n636.0\t11\n>>>>>>>>>>>\n.>>>>>>>>>>\n1\tdirect\n", f.read
|
81
|
-
}
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
class TestEvalAlignmentSimilarity < Test::Unit::TestCase
|
86
|
-
def test_process_at_optimal_alignment
|
87
|
-
IO.popen('eval_alignment test/data/KLF4_f2.pat test/data/SP1_f1.pat -1 direct '){|f|
|
88
|
-
assert_equal "0.2420758234928527\n779.0\t11\n.>>>>>>>>>>\n>>>>>>>>>>>\n-1\tdirect\n", f.read
|
89
|
-
}
|
90
|
-
end
|
91
|
-
def test_process_not_optimal_alignment
|
92
|
-
IO.popen('eval_alignment test/data/KLF4_f2.pat test/data/SP1_f1.pat 0 direct '){|f|
|
93
|
-
assert_equal "0.0017543859649122807\n7.0\t11\n>>>>>>>>>>.\n>>>>>>>>>>>\n0\tdirect\n", f.read
|
94
|
-
}
|
95
|
-
end
|
96
|
-
def test_process_at_optimal_alignment_reversed
|
97
|
-
IO.popen('eval_alignment test/data/KLF4_f2.pat test/data/SP1_f1.pat -1 revcomp '){|f|
|
98
|
-
assert_equal "0.0\n0.0\t11\n.>>>>>>>>>>\n<<<<<<<<<<<\n-1\trevcomp\n", f.read
|
99
|
-
}
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
class TestPreprocessCollection < Test::Unit::TestCase
|
104
|
-
def test_multipvalue_preproceessing
|
105
|
-
system('preprocess_collection ./test/data/test_collection -o test/data/test_collection.yaml.tmp -p 0.0005 0.0001 0.00005 --silent')
|
106
|
-
assert_equal File.read('test/data/test_collection.yaml'), File.read('test/data/test_collection.yaml.tmp')
|
107
|
-
File.delete 'test/data/test_collection.yaml.tmp'
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
class TestScanCollection < Test::Unit::TestCase
|
112
|
-
def test_scan_default_cutoff
|
113
|
-
assert_equal File.read('test/data/KLF4_f2_scan_results_default_cutoff.txt'),
|
114
|
-
IO.popen('scan_collection test/data/KLF4_f2.pat test/data/test_collection.yaml --silent', &:read)
|
115
|
-
end
|
116
|
-
def test_scan_and_output_all_results
|
117
|
-
assert_equal File.read('test/data/KLF4_f2_scan_results_all.txt'),
|
118
|
-
IO.popen('scan_collection test/data/KLF4_f2.pat test/data/test_collection.yaml --all --silent', &:read)
|
119
|
-
|
120
|
-
end
|
121
|
-
def test_scan_precise_mode
|
122
|
-
assert_equal File.read('test/data/KLF4_f2_scan_results_precise_mode.txt'),
|
123
|
-
IO.popen('scan_collection test/data/KLF4_f2.pat test/data/test_collection.yaml --precise --all --silent', &:read)
|
124
|
-
end
|
125
|
-
end
|