miga-base 0.2.0.6 → 0.2.0.7
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 -0
- data/LICENSE +201 -0
- data/README.md +17 -335
- data/Rakefile +31 -0
- data/actions/add_result +2 -5
- data/actions/add_taxonomy +4 -7
- data/actions/create_dataset +5 -6
- data/actions/create_project +2 -5
- data/actions/daemon +2 -5
- data/actions/download_dataset +88 -58
- data/actions/find_datasets +36 -38
- data/actions/import_datasets +2 -5
- data/actions/index_taxonomy +2 -5
- data/actions/list_datasets +47 -49
- data/actions/list_files +7 -11
- data/actions/unlink_dataset +2 -5
- data/bin/miga +1 -1
- data/lib/miga/common.rb +132 -0
- data/lib/miga/daemon.rb +229 -168
- data/lib/miga/dataset.rb +354 -277
- data/lib/miga/gui.rb +346 -269
- data/lib/miga/metadata.rb +115 -71
- data/lib/miga/project.rb +361 -259
- data/lib/miga/remote_dataset.rb +200 -148
- data/lib/miga/result.rb +150 -99
- data/lib/miga/tax_index.rb +124 -67
- data/lib/miga/taxonomy.rb +129 -100
- data/lib/miga/version.rb +57 -0
- data/lib/miga.rb +2 -77
- data/scripts/_distances_noref_nomulti.bash +2 -0
- data/scripts/_distances_ref_nomulti.bash +2 -0
- data/scripts/aai_distances.bash +1 -0
- data/scripts/ani_distances.bash +1 -0
- data/scripts/assembly.bash +1 -0
- data/scripts/cds.bash +1 -0
- data/scripts/clade_finding.bash +17 -1
- data/scripts/distances.bash +1 -0
- data/scripts/essential_genes.bash +1 -0
- data/scripts/haai_distances.bash +1 -0
- data/scripts/init.bash +2 -0
- data/scripts/mytaxa.bash +1 -0
- data/scripts/mytaxa_scan.bash +1 -0
- data/scripts/ogs.bash +1 -0
- data/scripts/read_quality.bash +1 -0
- data/scripts/ssu.bash +1 -0
- data/scripts/subclades.bash +1 -0
- data/scripts/trimmed_fasta.bash +1 -0
- data/scripts/trimmed_reads.bash +1 -0
- data/test/common_test.rb +82 -0
- data/test/daemon_test.rb +53 -0
- data/test/dataset_test.rb +156 -0
- data/test/jruby_gui_test.rb +20 -0
- data/test/metadata_test.rb +48 -0
- data/test/project_test.rb +54 -0
- data/test/remote_dataset_test.rb +41 -0
- data/test/tax_index_test.rb +44 -0
- data/test/taxonomy_test.rb +36 -0
- data/test/test_helper.rb +32 -0
- metadata +53 -38
data/actions/create_project
CHANGED
data/actions/daemon
CHANGED
data/actions/download_dataset
CHANGED
@@ -1,77 +1,107 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
|
3
3
|
# @package MiGA
|
4
|
-
# @
|
5
|
-
# @license artistic license 2.0
|
6
|
-
# @update Oct-01-2015
|
7
|
-
#
|
4
|
+
# @license Artistic-2.0
|
8
5
|
|
9
6
|
require "miga/remote_dataset"
|
10
7
|
|
11
|
-
o = {q:true,
|
8
|
+
o = {q:true, query:false, universe: :ebi, db: :embl}
|
12
9
|
OptionParser.new do |opt|
|
13
|
-
|
10
|
+
opt.banner = <<BAN
|
14
11
|
Creates an empty dataset in a pre-existing MiGA project.
|
15
12
|
|
16
13
|
Usage: #{$0} #{File.basename(__FILE__)} [options]
|
17
14
|
BAN
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
15
|
+
opt.separator ""
|
16
|
+
opt.on("-P", "--project PATH",
|
17
|
+
"(Mandatory) Path to the project to use."){ |v| o[:project]=v }
|
18
|
+
opt.on("-D", "--dataset STRING",
|
19
|
+
"(Mandatory unless -F) ID of the dataset to create."){ |v| o[:dataset]=v }
|
20
|
+
opt.on("-I", "--ids ID1,ID2,...",
|
21
|
+
"(Mandatory unless -F) IDs in the remote database separated by commas."
|
22
|
+
){ |v| o[:ids]=v }
|
23
|
+
opt.on("-U", "--universe STRING",
|
24
|
+
"Universe where the remote database lives. By default: #{o[:universe]}."
|
25
|
+
){ |v| o[:universe]=v.to_sym }
|
26
|
+
opt.on("--db STRING",
|
27
|
+
"Name of the remote database. By default: #{o[:db]}."
|
28
|
+
){ |v| o[:db]=v.to_sym }
|
29
|
+
opt.on("-F", "--file PATH",
|
30
|
+
"Tab-delimited file (with header) listing the datasets to download.",
|
31
|
+
"The long form of all the options are supported as header (without the --)",
|
32
|
+
"including dataset, ids, universe, and db. For query use true/false values."
|
33
|
+
){ |v| o[:file] = v }
|
34
|
+
opt.on("-t", "--type STRING",
|
35
|
+
"Type of dataset. Recognized types include:",
|
36
|
+
*MiGA::Dataset.KNOWN_TYPES.map{ |k,v| "~ #{k}: #{v[:description]}" }
|
37
|
+
){ |v| o[:type]=v.to_sym }
|
38
|
+
opt.on("-q", "--query",
|
39
|
+
"If set, the dataset is registered as a query, not a reference dataset."
|
40
|
+
){ |v| o[:query]=v }
|
41
|
+
opt.on("--ignore-dup",
|
42
|
+
"If set, ignores datasets that already exist."){ |v| o[:ignore_dup]=v }
|
43
|
+
opt.on("-d", "--description STRING",
|
44
|
+
"Description of the dataset."){ |v| o[:description]=v }
|
45
|
+
opt.on("-u", "--user STRING",
|
46
|
+
"Owner of the dataset."){ |v| o[:user]=v }
|
47
|
+
opt.on("-c", "--comments STRING",
|
48
|
+
"Comments on the dataset."){ |v| o[:comments]=v }
|
49
|
+
opt.on("-v", "--verbose",
|
50
|
+
"Print additional information to STDERR."){ o[:q]=false }
|
51
|
+
opt.on("-d", "--debug INT", "Print debugging information to STDERR.") do |v|
|
52
|
+
v.to_i>1 ? MiGA::MiGA.DEBUG_TRACE_ON : MiGA::MiGA.DEBUG_ON
|
53
|
+
end
|
54
|
+
opt.on("-h", "--help", "Display this screen.") do
|
55
|
+
puts opt
|
56
|
+
exit
|
57
|
+
end
|
58
|
+
opt.separator ""
|
55
59
|
end.parse!
|
56
60
|
|
57
61
|
|
58
62
|
### MAIN
|
59
|
-
|
60
|
-
|
61
|
-
|
63
|
+
glob = [o]
|
64
|
+
unless o[:file].nil?
|
65
|
+
glob = []
|
66
|
+
fh = File.open(o[:file], "r")
|
67
|
+
h = nil
|
68
|
+
fh.each do |ln|
|
69
|
+
r = ln.chomp.split(/\t/)
|
70
|
+
if h.nil?
|
71
|
+
h = r
|
72
|
+
else
|
73
|
+
glob << o.dup
|
74
|
+
h.each_index do |i|
|
75
|
+
glob[glob.size-1][h[i].to_sym] = h[i]=="query" ? r[i]=="true" :
|
76
|
+
%w[type universe db].include?(h[i]) ? r[i].to_sym : r[i]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
fh.close
|
81
|
+
end
|
62
82
|
|
63
|
-
|
64
|
-
|
83
|
+
glob.each do |o_i|
|
84
|
+
raise "-P is mandatory." if o_i[:project].nil?
|
85
|
+
raise "-D is mandatory." if o_i[:dataset].nil?
|
86
|
+
raise "-I is mandatory." if o_i[:ids].nil?
|
65
87
|
|
66
|
-
$stderr.puts "
|
67
|
-
|
68
|
-
|
88
|
+
$stderr.puts "Dataset: #{o_i[:dataset]}" unless o_i[:q]
|
89
|
+
$stderr.puts "Loading project." unless o_i[:q]
|
90
|
+
p = MiGA::Project.load(o_i[:project])
|
91
|
+
raise "Impossible to load project: #{o_i[:project]}" if p.nil?
|
69
92
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
p.add_dataset(o[:dataset])
|
93
|
+
next if o_i[:ignore_dup] and not p.dataset(o_i[:dataset]).nil?
|
94
|
+
|
95
|
+
$stderr.puts "Locating remote dataset." unless o_i[:q]
|
96
|
+
rd = MiGA::RemoteDataset.new(o_i[:ids], o_i[:db], o_i[:universe])
|
75
97
|
|
76
|
-
$stderr.puts "
|
98
|
+
$stderr.puts "Creating dataset." unless o_i[:q]
|
99
|
+
md = {}
|
100
|
+
[:type, :description, :user, :comments].each do |k|
|
101
|
+
md[k]=o_i[k] unless o_i[k].nil?
|
102
|
+
end
|
103
|
+
rd.save_to(p, o_i[:dataset], !o_i[:query], md)
|
104
|
+
p.add_dataset(o_i[:dataset])
|
77
105
|
|
106
|
+
$stderr.puts "Done." unless o_i[:q]
|
107
|
+
end
|
data/actions/find_datasets
CHANGED
@@ -1,42 +1,39 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
|
3
3
|
# @package MiGA
|
4
|
-
# @
|
5
|
-
# @license artistic license 2.0
|
6
|
-
# @update Oct-01-2015
|
7
|
-
#
|
4
|
+
# @license Artistic-2.0
|
8
5
|
|
9
6
|
o = {q:true, add:false, ref:false}
|
10
7
|
OptionParser.new do |opt|
|
11
|
-
|
8
|
+
opt.banner = <<BAN
|
12
9
|
Finds unregistered datasets based on result files.
|
13
10
|
|
14
11
|
Usage: #{$0} #{File.basename(__FILE__)} [options]
|
15
12
|
BAN
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
13
|
+
opt.separator ""
|
14
|
+
opt.on("-P", "--project PATH",
|
15
|
+
"(Mandatory) Path to the project to use."){ |v| o[:project]=v }
|
16
|
+
opt.on("-a", "--add",
|
17
|
+
"Register the datasets found. By default, only lists them (dry run)."
|
18
|
+
){ |v| o[:add]=v }
|
19
|
+
opt.on("-t", "--type STRING",
|
20
|
+
"Type of datasets. Recognized types include:",
|
21
|
+
*MiGA::Dataset.KNOWN_TYPES.map{ |k,v| "~ #{k}: #{v[:description]}"}
|
22
|
+
){ |v| o[:type]=v.to_sym }
|
23
|
+
opt.on("-r", "--ref",
|
24
|
+
"If set, all datasets are registered as reference datasets."
|
25
|
+
){ |v| o[:ref]=v }
|
26
|
+
opt.on("-u", "--user STRING", "Owner of the dataset."){ |v| o[:user]=v }
|
27
|
+
opt.on("-v", "--verbose",
|
28
|
+
"Print additional information to STDERR."){ o[:q]=false }
|
29
|
+
opt.on("-d", "--debug INT", "Print debugging information to STDERR.") do |v|
|
30
|
+
v.to_i>1 ? MiGA::MiGA.DEBUG_TRACE_ON : MiGA::MiGA.DEBUG_ON
|
31
|
+
end
|
32
|
+
opt.on("-h", "--help", "Display this screen.") do
|
33
|
+
puts opt
|
34
|
+
exit
|
35
|
+
end
|
36
|
+
opt.separator ""
|
40
37
|
end.parse!
|
41
38
|
|
42
39
|
|
@@ -50,14 +47,15 @@ raise "Impossible to load project: #{o[:project]}" if p.nil?
|
|
50
47
|
$stderr.puts "Finding datasets." unless o[:q]
|
51
48
|
ud = p.unregistered_datasets
|
52
49
|
ud.each do |dn|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
50
|
+
puts dn
|
51
|
+
if o[:add]
|
52
|
+
md = {}
|
53
|
+
[:type, :user].each{ |k| md[k]=o[k] unless o[k].nil? }
|
54
|
+
d = MiGA::Dataset.new(p, dn, o[:ref], md)
|
55
|
+
p.add_dataset(dn)
|
56
|
+
res = d.first_preprocessing
|
57
|
+
puts "- #{res}" unless o[:q]
|
58
|
+
end
|
60
59
|
end
|
61
60
|
|
62
61
|
$stderr.puts "Done." unless o[:q]
|
63
|
-
|
data/actions/import_datasets
CHANGED
@@ -1,10 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
|
3
3
|
# @package MiGA
|
4
|
-
# @
|
5
|
-
# @license artistic license 2.0
|
6
|
-
# @update Oct-01-2015
|
7
|
-
#
|
4
|
+
# @license Artistic-2.0
|
8
5
|
|
9
6
|
o = {q:true, info:false, force:false, method: :hardlink }
|
10
7
|
OptionParser.new do |opt|
|
data/actions/index_taxonomy
CHANGED
data/actions/list_datasets
CHANGED
@@ -1,46 +1,45 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
|
3
3
|
# @package MiGA
|
4
|
-
# @
|
5
|
-
# @license artistic license 2.0
|
6
|
-
# @update Oct-01-2015
|
7
|
-
#
|
4
|
+
# @license Artistic-2.0
|
8
5
|
|
9
|
-
o = {q:true, info:false}
|
6
|
+
o = {q:true, info:false, processing:false}
|
10
7
|
OptionParser.new do |opt|
|
11
|
-
|
8
|
+
opt.banner = <<BAN
|
12
9
|
Lists all registered datasets in an MiGA project.
|
13
10
|
|
14
11
|
Usage: #{$0} #{File.basename(__FILE__)} [options]
|
15
12
|
BAN
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
13
|
+
opt.separator ""
|
14
|
+
opt.on("-P", "--project PATH",
|
15
|
+
"(Mandatory) Path to the project to read."){ |v| o[:project]=v }
|
16
|
+
opt.on("-D", "--dataset STRING",
|
17
|
+
"ID of the dataset to read."){ |v| o[:dataset]=v.miga_name }
|
18
|
+
opt.on("--[no-]ref",
|
19
|
+
"If set, lists only reference (or only non-reference) datasets."
|
20
|
+
){ |v| o[:ref]=v }
|
21
|
+
opt.on("--[no-]multi",
|
22
|
+
"If set, lists only multi-species (or only single-species) datasets."
|
23
|
+
){ |v| o[:multi]=v }
|
24
|
+
opt.on("-i", "--info",
|
25
|
+
"Print additional information on each dataset."){ |v| o[:info]=v }
|
26
|
+
opt.on("-p", "--processing",
|
27
|
+
"Print information on processing advance."){ |v| o[:processing]=v }
|
28
|
+
opt.on("-t", "--taxonomy RANK:TAXON",
|
29
|
+
"Filter by taxonomy."){ |v| o[:taxonomy]=MiGA::Taxonomy.new v }
|
30
|
+
opt.on("-m", "--metadata STRING",
|
31
|
+
"Print name and metadata field only. If set, ignores -i."
|
32
|
+
){ |v| o[:datum]=v }
|
33
|
+
opt.on("-v", "--verbose",
|
34
|
+
"Print additional information to STDERR."){ o[:q]=false }
|
35
|
+
opt.on("-d", "--debug INT", "Print debugging information to STDERR.") do |v|
|
36
|
+
v.to_i>1 ? MiGA::MiGA.DEBUG_TRACE_ON : MiGA::MiGA.DEBUG_ON
|
37
|
+
end
|
38
|
+
opt.on("-h", "--help", "Display this screen.") do
|
39
|
+
puts opt
|
40
|
+
exit
|
41
|
+
end
|
42
|
+
opt.separator ""
|
44
43
|
end.parse!
|
45
44
|
|
46
45
|
|
@@ -53,31 +52,30 @@ raise "Impossible to load project: #{o[:project]}" if p.nil?
|
|
53
52
|
|
54
53
|
$stderr.puts "Listing datasets." unless o[:q]
|
55
54
|
if o[:dataset].nil?
|
56
|
-
|
55
|
+
ds = p.datasets
|
57
56
|
elsif MiGA::Dataset.exist? p, o[:dataset]
|
58
|
-
|
57
|
+
ds = [p.dataset(o[:dataset])]
|
59
58
|
else
|
60
|
-
|
59
|
+
ds = []
|
61
60
|
end
|
62
61
|
ds.select!{|d| d.is_ref? == o[:ref] } unless o[:ref].nil?
|
63
62
|
ds.select! do |d|
|
64
|
-
|
65
|
-
|
63
|
+
(not d.metadata[:type].nil?) and
|
64
|
+
(MiGA::Dataset.KNOWN_TYPES[d.metadata[:type]][:multi] == o[:multi])
|
66
65
|
end unless o[:multi].nil?
|
67
66
|
ds.select! do |d|
|
68
|
-
|
67
|
+
(not d.metadata[:tax].nil?) and d.metadata[:tax].is_in?(o[:taxonomy])
|
69
68
|
end unless o[:taxonomy].nil?
|
70
69
|
if not o[:datum].nil?
|
71
|
-
|
70
|
+
ds.each{|d| puts "#{d.name}\t#{d.metadata[ o[:datum] ] || "?"}"}
|
72
71
|
elsif o[:info]
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
72
|
+
puts MiGA::MiGA.tabulate(MiGA::Dataset.INFO_FIELDS, ds.map{ |d| d.info })
|
73
|
+
elsif o[:processing]
|
74
|
+
comp = ["undef","done","queued"]
|
75
|
+
puts MiGA::MiGA.tabulate([:name] + MiGA::Dataset.PREPROCESSING_TASKS,
|
76
|
+
ds.map{ |d| [d.name] + d.profile_advance.map{ |i| comp[i] } })
|
78
77
|
else
|
79
|
-
|
78
|
+
ds.each{|d| puts d.name}
|
80
79
|
end
|
81
80
|
|
82
81
|
$stderr.puts "Done." unless o[:q]
|
83
|
-
|
data/actions/list_files
CHANGED
@@ -1,10 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
|
3
3
|
# @package MiGA
|
4
|
-
# @
|
5
|
-
# @license artistic license 2.0
|
6
|
-
# @update Oct-01-2015
|
7
|
-
#
|
4
|
+
# @license Artistic-2.0
|
8
5
|
|
9
6
|
o = {q:true, details:false, json:true}
|
10
7
|
OptionParser.new do |opt|
|
@@ -22,9 +19,9 @@ BAN
|
|
22
19
|
opt.on("-i", "--info",
|
23
20
|
"If set, it prints additional details for each file."
|
24
21
|
){ |v| o[:details]=v }
|
25
|
-
opt.on("--
|
26
|
-
"If set, excludes json files containing results metadata."
|
27
|
-
){ |v| o[:json]
|
22
|
+
opt.on("--[no-]json",
|
23
|
+
"If set to no, excludes json files containing results metadata."
|
24
|
+
){ |v| o[:json]=v }
|
28
25
|
opt.on("-v", "--verbose",
|
29
26
|
"Print additional information to STDERR."){ o[:q]=false }
|
30
27
|
opt.on("-d", "--debug INT", "Print debugging information to STDERR.") do |v|
|
@@ -56,10 +53,9 @@ end
|
|
56
53
|
|
57
54
|
$stderr.puts "Listing files." unless o[:q]
|
58
55
|
results.each do |result|
|
59
|
-
puts
|
56
|
+
puts "#{ "#{result.path}\t\t" if o[:details] }#{result.path}" if o[:json]
|
60
57
|
result.each_file do |k,f|
|
61
|
-
puts
|
62
|
-
File.dirname(result.path) + "/" + f.to_s
|
58
|
+
puts "#{ "#{result.path}\t#{k}\t" if o[:details] }#{result.dir}/#{f}"
|
63
59
|
end
|
64
60
|
end
|
65
61
|
|
data/actions/unlink_dataset
CHANGED
data/bin/miga
CHANGED
data/lib/miga/common.rb
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# @package MiGA
|
2
|
+
# @license Artistic-2.0
|
3
|
+
|
4
|
+
require "miga/version"
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
##
|
8
|
+
# Generic class used to handle system-wide information and methods, and parent
|
9
|
+
# of all other MiGA::* classes.
|
10
|
+
class MiGA::MiGA
|
11
|
+
|
12
|
+
ENV["MIGA_HOME"] ||= ENV["HOME"]
|
13
|
+
|
14
|
+
##
|
15
|
+
# Root path to MiGA (as estimated from the location of the current file).
|
16
|
+
def self.root_path ; File.expand_path("../../..", __FILE__) ; end
|
17
|
+
|
18
|
+
##
|
19
|
+
# Should debugging information be reported?
|
20
|
+
@@DEBUG = false
|
21
|
+
|
22
|
+
##
|
23
|
+
# Should the trace of debugging information be reported?
|
24
|
+
@@DEBUG_TRACE = false
|
25
|
+
|
26
|
+
##
|
27
|
+
# Turn on debugging.
|
28
|
+
def self.DEBUG_ON() @@DEBUG=true end
|
29
|
+
|
30
|
+
##
|
31
|
+
# Turn off debugging.
|
32
|
+
def self.DEBUG_OFF() @@DEBUG=false end
|
33
|
+
|
34
|
+
##
|
35
|
+
# Turn on debug tracing (and debugging).
|
36
|
+
def self.DEBUG_TRACE_ON
|
37
|
+
@@DEBUG_TRACE=true
|
38
|
+
self.DEBUG_ON
|
39
|
+
end
|
40
|
+
|
41
|
+
##
|
42
|
+
# Turn off debug tracing (but not debugging).
|
43
|
+
def self.DEBUG_TRACE_OFF
|
44
|
+
@@DEBUG_TRACE=false
|
45
|
+
end
|
46
|
+
|
47
|
+
##
|
48
|
+
# Send debug message.
|
49
|
+
def self.DEBUG *args
|
50
|
+
$stderr.puts(*args) if @@DEBUG
|
51
|
+
$stderr.puts caller.map{|v| v.gsub(/^/," ")}.join("\n") if
|
52
|
+
@@DEBUG_TRACE
|
53
|
+
end
|
54
|
+
|
55
|
+
##
|
56
|
+
# Has MiGA been initialized?
|
57
|
+
def self.initialized?
|
58
|
+
File.exist?(File.expand_path(".miga_rc", ENV["MIGA_HOME"])) and
|
59
|
+
File.exist?(File.expand_path(".miga_daemon.json", ENV["MIGA_HOME"]))
|
60
|
+
end
|
61
|
+
|
62
|
+
##
|
63
|
+
# Tabulates an +values+, and Array of Arrays, all with the same number of
|
64
|
+
# entries as +header+. Returns an Array of String, one per line.
|
65
|
+
def self.tabulate(header, values)
|
66
|
+
fields = [header.map{ |h| h.to_s }]
|
67
|
+
fields << fields.first.map{ |h| h.gsub(/\S/, "-") }
|
68
|
+
fields += values.map{ |row| row.map{ |cell| cell.nil? ? "?" : cell.to_s } }
|
69
|
+
clen = fields.map{ |row|
|
70
|
+
row.map{ |cell| cell.length } }.transpose.map{ |col| col.max }
|
71
|
+
fields.map do |row|
|
72
|
+
(0 .. clen.size-1).map do |col_n|
|
73
|
+
col_n==0 ? row[col_n].rjust(clen[col_n]) : row[col_n].ljust(clen[col_n])
|
74
|
+
end.join(" ")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
##
|
79
|
+
# Check if the result files exist with +base+ name (String) followed by the
|
80
|
+
# +ext+ values (Array of String).
|
81
|
+
def result_files_exist?(base, ext)
|
82
|
+
ext = [ext] unless ext.kind_of? Array
|
83
|
+
ext.all? do |f|
|
84
|
+
File.exist?(base + f) or File.exist?(base + f + ".gz")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
##
|
91
|
+
# MiGA extensions to the File class.
|
92
|
+
class File
|
93
|
+
|
94
|
+
##
|
95
|
+
# Method to transfer a file from +old_name+ to +new_name+, using a +method+
|
96
|
+
# that can be one of :symlink for File#symlink, :hardlink for File#link, or
|
97
|
+
# :copy for FileUtils#cp_r.
|
98
|
+
def self.generic_transfer(old_name, new_name, method)
|
99
|
+
return nil if exist? new_name
|
100
|
+
case method
|
101
|
+
when :symlink
|
102
|
+
File.symlink(old_name, new_name)
|
103
|
+
when :hardlink
|
104
|
+
File.link(old_name, new_name)
|
105
|
+
when :copy
|
106
|
+
FileUtils.cp_r(old_name, new_name)
|
107
|
+
else
|
108
|
+
raise "Unknown transfer method: #{method}."
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
##
|
115
|
+
# MiGA extensions to the String class.
|
116
|
+
class String
|
117
|
+
|
118
|
+
##
|
119
|
+
# Replace any character not allowed in a MiGA name for underscore (_). This
|
120
|
+
# results in a MiGA-compliant name EXCEPT for empty strings, that results in
|
121
|
+
# empty strings.
|
122
|
+
def miga_name ; gsub(/[^A-Za-z0-9_]/, "_") ; end
|
123
|
+
|
124
|
+
##
|
125
|
+
# Is the string a MiGA-compliant name?
|
126
|
+
def miga_name? ; not(self !~ /^[A-Za-z0-9_]+$/) ; end
|
127
|
+
|
128
|
+
##
|
129
|
+
# Replace underscores by spaces.
|
130
|
+
def unmiga_name ; tr("_", " ") ; end
|
131
|
+
|
132
|
+
end
|