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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -0
  3. data/LICENSE +201 -0
  4. data/README.md +17 -335
  5. data/Rakefile +31 -0
  6. data/actions/add_result +2 -5
  7. data/actions/add_taxonomy +4 -7
  8. data/actions/create_dataset +5 -6
  9. data/actions/create_project +2 -5
  10. data/actions/daemon +2 -5
  11. data/actions/download_dataset +88 -58
  12. data/actions/find_datasets +36 -38
  13. data/actions/import_datasets +2 -5
  14. data/actions/index_taxonomy +2 -5
  15. data/actions/list_datasets +47 -49
  16. data/actions/list_files +7 -11
  17. data/actions/unlink_dataset +2 -5
  18. data/bin/miga +1 -1
  19. data/lib/miga/common.rb +132 -0
  20. data/lib/miga/daemon.rb +229 -168
  21. data/lib/miga/dataset.rb +354 -277
  22. data/lib/miga/gui.rb +346 -269
  23. data/lib/miga/metadata.rb +115 -71
  24. data/lib/miga/project.rb +361 -259
  25. data/lib/miga/remote_dataset.rb +200 -148
  26. data/lib/miga/result.rb +150 -99
  27. data/lib/miga/tax_index.rb +124 -67
  28. data/lib/miga/taxonomy.rb +129 -100
  29. data/lib/miga/version.rb +57 -0
  30. data/lib/miga.rb +2 -77
  31. data/scripts/_distances_noref_nomulti.bash +2 -0
  32. data/scripts/_distances_ref_nomulti.bash +2 -0
  33. data/scripts/aai_distances.bash +1 -0
  34. data/scripts/ani_distances.bash +1 -0
  35. data/scripts/assembly.bash +1 -0
  36. data/scripts/cds.bash +1 -0
  37. data/scripts/clade_finding.bash +17 -1
  38. data/scripts/distances.bash +1 -0
  39. data/scripts/essential_genes.bash +1 -0
  40. data/scripts/haai_distances.bash +1 -0
  41. data/scripts/init.bash +2 -0
  42. data/scripts/mytaxa.bash +1 -0
  43. data/scripts/mytaxa_scan.bash +1 -0
  44. data/scripts/ogs.bash +1 -0
  45. data/scripts/read_quality.bash +1 -0
  46. data/scripts/ssu.bash +1 -0
  47. data/scripts/subclades.bash +1 -0
  48. data/scripts/trimmed_fasta.bash +1 -0
  49. data/scripts/trimmed_reads.bash +1 -0
  50. data/test/common_test.rb +82 -0
  51. data/test/daemon_test.rb +53 -0
  52. data/test/dataset_test.rb +156 -0
  53. data/test/jruby_gui_test.rb +20 -0
  54. data/test/metadata_test.rb +48 -0
  55. data/test/project_test.rb +54 -0
  56. data/test/remote_dataset_test.rb +41 -0
  57. data/test/tax_index_test.rb +44 -0
  58. data/test/taxonomy_test.rb +36 -0
  59. data/test/test_helper.rb +32 -0
  60. metadata +53 -38
@@ -1,10 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- #
2
+
3
3
  # @package MiGA
4
- # @author Luis M. Rodriguez-R <lmrodriguezr at gmail dot com>
5
- # @license artistic license 2.0
6
- # @update Oct-01-2015
7
- #
4
+ # @license Artistic-2.0
8
5
 
9
6
  o = {q:true, update:false}
10
7
  OptionParser.new do |opt|
data/actions/daemon CHANGED
@@ -1,10 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- #
2
+
3
3
  # @package MiGA
4
- # @author Luis M. Rodriguez-R <lmrodriguezr at gmail dot com>
5
- # @license artistic license 2.0
6
- # @update Oct-01-2015
7
- #
4
+ # @license Artistic-2.0
8
5
 
9
6
  require "miga/daemon"
10
7
 
@@ -1,77 +1,107 @@
1
1
  #!/usr/bin/env ruby
2
- #
2
+
3
3
  # @package MiGA
4
- # @author Luis M. Rodriguez-R <lmrodriguezr at gmail dot com>
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, ref:true, universe: :ebi, db: :embl}
8
+ o = {q:true, query:false, universe: :ebi, db: :embl}
12
9
  OptionParser.new do |opt|
