rbbt-util 5.8.7 → 5.8.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a0b0f59e7a2c5b61fd8ab0fc16b19008f534231
4
- data.tar.gz: 590b7d23d0f33022de18241f12b221f640336a75
3
+ metadata.gz: 79182b6a00b36773864861817a0994c8b89b466a
4
+ data.tar.gz: 64eda216950e3ea231a67d5ebf463ddfd6f99855
5
5
  SHA512:
6
- metadata.gz: 77577ab31857ac920b06346463a5f46ed85238a2d5fc0c55070b488dd2cf80cefd08d7ec6062d6cb967eb0aaafbe2875bd865ae8404effbbd2c4bc9795decffe
7
- data.tar.gz: a935d916adc432ef32d2d254f9d518a7cd27c087ff8f01980233183a430d1f196442fe4ebe4c41aa62436f8f212ab8e5a222796d5ab68977bdeb099d2cfb6002
6
+ metadata.gz: 77f978c48f2f87df1b39e200d02ddec6b2b9e99413281935c4e95d8c8320e8f1ad3b4ec30e43677af723b19386152f86b10a0faee2e466fdd6d745c65d1d2c83
7
+ data.tar.gz: 0144b36d0f85345835b9abba865aa866e7d98df42f73f3594c967b8d5dfb8cb07f19719fe11c1bea3f03b5871779fac3146966b19a6e6edf2f10f21e55d28521
@@ -32,19 +32,31 @@ Lockfile.refresh = false if ENV["RBBT_NO_LOCKFILE_REFRESH"] == "true"
32
32
  module Misc
33
33
 
34
34
  def self.format_paragraph(text, size = 80, indent = 0, offset = 0)
35
- words = text.gsub(/\s+/, "\s").split(" ")
36
- lines = []
37
- line = " "*offset
38
- word = words.shift
39
- while word
40
- while word and line.length + word.length < size - indent
41
- line << word << " "
42
- word = words.shift
43
- end
44
- lines << ((" " * indent) << line[0..-2])
45
- line = ""
46
- end
47
- (lines * "\n")
35
+ i = 0
36
+ re = /((?:\n\s*\n\s*)|(?:\n\s*(?=\*)))/
37
+ text.split(re).collect do |paragraph|
38
+ i += 1
39
+ str = if i % 2 == 1
40
+ words = paragraph.gsub(/\s+/, "\s").split(" ")
41
+ lines = []
42
+ line = " "*offset
43
+ word = words.shift
44
+ while word
45
+ word = word[0..size-indent-offset-4] + '...' if word.length >= size - indent - offset
46
+ while word and line.length + word.length <= size - indent
47
+ line << word << " "
48
+ word = words.shift
49
+ end
50
+ lines << ((" " * indent) << line[0..-2])
51
+ line = ""
52
+ end
53
+ (lines * "\n")
54
+ else
55
+ paragraph
56
+ end
57
+ offset = 0
58
+ str
59
+ end*""
48
60
  end
49
61
 
50
62
  def self.format_definition_list_item(dt, dd, size = 80, indent = 20, color = :yellow)
@@ -67,7 +79,7 @@ module Misc
67
79
  def self.format_definition_list(defs, size = 80, indent = 20, color = :yellow)
68
80
  entries = []
69
81
  defs.each do |dt,dd|
70
- text = format_definition_list_item(dt,dd,size,indent, color)
82
+ text = format_definition_list_item(dt,dd,size,indent,color)
71
83
  entries << text
72
84
  end
73
85
  entries * "\n\n"
@@ -72,6 +72,32 @@ module Workflow
72
72
  dependencies = self.rec_dependencies(task_name).collect{|dep_name| self.tasks[dep_name.to_sym]}
73
73
 
74
74
  task.doc(dependencies)
