rbbt-util 5.6.13 → 5.6.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/rbbt +14 -2
- data/lib/rbbt/util/misc.rb +24 -7
- data/lib/rbbt/util/simpleopt/parse.rb +3 -3
- data/lib/rbbt/workflow.rb +2 -2
- data/share/rbbt_commands/tsv/change_id +41 -5
- data/share/rbbt_commands/workflow/jobs +15 -0
- data/share/rbbt_commands/workflow/task +1 -1
- data/test/rbbt/util/test_misc.rb +44 -38
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e0c8c6ded43303be8e60d1b3f296c01a7eb71d9
|
4
|
+
data.tar.gz: 16641eeaa05112c42e6d4cbf19225a241f838910
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cbac69ebc91242fb6a0343a082a7e90d4bb1746b93b2af1b750e71a14745f77256351f539223da2ffc3918a1270410c8bdd4d5efaa590e83fbcbff60fe19742
|
7
|
+
data.tar.gz: de45c205481873a3d514e160275fa22a6182d2862796d09c1cb6e54009645ee29dc8d132dc739282fb09adc45bfb0f6ce089047f61089876db5d57b34e9565ba
|
data/bin/rbbt
CHANGED
@@ -33,13 +33,19 @@ Known locations are: #{([$rbbt_command_dir] + $rbbt_command_dir.find_all) * ", "
|
|
33
33
|
You can place your own commads at #{$rbbt_command_dir.find(:user)}.
|
34
34
|
EOF
|
35
35
|
|
36
|
-
def
|
36
|
+
def prev_dir(prev)
|
37
37
|
rbbt_command_dir = $rbbt_command_dir
|
38
38
|
|
39
39
|
prev.each do |previous_command|
|
40
40
|
rbbt_command_dir = rbbt_command_dir[previous_command]
|
41
41
|
end
|
42
42
|
|
43
|
+
rbbt_command_dir
|
44
|
+
end
|
45
|
+
|
46
|
+
def commands(prev)
|
47
|
+
rbbt_command_dir = prev_dir(prev)
|
48
|
+
|
43
49
|
command_file_dirs = rbbt_command_dir.find_all
|
44
50
|
command_files = command_file_dirs.collect{|d| d.glob('*') }.flatten
|
45
51
|
command_files.collect{|p| File.basename(p) }.uniq.reject{|p| p =~ /\.desc$/}.sort
|
@@ -59,8 +65,14 @@ def rbbt_usage(prev = nil)
|
|
59
65
|
puts
|
60
66
|
puts Log.color :magenta, "Subcommands:"
|
61
67
|
puts
|
68
|
+
prev_dir = prev_dir(prev)
|
62
69
|
commands(prev).each do |command|
|
63
|
-
|
70
|
+
directory = File.directory? prev_dir[command].find
|
71
|
+
if directory
|
72
|
+
puts " " << Log.color(:blue, command)
|
73
|
+
else
|
74
|
+
puts " " << command
|
75
|
+
end
|
64
76
|
end
|
65
77
|
end
|
66
78
|
puts
|
data/lib/rbbt/util/misc.rb
CHANGED
@@ -917,15 +917,32 @@ end
|
|
917
917
|
html
|
918
918
|
end
|
919
919
|
|
920
|
+
#def self.path_relative_to(basedir, path)
|
921
|
+
# path = File.expand_path(path) unless path[0] == "/"
|
922
|
+
# basedir = File.expand_path(basedir) unless basedir[0] == "/"
|
923
|
+
|
924
|
+
# basedir << "/" unless basedir[-1] == "/"
|
925
|
+
# case
|
926
|
+
# when path == basedir
|
927
|
+
# "."
|
928
|
+
# #when path =~ /#{Regexp.quote basedir}\/(.*)/
|
929
|
+
# when path.index(basedir) == 0
|
930
|
+
# return path[basedir.length..-1]
|
931
|
+
# else
|
932
|
+
# return nil
|
933
|
+
# end
|
934
|
+
#end
|
935
|
+
|
920
936
|
def self.path_relative_to(basedir, path)
|
921
|
-
path = File.expand_path(path)
|
922
|
-
basedir = File.expand_path(basedir)
|
937
|
+
path = File.expand_path(path) unless path[0] == "/"
|
938
|
+
basedir = File.expand_path(basedir) unless basedir[0] == "/"
|
923
939
|
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
940
|
+
if path.index(basedir) == 0
|
941
|
+
if basedir[-1] == "/"
|
942
|
+
return path[basedir.length..-1]
|
943
|
+
else
|
944
|
+
return path[basedir.length+1..-1]
|
945
|
+
end
|
929
946
|
else
|
930
947
|
return nil
|
931
948
|
end
|
@@ -7,14 +7,14 @@ module SOPT
|
|
7
7
|
current = [chars.shift]
|
8
8
|
short = current * ""
|
9
9
|
|
10
|
-
if shortcuts.include? short and long.index "-" or long.index "_"
|
10
|
+
if (shortcuts.include?(short) and not shortcuts[short] == long) and long.index "-" or long.index "_"
|
11
11
|
parts = long.split(/[_-]/)
|
12
12
|
acc = parts.collect{|s| s[0] } * ""
|
13
13
|
return acc unless shortcuts.include? acc
|
14
14
|
end
|
15
15
|
|
16
|
-
while shortcuts.include? short
|
17
|
-
while shortcuts[short].index current * ""
|
16
|
+
while shortcuts.include?(short) and not shortcuts[short] == long
|
17
|
+
while (long.length - current.length > 2) and shortcuts[short].index current * ""
|
18
18
|
next_letter = chars.shift
|
19
19
|
return nil if next_letter.nil?
|
20
20
|
current << next_letter
|
data/lib/rbbt/workflow.rb
CHANGED
@@ -259,8 +259,8 @@ module Workflow
|
|
259
259
|
end
|
260
260
|
|
261
261
|
def jobs(taskname, query = nil)
|
262
|
-
task_dir = File.join(workdir.find, taskname.to_s)
|
263
|
-
pattern = File.join(task_dir, '**/*')
|
262
|
+
task_dir = File.join(File.expand_path(workdir.find), taskname.to_s)
|
263
|
+
pattern = File.join(File.expand_path(task_dir), '**/*')
|
264
264
|
job_info_files = Dir.glob(Step.info_file(pattern)).collect{|f| Misc.path_relative_to task_dir, f }
|
265
265
|
job_info_files = job_info_files.select{|f| f.index(query) == 0 } if query
|
266
266
|
job_info_files.collect{|f|
|
@@ -2,14 +2,50 @@
|
|
2
2
|
|
3
3
|
require 'rbbt-util'
|
4
4
|
require 'rbbt/util/simpleopt'
|
5
|
+
require 'rbbt/sources/organism'
|
5
6
|
|
7
|
+
options = SOPT.get("-f--file* File to process:-f--field* Field to change:-t--target* Target format:-i--identifiers* Identifier file to use")
|
6
8
|
|
7
|
-
file =
|
8
|
-
|
9
|
-
|
9
|
+
raise ParameterException, "No file given" unless file = options[:file]
|
10
|
+
raise ParameterException, "No field given" unless field = options[:field]
|
11
|
+
raise ParameterException, "No target given" unless target = options[:target]
|
10
12
|
|
13
|
+
identifiers = options[:identifiers] || Organism.identifiers("Hsa").find
|
11
14
|
|
12
|
-
|
15
|
+
begin
|
16
|
+
index = TSV.index(identifiers, :persist => true, :target => target, :merge => true)
|
17
|
+
rescue
|
18
|
+
raise ParameterException, "Could not build index for '#{target}': #{ identifiers }"
|
19
|
+
end
|
13
20
|
|
14
|
-
|
21
|
+
tsv = TSV.open file
|
15
22
|
|
23
|
+
tsv.process field do |value|
|
24
|
+
if Array === value
|
25
|
+
index.values_at *value
|
26
|
+
else
|
27
|
+
index[value]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
tsv.fields = tsv.fields.collect{|f| f == field ? target : f}
|
32
|
+
|
33
|
+
puts tsv
|
34
|
+
|
35
|
+
exit
|
36
|
+
|
37
|
+
#stream = Open.open file
|
38
|
+
#header = TSV.parse_header stream
|
39
|
+
#field_pos = header.all_fields.index field
|
40
|
+
#raise ParameterException, "Unknown field: #{ field }" unless field_pos
|
41
|
+
#
|
42
|
+
#out = STDOUT
|
43
|
+
#out.puts TSV.header_lines :fields => header.fields, :key_field =
|
44
|
+
#while line = stream.gets do
|
45
|
+
# if line =~ /^#/
|
46
|
+
# out.puts line
|
47
|
+
# next
|
48
|
+
# else
|
49
|
+
# end
|
50
|
+
#end
|
51
|
+
#
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rbbt/workflow'
|
4
|
+
|
5
|
+
dir = ARGV.shift || '.'
|
6
|
+
|
7
|
+
all_files = Dir.glob(File.join(dir, '*'))
|
8
|
+
info_files = Dir.glob(File.join(dir, Step.info_file('*')))
|
9
|
+
file_dirs = Dir.glob(File.join(dir, Step.files_dir('*')))
|
10
|
+
|
11
|
+
jobs = (all_files - info_files - file_dirs)
|
12
|
+
|
13
|
+
jobs.reject!{|j| j =~ /\.lock/ }
|
14
|
+
|
15
|
+
puts jobs * "\n"
|
data/test/rbbt/util/test_misc.rb
CHANGED
@@ -6,12 +6,12 @@ require 'rbbt/entity'
|
|
6
6
|
|
7
7
|
class TestMisc < Test::Unit::TestCase
|
8
8
|
|
9
|
-
def
|
9
|
+
def _test_parse_cmd_params
|
10
10
|
ddd Misc.parse_cmd_params("workflow task Translation translate -f 'Associated Gene Name' -l -")
|
11
11
|
end
|
12
12
|
|
13
13
|
|
14
|
-
def
|
14
|
+
def _test_fixutf8
|
15
15
|
string = "abc\xffdef"
|
16
16
|
string = string.force_encoding("UTF-8") if string.respond_to? :force_encoding
|
17
17
|
assert(! string.valid_encoding?) if string.respond_to? :valid_encoding?
|
@@ -20,37 +20,37 @@ class TestMisc < Test::Unit::TestCase
|
|
20
20
|
assert( Misc.fixutf8(string).valid_encoding) if string.respond_to? :valid_encoding
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
23
|
+
def _test_colors_for
|
24
24
|
colors, used = Misc.colors_for([1,2,2,1,2,1,2,2,3,3,2,3,2])
|
25
25
|
assert_equal Misc::COLOR_LIST[1], used[2]
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
28
|
+
def _test_total_length
|
29
29
|
ranges = [(0..100), (50..150), (120..160)]
|
30
30
|
ranges = [(0..100), (50..150), (120..160), (51..70)]
|
31
31
|
assert_equal 161, Misc.total_length(ranges)
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
34
|
+
def _test_id_filename?
|
35
35
|
TmpFile.with_file("") do |file|
|
36
36
|
assert Misc.is_filename?(file)
|
37
37
|
assert ! Misc.is_filename?("TEST STRING")
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
def
|
41
|
+
def _test_merge_sorted_arrays
|
42
42
|
assert_equal [1,2,3,4], Misc.merge_sorted_arrays([1,3], [2,4])
|
43
43
|
end
|
44
44
|
|
45
|
-
def
|
45
|
+
def _test_intersect_sorted_arrays
|
46
46
|
assert_equal [2,4], Misc.intersect_sorted_arrays([1,2,3,4], [2,4])
|
47
47
|
end
|
48
48
|
|
49
|
-
def
|
49
|
+
def _test_sorted_array_matches
|
50
50
|
assert_equal [1,3], Misc.sorted_array_hits(%w(a b c d e), %w(b d))
|
51
51
|
end
|
52
52
|
|
53
|
-
def
|
53
|
+
def _test_binary_include?
|
54
54
|
a = %w(a b c d e).sort
|
55
55
|
assert Misc.binary_include?(a, "a")
|
56
56
|
assert(!Misc.binary_include?(a, "z"))
|
@@ -59,24 +59,24 @@ class TestMisc < Test::Unit::TestCase
|
|
59
59
|
assert(Misc.binary_include?(a, "d"))
|
60
60
|
end
|
61
61
|
|
62
|
-
def
|
62
|
+
def _test_process_to_hash
|
63
63
|
list = [1,2,3,4]
|
64
64
|
assert_equal 4, Misc.process_to_hash(list){|l| l.collect{|e| e * 2}}[2]
|
65
65
|
end
|
66
66
|
|
67
|
-
# def
|
67
|
+
# def _test_pdf2text_example
|
68
68
|
# assert PDF2Text.pdf2text(datafile_test('example.pdf')).read =~ /An Example Paper/i
|
69
69
|
# end
|
70
70
|
#
|
71
|
-
# def
|
71
|
+
# def _test_pdf2text_EPAR
|
72
72
|
# assert PDF2Text.pdf2text("http://www.ema.europa.eu/docs/en_GB/document_library/EPAR_-_Scientific_Discussion/human/000402/WC500033103.pdf").read =~ /Tamiflu/i
|
73
73
|
# end
|
74
74
|
#
|
75
|
-
# def
|
75
|
+
# def _test_pdf2text_wrong
|
76
76
|
# assert_raise CMD::CMDError do PDF2Text.pdf2text("http://www.ema.europa.eu/docs/en_GB#").read end
|
77
77
|
# end
|
78
78
|
|
79
|
-
def
|
79
|
+
def _test_string2hash
|
80
80
|
assert(Misc.string2hash("--user-agent=firefox").include? "--user-agent")
|
81
81
|
assert_equal(true, Misc.string2hash(":true")[:true])
|
82
82
|
assert_equal(true, Misc.string2hash("true")["true"])
|
@@ -87,17 +87,23 @@ class TestMisc < Test::Unit::TestCase
|
|
87
87
|
assert_equal(:j, Misc.string2hash("a=b#c=d#:h=:j")[:h])
|
88
88
|
end
|
89
89
|
|
90
|
-
def
|
90
|
+
def _test_named_array
|
91
91
|
a = NamedArray.setup([1,2,3,4], %w(a b c d))
|
92
92
|
assert_equal(1, a['a'])
|
93
93
|
end
|
94
94
|
|
95
|
-
|
96
|
-
|
97
|
-
|
95
|
+
def test_path_relative_to
|
96
|
+
assert_equal "test/foo", Misc.path_relative_to('/test', '/test/test/foo')
|
97
|
+
|
98
|
+
Misc.profile do
|
99
|
+
Misc.benchmark(45_000) do
|
100
|
+
Misc.path_relative_to('/test', '/test/test/foo')
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
98
104
|
|
99
|
-
# def
|
100
|
-
#
|
105
|
+
# def _test_chunk
|
106
|
+
# _test =<<-EOF
|
101
107
|
#This is an example file. Entries are separated by Entry
|
102
108
|
#-- Entry
|
103
109
|
#1
|
@@ -112,7 +118,7 @@ class TestMisc < Test::Unit::TestCase
|
|
112
118
|
# assert_equal "1\n2\n3", Misc.chunk(test, /^-- Entry/).first.strip
|
113
119
|
# end
|
114
120
|
|
115
|
-
def
|
121
|
+
def _test_hash2string
|
116
122
|
hash = {}
|
117
123
|
assert_equal hash, Misc.string2hash(Misc.hash2string(hash))
|
118
124
|
|
@@ -130,14 +136,14 @@ class TestMisc < Test::Unit::TestCase
|
|
130
136
|
|
131
137
|
end
|
132
138
|
|
133
|
-
def
|
139
|
+
def _test_merge
|
134
140
|
a = [[1],[2]]
|
135
141
|
a = NamedArray.setup a, %w(1 2)
|
136
142
|
a.merge [3,4]
|
137
143
|
assert_equal [1,3], a[0]
|
138
144
|
end
|
139
145
|
|
140
|
-
def
|
146
|
+
def _test_indiferent_hash
|
141
147
|
a = {:a => 1, "b" => 2}
|
142
148
|
a.extend IndiferentHash
|
143
149
|
|
@@ -147,7 +153,7 @@ class TestMisc < Test::Unit::TestCase
|
|
147
153
|
assert_equal 2, a[:b]
|
148
154
|
end
|
149
155
|
|
150
|
-
def
|
156
|
+
def _test_lockfile
|
151
157
|
|
152
158
|
TmpFile.with_file do |tmpfile|
|
153
159
|
pids = []
|
@@ -171,7 +177,7 @@ class TestMisc < Test::Unit::TestCase
|
|
171
177
|
end
|
172
178
|
end
|
173
179
|
|
174
|
-
def
|
180
|
+
def _test_positions2hash
|
175
181
|
inputs = Misc.positional2hash([:one, :two, :three], 1, :two => 2, :four => 4)
|
176
182
|
assert_equal 1, inputs[:one]
|
177
183
|
assert_equal 2, inputs[:two]
|
@@ -179,7 +185,7 @@ class TestMisc < Test::Unit::TestCase
|
|
179
185
|
assert_equal nil, inputs[:four]
|
180
186
|
end
|
181
187
|
|
182
|
-
def
|
188
|
+
def _test_mean
|
183
189
|
assert_equal 2, Misc.mean([1,2,3])
|
184
190
|
assert_equal 3, Misc.mean([1,2,3,4,5])
|
185
191
|
end
|
@@ -188,32 +194,32 @@ class TestMisc < Test::Unit::TestCase
|
|
188
194
|
assert_equal Math.sqrt(2), Misc.sd([1,3])
|
189
195
|
end
|
190
196
|
|
191
|
-
def
|
197
|
+
def _test_align_small
|
192
198
|
reference = "AABCDEBD"
|
193
199
|
sequence = "ABCD"
|
194
200
|
assert_equal '-ABCD---', Misc.fast_align(reference, sequence).last
|
195
201
|
end
|
196
202
|
|
197
|
-
def
|
203
|
+
def _test_align_real
|
198
204
|
reference = "SGNECNKAIDGNKDTFWHTFYGANGDPKPPPHTYTIDMKTTQNVNGLSMLPRQDGNQNGWIGRHEVYLSSDGTNW"
|
199
205
|
sequence = "TYTIDMKTTQNVNGLSML"
|
200
206
|
assert_equal "--------------------------------TYTIDMKTTQNVNGLSML-------------------------", Misc.fast_align(reference, sequence).last
|
201
207
|
end
|
202
208
|
|
203
|
-
def
|
209
|
+
def _test_divide
|
204
210
|
assert_equal 2, Misc.divide(%w(1 2 3 4 5 6 7 8 9),2).length
|
205
211
|
end
|
206
212
|
|
207
|
-
def
|
213
|
+
def _test_ordered_divide
|
208
214
|
assert_equal 5, Misc.ordered_divide(%w(1 2 3 4 5 6 7 8 9),2).length
|
209
215
|
end
|
210
216
|
|
211
|
-
def
|
217
|
+
def _test_collapse_ranges
|
212
218
|
ranges = [(0..100), (50..150), (51..61),(200..250), (300..324),(320..350)]
|
213
219
|
assert_equal [(0..150),(200..250), (300..350)], Misc.collapse_ranges(ranges)
|
214
220
|
end
|
215
221
|
|
216
|
-
def
|
222
|
+
def _test_humanize
|
217
223
|
str1 = "test_string"
|
218
224
|
str2 = "TEST_string"
|
219
225
|
str3 = "test"
|
@@ -225,22 +231,22 @@ class TestMisc < Test::Unit::TestCase
|
|
225
231
|
assert_equal "mutation_enrichment", Misc.snake_case("MutationEnrichment")
|
226
232
|
end
|
227
233
|
|
228
|
-
def
|
234
|
+
def _test_snake_case
|
229
235
|
str1 = "ACRONIMTest"
|
230
236
|
str2 = "ACRONIM_test"
|
231
237
|
assert_equal "ACRONIM_test", Misc.snake_case(str1)
|
232
238
|
assert_equal "ACRONIM_test", Misc.snake_case(str2)
|
233
239
|
end
|
234
240
|
|
235
|
-
def
|
241
|
+
def _test_correct_vcf_mutations
|
236
242
|
assert_equal [737407, ["-----", "-----G", "-----GTTAAT"]], Misc.correct_vcf_mutation(737406, "GTTAAT", "G,GG,GGTTAAT")
|
237
243
|
end
|
238
244
|
|
239
|
-
def
|
245
|
+
def _test_fingerprint
|
240
246
|
assert_equal '{a=>1}', Misc.fingerprint({:a => 1})
|
241
247
|
end
|
242
248
|
|
243
|
-
def
|
249
|
+
def _test_tarize
|
244
250
|
path = File.expand_path('/home/mvazquezg/git/rbbt-util/lib')
|
245
251
|
stream = Misc.tarize(path)
|
246
252
|
TmpFile.with_file do |res|
|
@@ -250,7 +256,7 @@ class TestMisc < Test::Unit::TestCase
|
|
250
256
|
end
|
251
257
|
end
|
252
258
|
|
253
|
-
def
|
259
|
+
def _test_camel_case
|
254
260
|
assert_equal "DbSNP", Misc.camel_case("db_SNP")
|
255
261
|
assert_equal "D3Js", Misc.camel_case("D3Js")
|
256
262
|
assert_equal "Structure", Misc.camel_case("Structure")
|
@@ -258,7 +264,7 @@ class TestMisc < Test::Unit::TestCase
|
|
258
264
|
assert_equal "COSMIC", Misc.camel_case("COSMIC")
|
259
265
|
end
|
260
266
|
|
261
|
-
def
|
267
|
+
def _test_pipe
|
262
268
|
t = 5
|
263
269
|
stream = Misc.open_pipe do |sin|
|
264
270
|
t.times do |i|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbbt-util
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.6.
|
4
|
+
version: 5.6.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Vazquez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -228,6 +228,7 @@ files:
|
|
228
228
|
- share/rbbt_commands/workflow/cmd
|
229
229
|
- share/rbbt_commands/workflow/example
|
230
230
|
- share/rbbt_commands/workflow/install
|
231
|
+
- share/rbbt_commands/workflow/jobs
|
231
232
|
- share/rbbt_commands/workflow/list
|
232
233
|
- share/rbbt_commands/workflow/monitor
|
233
234
|
- share/rbbt_commands/workflow/provenance
|