13
- opt.banner = <<BAN
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
- opt.separator ""
19
- opt.on("-P", "--project PATH",
20
- "(Mandatory) Path to the project to use."){ |v| o[:project]=v }
21
- opt.on("-D", "--dataset STRING",
22
- "(Mandatory) ID of the dataset to create."){ |v| o[:dataset]=v }
23
- opt.on("-I", "--ids ID1,ID2,...",
24
- "(Mandatory) IDs in the remote database separated by commas."
25
- ){ |v| o[:ids]=v }
26
- opt.on("-U", "--universe STRING",
27
- "Universe where the remote database lives. By default: #{o[:universe]}."
28
- ){ |v| o[:universe]=v.to_sym }
29
- opt.on("--db STRING",
30
- "Name of the remote database. By default: #{o[:db]}."
31
- ){ |v| o[:db]=v.to_sym }
32
- opt.on("-t", "--type STRING",
33
- "Type of dataset. Recognized types include:",
34
- *MiGA::Dataset.KNOWN_TYPES.map{ |k,v| "~ #{k}: #{v[:description]}"}
35
- ){ |v| o[:type]=v.to_sym }
36
- opt.on("-q", "--query",
37
- "If set, the dataset is registered as a query, not a reference dataset."
38
- ){ |v| o[:ref]=!v }
39
- opt.on("-d", "--description STRING",
40
- "Description of the dataset."){ |v| o[:description]=v }
41
- opt.on("-u", "--user STRING",
42
- "Owner of the dataset."){ |v| o[:user]=v }
43
- opt.on("-c", "--comments STRING",
44
- "Comments on the dataset."){ |v| o[:comments]=v }
45
- opt.on("-v", "--verbose",
46
- "Print additional information to STDERR."){ o[:q]=false }
47
- opt.on("-d", "--debug INT", "Print debugging information to STDERR.") do |v|
48
- v.to_i>1 ? MiGA::MiGA.DEBUG_TRACE_ON : MiGA::MiGA.DEBUG_ON
49
- end
50
- opt.on("-h", "--help", "Display this screen.") do
51
- puts opt
52
- exit
53
- end
54
- opt.separator ""
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
- raise "-P is mandatory." if o[:project].nil?
60
- raise "-D is mandatory." if o[:dataset].nil?
61
- raise "-I is mandatory." if o[:ids].nil?
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
- $stderr.puts "Locating remote dataset." unless o[:q]
64
- rd = MiGA::RemoteDataset.new(o[:ids], o[:db], o[:universe])
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 "Loading project." unless o[:q]
67
- p = MiGA::Project.load(o[:project])
68
- raise "Impossible to load project: #{o[:project]}" if p.nil?
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
- $stderr.puts "Creating dataset." unless o[:q]
71
- md = {}
72
- [:type, :description, :user, :comments].each{ |k| md[k]=o[k] unless o[k].nil? }
73
- d = rd.save_to(p, o[:dataset], o[:ref], md)
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 "Done." unless o[:q]
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
@@ -1,42 +1,39 @@
1
1
  #!/usr/bin/env ruby
2
- #
2
+
3
3
  # @package MiGA
4
- # @author Luis M. Rodriguez-R <lmrodriguezr at gmail dot com>
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
- opt.banner = <<BAN
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
- opt.separator ""
17
- opt.on("-P", "--project PATH",
18
- "(Mandatory) Path to the project to use."){ |v| o[:project]=v }
19
- opt.on("-a", "--add",
20
- "Register the datasets found. By default, only lists them (dry run)."
21
- ){ |v| o[:add]=v }
22
- opt.on("-t", "--type STRING",
23
- "Type of datasets. Recognized types include:",
24
- *MiGA::Dataset.KNOWN_TYPES.map{ |k,v| "~ #{k}: #{v[:description]}"}
25
- ){ |v| o[:type]=v.to_sym }
26
- opt.on("-r", "--ref",
27
- "If set, all datasets are registered as reference datasets."
28
- ){ |v| o[:ref]=v }
29
- opt.on("-u", "--user STRING", "Owner of the dataset."){ |v| o[:user]=v }
30
- opt.on("-v", "--verbose",
31
- "Print additional information to STDERR."){ o[:q]=false }
32
- opt.on("-d", "--debug INT", "Print debugging information to STDERR.") do |v|
33
- v.to_i>1 ? MiGA::MiGA.DEBUG_TRACE_ON : MiGA::MiGA.DEBUG_ON
34
- end
35
- opt.on("-h", "--help", "Display this screen.") do
36
- puts opt
37
- exit
38
- end
39
- opt.separator ""
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
- puts dn
54
- if o[:add]
55
- md = {}
56
- [:type, :user].each{ |k| md[k]=o[k] unless o[k].nil? }
57
- d = MiGA::Dataset.new(p, dn, o[:ref], md)
58
- p.add_dataset(dn)
59
- end
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
-
@@ -1,10 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- #
2
+
3
3
  # @package MiGA
4
- # @author Luis M. Rodriguez-R <lmrodriguezr at gmail dot com>
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|
@@ -1,10 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- #
2
+
3
3
  # @package MiGA