75
+
76
+ if self.libdir.examples[task_name].exists?
77
+ self.libdir.examples[task_name].glob("*").each do |example_dir|
78
+ example = File.basename(example_dir)
79
+
80
+ puts Log.color(:magenta, "Example " << example) + " -- " + Log.color(:blue, example_dir)
81
+
82
+ inputs = {}
83
+
84
+ task.input_types.each do |input,type|
85
+ if example_dir[input].exists?
86
+ case type
87
+ when :tsv, :array, :text
88
+ head = example_dir[input].read.split("\n")[0..5].compact * "\n\n"
89
+ head = head[0..500]
90
+ puts Misc.format_definition_list_item(input, head).gsub("\n\n","\n")
91
+ else
92
+ puts Misc.format_definition_list_item(input, example_dir[input].read)
93
+ end
94
+ end
95
+ end
96
+
97
+ puts
98
+ end
99
+
100
+ end
75
101
  end
76
102
  end
77
103
  end
@@ -22,7 +22,7 @@ else
22
22
  file = file.dup
23
23
  Path.setup(File.expand_path(file))
24
24
  end
25
- tsv = TSV.open(file)
25
+ tsv = TSV.open(file, :type => :double)
26
26
  end
27
27
 
28
28
  puts tsv.unzip(field, merge).to_s
@@ -37,7 +37,7 @@ def usage(workflow = nil, task = nil, exception=nil)
37
37
  puts SOPT.doc
38
38
  puts
39
39
  if workflow.nil?
40
- puts "No workflow specified"
40
+ puts "No workflow specified. Use `rbbt workflow list` to list available workflows."
41
41
  exit -1
42
42
  end
43
43
 
@@ -118,9 +118,9 @@ def fix_options(workflow, task, job_options)
118
118
  when TSV
119
119
  value
120
120
  when '-'
121
- TSV.open(STDIN, :unnamed => true)
121
+ TSV.open(STDIN, :unnamed => true, :sep => $field_separator, :sep2 => $array_separator || "|")
122
122
  else
123
- TSV.open(value, :unnamed => true)
123
+ TSV.open(value, :unnamed => true, :sep => $field_separator, :sep2 => $array_separator || "|")
124
124
  end
125
125
  else
126
126
  value
@@ -135,6 +135,7 @@ options = SOPT.get <<EOF
135
135
  -h--help Show this help:
136
136
  -wd--workdir* Change the working directory of the workflow:
137
137
  -as--array_separator* Change the character that separates elements of Arrays, ',', '|', or '\\n' by default:
138
+ -fs--field_separator* Change the character that separates fields of TSV files '\\t' by default:
138
139
  -jn--jobname* Job name to use. The name 'Default' is used by default:
139
140
  -pn--printname Print the name of the job and exit without starting it:
140
141
  -pf--printpath Print the path of the job result:
@@ -164,6 +165,7 @@ recursive_clean = !!options.delete(:recursive_clean)
164
165
  out = options.include?(:output) ? File.open(options[:output], 'wb') : STDOUT
165
166
 
166
167
  $array_separator = options.delete(:array_separator)
168
+ $field_separator = options.delete(:field_separator) || "\t"
167
169
 
168
170
  # Get workflow
169
171
 
@@ -6,20 +6,24 @@ require 'rbbt/entity'
6
6
 
7
7
  class TestMisc < Test::Unit::TestCase
8
8
 
9
- def _test_format_paragraph
9
+ def test_format_paragraph
10
10
  p = <<-EOF
11
-
12
11
  Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
13
12
  incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
14
13
  nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
14
+
15
15
  Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
16
- fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt
17
- in culpa qui officia deserunt mollit anim id est laborum.
16
+ fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt
17
+ in culpa qui officia deserunt mollit anim id est laborum.
18
18
 
19
19
 
20
+ * one
21
+ * two
22
+ * three
23
+
20
24
  EOF
21
25
 
22
- puts Misc.format_paragraph p, 70, 10, 5
26
+ assert Misc.format_paragraph(p, 70, 10, 5) =~ /\n\s*\* two/sm
23
27
  end
24
28
 
25
29
  def test_format_dl
@@ -38,27 +42,27 @@ Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium
38
42
  doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore
39
43
  veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim
40
44
  ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia
41
- consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque
42
- porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur,
45
+ consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.
46
+
47
+ Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur,
43
48
  adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et
44
49
  dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis
45
50
  nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex
46
51
  ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea
47
52
  voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem
48
53
  eum fugiat quo voluptas nulla pariatur?"
49
-
50
54
  EOF
51
55
 
52
- puts Misc.format_definition_list({:paragraph_first => p1, :paragraph_second => p2})
56
+ assert Misc.format_definition_list({:paragraph_first => p1, :paragraph_second => p2}) =~ / /
53
57
  end
54
58
 
55
- def _test_parse_cmd_params
59
+ def test_parse_cmd_params
56
60
  assert_equal ["workflow", "task", "Translation", "translate", "-f", "Associated Gene Name", "-l", "-"],
57
61
  Misc.parse_cmd_params("workflow task Translation translate -f 'Associated Gene Name' -l -")
58
62
  end
59
63
 
60
64
 
61
- def _test_fixutf8
65
+ def test_fixutf8
62
66
  string = "abc\xffdef"
63
67
  string = string.force_encoding("UTF-8") if string.respond_to? :force_encoding
64
68
  assert(! string.valid_encoding?) if string.respond_to? :valid_encoding?
@@ -67,37 +71,37 @@ eum fugiat quo voluptas nulla pariatur?"
67
71
  assert( Misc.fixutf8(string).valid_encoding) if string.respond_to? :valid_encoding
68
72
  end
69
73
 
70
- def _test_colors_for
74
+ def test_colors_for
71
75
  colors, used = Misc.colors_for([1,2,2,1,2,1,2,2,3,3,2,3,2])
72
76
  assert_equal Misc::COLOR_LIST[1], used[2]
73
77
  end
74
78
 
75
- def _test_total_length
79
+ def test_total_length
76
80
  ranges = [(0..100), (50..150), (120..160)]
77
81
  ranges = [(0..100), (50..150), (120..160), (51..70)]
78
82
  assert_equal 161, Misc.total_length(ranges)
79
83
  end
80
84
 
81
- def _test_id_filename?
85
+ def test_id_filename?
82
86
  TmpFile.with_file("") do |file|
83
87
  assert Misc.is_filename?(file)
84
88
  assert ! Misc.is_filename?("TEST STRING")
85
89
  end
86
90
  end
87
91
 
88
- def _test_merge_sorted_arrays
92
+ def test_merge_sorted_arrays
89
93
  assert_equal [1,2,3,4], Misc.merge_sorted_arrays([1,3], [2,4])
90
94
  end
91
95
 
92
- def _test_intersect_sorted_arrays
96
+ def test_intersect_sorted_arrays
93
97
  assert_equal [2,4], Misc.intersect_sorted_arrays([1,2,3,4], [2,4])
94
98
  end
95
99
 
96
- def _test_sorted_array_matches
100
+ def test_sorted_array_matches
97
101
  assert_equal [1,3], Misc.sorted_array_hits(%w(a b c d e), %w(b d))
98
102
  end
99
103
 
100
- def _test_binary_include?
104
+ def test_binary_include?
101
105
  a = %w(a b c d e).sort
102
106
  assert Misc.binary_include?(a, "a")
103
107
  assert(!Misc.binary_include?(a, "z"))
@@ -106,24 +110,24 @@ eum fugiat quo voluptas nulla pariatur?"
106
110
  assert(Misc.binary_include?(a, "d"))
107
111
  end
108
112
 
109
- def _test_process_to_hash
113
+ def test_process_to_hash
110
114
  list = [1,2,3,4]
111
115
  assert_equal 4, Misc.process_to_hash(list){|l| l.collect{|e| e * 2}}[2]
112
116
  end
113
117
 
114
- # def _test_pdf2text_example
118
+ # def test_pdf2text_example
115
119
  # assert PDF2Text.pdf2text(datafile_test('example.pdf')).read =~ /An Example Paper/i
116
120
  # end
117
121
  #