4
- # @author Luis M. Rodriguez-R <lmrodriguezr at gmail dot com>
5
- # @license artistic license 2.0
6
- # @update Oct-01-2015
7
- #
4
+ # @license Artistic-2.0
8
5
 
9
6
  require "miga/tax_index"
10
7
 
@@ -1,46 +1,45 @@
1
1
  #!/usr/bin/env ruby
2
- #
2
+
3
3
  # @package MiGA
4
- # @author Luis M. Rodriguez-R <lmrodriguezr at gmail dot com>
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
- opt.banner = <<BAN
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
- opt.separator ""
17
- opt.on("-P", "--project PATH",
18
- "(Mandatory) Path to the project to read."){ |v| o[:project]=v }
19
- opt.on("-D", "--dataset STRING",
20
- "ID of the dataset to read."){ |v| o[:dataset]=v.miga_name }
21
- opt.on("--[no-]ref",
22
- "If set, lists only reference (or only non-reference) datasets."
23
- ){ |v| o[:ref]=v }
24
- opt.on("--[no-]multi",
25
- "If set, lists only multi-species (or only single-species) datasets."
26
- ){ |v| o[:multi]=v }
27
- opt.on("-i", "--info",
28
- "Print additional information on each dataset."){ o[:info]=true }
29
- opt.on("-t", "--taxonomy RANK:TAXON",
30
- "Filter by taxonomy."){ |v| o[:taxonomy]=MiGA::Taxonomy.new v }
31
- opt.on("-m", "--metadata STRING",
32
- "Print name and metadata field only. If set, ignores -i."
33
- ){ |v| o[:datum]=v }
34
- opt.on("-v", "--verbose",
35
- "Print additional information to STDERR."){ o[:q]=false }
36
- opt.on("-d", "--debug INT", "Print debugging information to STDERR.") do |v|
37
- v.to_i>1 ? MiGA::MiGA.DEBUG_TRACE_ON : MiGA::MiGA.DEBUG_ON
38
- end
39
- opt.on("-h", "--help", "Display this screen.") do
40
- puts opt
41
- exit
42
- end
43
- opt.separator ""
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
- ds = p.datasets
55
+ ds = p.datasets
57
56
  elsif MiGA::Dataset.exist? p, o[:dataset]
58
- ds = [p.dataset(o[:dataset])]
57
+ ds = [p.dataset(o[:dataset])]
59
58
  else
60
- ds = []
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
- (not d.metadata[:type].nil?) and
65
- (MiGA::Dataset.KNOWN_TYPES[d.metadata[:type]][:multi] == o[:multi])
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
- (not d.metadata[:tax].nil?) and d.metadata[:tax].is_in?(o[:taxonomy])
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
- ds.each{|d| puts "#{d.name}\t#{(d.metadata[ o[:datum] ] || "?").to_s}"}
70
+ ds.each{|d| puts "#{d.name}\t#{d.metadata[ o[:datum] ] || "?"}"}
72
71
  elsif o[:info]
73
- header = MiGA::Dataset.INFO_FIELDS.map{|i| i.ljust(25)}.join(" ")
74
- puts header, header.gsub(/\S/,"-")
75
- ds.each do |d|
76
- puts d.info.map{|i| i.nil? ? "?" : i.to_s}.map{|i| i.ljust(25)}.join(" ")
77
- end
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
- ds.each{|d| puts d.name}
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
- # @author Luis M. Rodriguez-R <lmrodriguezr at gmail dot com>
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("--exclude-json",
26
- "If set, excludes json files containing results metadata."
27
- ){ |v| o[:json]=!v }
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 (o[:details] ? result.path + "\t" + "\t" : "") + result.path if o[:json]
56
+ puts "#{ "#{result.path}\t\t" if o[:details] }#{result.path}" if o[:json]
60
57
  result.each_file do |k,f|
61
- puts (o[:details] ? result.path + "\t" + k.to_s + "\t" : "") +
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
 
@@ -1,10 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- #
2
+
3
3
  # @package MiGA
4
- # @author Luis M. Rodriguez-R <lmrodriguezr at gmail dot com>
5
- # @license artistic license 2.0
6
- # @update Oct-01-2015
7
- #
4
+ # @license Artistic-2.0
8
5
 
9
6
  o = {q:true, remove:false}
10
7
  OptionParser.new do |opt|
data/bin/miga CHANGED
@@ -31,7 +31,7 @@ elsif execs.include? ARGV[0]
31
31
  err
32
32
  end
33
33
  else
34
- print <<HELP.gsub /^ /,""
34
+ print <<HELP.gsub(/^ /,"")
35
35
  Microbial Genomes Atlas.
36
36
 
37
37
  Usage: #{$0} {action} [options]
@@ -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