118
- # def _test_pdf2text_EPAR
122
+ # def test_pdf2text_EPAR
119
123
  # assert PDF2Text.pdf2text("http://www.ema.europa.eu/docs/en_GB/document_library/EPAR_-_Scientific_Discussion/human/000402/WC500033103.pdf").read =~ /Tamiflu/i
120
124
  # end
121
125
  #
122
- # def _test_pdf2text_wrong
126
+ # def test_pdf2text_wrong
123
127
  # assert_raise CMD::CMDError do PDF2Text.pdf2text("http://www.ema.europa.eu/docs/en_GB#").read end
124
128
  # end
125
129
 
126
- def _test_string2hash
130
+ def test_string2hash
127
131
  assert(Misc.string2hash("--user-agent=firefox").include? "--user-agent")
128
132
  assert_equal(true, Misc.string2hash(":true")[:true])
129
133
  assert_equal(true, Misc.string2hash("true")["true"])
@@ -134,12 +138,12 @@ eum fugiat quo voluptas nulla pariatur?"
134
138
  assert_equal(:j, Misc.string2hash("a=b#c=d#:h=:j")[:h])
135
139
  end
136
140
 
137
- def _test_named_array
141
+ def test_named_array
138
142
  a = NamedArray.setup([1,2,3,4], %w(a b c d))
139
143
  assert_equal(1, a['a'])
140
144
  end
141
145
 
142
- def _test_path_relative_to
146
+ def test_path_relative_to
143
147
  assert_equal "test/foo", Misc.path_relative_to('/test', '/test/test/foo')
144
148
 
145
149
  Misc.profile do
@@ -149,8 +153,8 @@ eum fugiat quo voluptas nulla pariatur?"
149
153
  end
150
154
  end
151
155
 
152
- # def _test_chunk
153
- # _test =<<-EOF
156
+ # def test_chunk
157
+ # test =<<-EOF
154
158
  #This is an example file. Entries are separated by Entry
155
159
  #-- Entry
156
160
  #1
@@ -165,7 +169,7 @@ eum fugiat quo voluptas nulla pariatur?"
165
169
  # assert_equal "1\n2\n3", Misc.chunk(test, /^-- Entry/).first.strip
166
170
  # end
167
171
 
168
- def _test_hash2string
172
+ def test_hash2string
169
173
  hash = {}
170
174
  assert_equal hash, Misc.string2hash(Misc.hash2string(hash))
171
175
 
@@ -183,14 +187,14 @@ eum fugiat quo voluptas nulla pariatur?"
183
187
 
184
188
  end
185
189
 
186
- def _test_merge
190
+ def test_merge
187
191
  a = [[1],[2]]
188
192
  a = NamedArray.setup a, %w(1 2)
189
193
  a.merge [3,4]
190
194
  assert_equal [1,3], a[0]
191
195
  end
192
196
 
193
- def _test_indiferent_hash
197
+ def test_indiferent_hash
194
198
  a = {:a => 1, "b" => 2}
195
199
  a.extend IndiferentHash
196
200
 
@@ -200,7 +204,7 @@ eum fugiat quo voluptas nulla pariatur?"
200
204
  assert_equal 2, a[:b]
201
205
  end
202
206
 
203
- def _test_lockfile
207
+ def test_lockfile
204
208
 
205
209
  TmpFile.with_file do |tmpfile|
206
210
  pids = []
@@ -224,7 +228,7 @@ eum fugiat quo voluptas nulla pariatur?"
224
228
  end
225
229
  end
226
230
 
227
- def _test_positions2hash
231
+ def test_positions2hash
228
232
  inputs = Misc.positional2hash([:one, :two, :three], 1, :two => 2, :four => 4)
229
233
  assert_equal 1, inputs[:one]
230
234
  assert_equal 2, inputs[:two]
@@ -232,18 +236,18 @@ eum fugiat quo voluptas nulla pariatur?"
232
236
  assert_equal nil, inputs[:four]
233
237
  end
234
238
 
235
- def _test_mean
239
+ def test_mean
236
240
  assert_equal 2, Misc.mean([1,2,3])
237
241
  assert_equal 3, Misc.mean([1,2,3,4,5])
238
242
  end
239
243
 
240
- def _test_zip_fields
244
+ def test_zip_fields
241
245
  current = [[:a,1], [:b,2]]
242
246
  assert_equal [[:a, :b],[1,2]], Misc.zip_fields(current)
243
247
  assert_equal current, Misc.zip_fields(Misc.zip_fields(current))
244
248
  end
245
249
 
246
- def _test_add_zipped
250
+ def test_add_zipped
247
251
  current = [[:a,1], [:b,2]]
248
252
  new = %w(A B)
249
253
  Misc.append_zipped current, new
@@ -254,20 +258,20 @@ eum fugiat quo voluptas nulla pariatur?"
254
258
  assert_equal Math.sqrt(2), Misc.sd([1,3])
255
259
  end
256
260
 
257
- def _test_divide
261
+ def test_divide
258
262
  assert_equal 2, Misc.divide(%w(1 2 3 4 5 6 7 8 9),2).length
259
263
  end
260
264
 
261
- def _test_ordered_divide
265
+ def test_ordered_divide
262
266
  assert_equal 5, Misc.ordered_divide(%w(1 2 3 4 5 6 7 8 9),2).length
263
267
  end
264
268
 
265
- def _test_collapse_ranges
269
+ def test_collapse_ranges
266
270
  ranges = [(0..100), (50..150), (51..61),(200..250), (300..324),(320..350)]
267
271
  assert_equal [(0..150),(200..250), (300..350)], Misc.collapse_ranges(ranges)
268
272
  end
269
273
 
270
- def _test_humanize
274
+ def test_humanize
271
275
  str1 = "test_string"
272
276
  str2 = "TEST_string"
273
277
  str3 = "test"
@@ -279,22 +283,22 @@ eum fugiat quo voluptas nulla pariatur?"
279
283
  assert_equal "mutation_enrichment", Misc.snake_case("MutationEnrichment")
280
284
  end
281
285
 
282
- def _test_snake_case
286
+ def test_snake_case
283
287
  str1 = "ACRONIMTest"
284
288
  str2 = "ACRONIM_test"
285
289
  assert_equal "ACRONIM_test", Misc.snake_case(str1)
286
290
  assert_equal "ACRONIM_test", Misc.snake_case(str2)
287
291
  end
288
292
 
289
- def _test_correct_vcf_mutations
293
+ def test_correct_vcf_mutations
290
294
  assert_equal [737407, ["-----", "-----G", "-----GTTAAT"]], Misc.correct_vcf_mutation(737406, "GTTAAT", "G,GG,GGTTAAT")
291
295
  end
292
296
 
293
- def _test_fingerprint
297
+ def test_fingerprint
294
298
  assert_equal '{a=>1}', Misc.fingerprint({:a => 1})
295
299
  end
296
300
 
297
- def _test_tarize
301
+ def test_tarize
298
302
  path = File.expand_path('/home/mvazquezg/git/rbbt-util/lib')
299
303
  stream = Misc.tarize(path)
300
304
  TmpFile.with_file do |res|
@@ -304,7 +308,7 @@ eum fugiat quo voluptas nulla pariatur?"
304
308
  end
305
309
  end
306
310
 
307
- def _test_camel_case
311
+ def test_camel_case
308
312
  assert_equal "DbSNP", Misc.camel_case("db_SNP")
309
313
  assert_equal "D3Js", Misc.camel_case("D3Js")
310
314
  assert_equal "Structure", Misc.camel_case("Structure")
@@ -312,7 +316,7 @@ eum fugiat quo voluptas nulla pariatur?"
312
316
  assert_equal "COSMIC", Misc.camel_case("COSMIC")
313
317
  end
314
318
 
315
- def _test_pipe
319
+ def test_pipe
316
320
  t = 5
317
321
  stream = Misc.open_pipe do |sin|
318
322
  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.8.7
4
+ version: 5.8.8
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-03-15 00:00:00.000000000 Z
11
+ date: 2014-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake