miga-base 0.3.0.1 → 0.3.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 20d84d5171a208f02d6278778c7967ff7d1ec3e5
4
- data.tar.gz: 7f92d205fb8058af84b15c96d158049889efa0ca
3
+ metadata.gz: 128dc675d7890680368567d6d20d4fc37f746852
4
+ data.tar.gz: f58156b654b1463670d48c613c552e55b14d1b18
5
5
  SHA512:
6
- metadata.gz: 3d78f1bf02243234a668e91cd2bafe608a7ca48fd41a11bcee77f6a7164d0222841a0b54ed8c3076f38d47268ff671ac128519d6433284f7fef8286d638c77b4
7
- data.tar.gz: 21ae7b9c7514d542496197541a14ddc3d19dd424f97c04ec1a1913f34dadf93f4b25f76c7d54d2c3c79b4ccb67cf567bb552ea35c263dc62f0db4ab235757ffd
6
+ metadata.gz: 9431dc3c5ce79996bdaf77d9a2bffe06cb32645a95ebbe397164de0706825c50c8da54fdd0574b4ba4123226cbbd3dd7a322a9a5d87d8dd40ced955c618f59ae
7
+ data.tar.gz: 24e4ba089124116c4a12b67df9be0930c11a60af8d70dac3a2525061ffddf195e20b4f130d94de391a474af7782222066f2a41552de5f078234af7f3d03f0972
@@ -12,8 +12,6 @@ OptionParser.new do |opt|
12
12
  ){ |v| o[:ref]=!v }
13
13
  opt.on("-d", "--description STRING",
14
14
  "Description of the dataset."){ |v| o[:description]=v }
15
- opt.on("-u", "--user STRING",
16
- "Owner of the dataset."){ |v| o[:user]=v }
17
15
  opt.on("-c", "--comments STRING",
18
16
  "Comments on the dataset."){ |v| o[:comments]=v }
19
17
  opt.on("-m", "--metadata STRING",
@@ -43,9 +41,7 @@ end.parse!
43
41
 
44
42
  ##=> Main <=
45
43
  opt_require(o)
46
- opt_require(o, type:"-t") unless o[:update]
47
- raise "Unrecognized dataset type: #{o[:type]}." if
48
- (not o[:update]) and MiGA::Dataset.KNOWN_TYPES[o[:type]].nil?
44
+ opt_require_type(o, MiGA::Dataset) unless o[:update]
49
45
 
50
46
  $stderr.puts "Loading project." unless o[:q]
51
47
  p = MiGA::Project.load(o[:project])
@@ -55,7 +51,7 @@ raise "Dataset already exists, aborting." unless
55
51
  o[:update] or not MiGA::Dataset.exist?(p, o[:dataset])
56
52
  $stderr.puts "Loading dataset." unless o[:q]
57
53
  d = o[:update] ? p.dataset(o[:dataset]) :
58
- MiGA::Dataset.new(p, o[:dataset], o[:ref], {})
54
+ MiGA::Dataset.new(p, o[:dataset], o[:ref])
59
55
  raise "Dataset does not exist." if d.nil?
60
56
 
61
57
  in_files = [:raw_reads, :trimmed_fasta_s, :trimmed_fasta_c, :assembly]
@@ -83,21 +79,7 @@ if in_files.any? { |i| not o[i].nil? }
83
79
  cp_result(o, d, p, :assembly, :assembly, %w[.LargeContigs.fna])
84
80
  end
85
81
 
86
- unless o[:metadata].nil?
87
- o[:metadata].split(",").each do |pair|
88
- (k,v) = pair.split("=")
89
- case v
90
- when "true"; v = true
91
- when "false"; v = false
92
- when "nil"; v = nil
93
- end
94
- d.metadata[k] = v
95
- end
96
- end
97
- [:type, :description, :user, :comments].each do |k|
98
- d.metadata[k]=o[k] unless o[k].nil?
99
- end
100
-
82
+ d = add_metadata(o, d)
101
83
  d.save
102
84
  p.add_dataset(o[:dataset]) unless o[:update]
103
85
  res = d.first_preprocessing(true)
@@ -11,9 +11,12 @@ OptionParser.new do |opt|
11
11
  "Name of the project."){ |v| o[:name]=v }
12
12
  opt.on("-d", "--description STRING",
13
13
  "Description of the project."){ |v| o[:description]=v }
14
- opt.on("-u", "--user STRING", "Owner of the project."){ |v| o[:user]=v }
15
14
  opt.on("-c", "--comments STRING",
16
15
  "Comments on the project."){ |v| o[:comments]=v }
16
+ opt.on("-m", "--metadata STRING",
17
+ "Metadata as key-value pairs separated by = and delimited by comma.",
18
+ "Values are saved as strings except for booleans (true / false) or nil."
19
+ ){ |v| o[:metadata]=v }
17
20
  opt.on("--update",
18
21
  "Updates the project if it already exists."){ o[:update]=true }
19
22
  opt_common(opt, o)
@@ -21,14 +24,12 @@ end.parse!
21
24
 
22
25
  ##=> Main <=
23
26
  opt_require(o, project:"-P")
24
- opt_require(o, type:"-t") unless o[:update]
27
+ opt_require_type(o, MiGA::Project) unless o[:update]
25
28
 
26
29
  unless File.exist? "#{ENV["HOME"]}/.miga_rc" and
27
30
  File.exist? "#{ENV["HOME"]}/.miga_daemon.json"
28
- puts "You must initialize MiGA before creating the first project.\n" +
29
- "Do you want to initialize MiGA now? (yes / no)"
30
- `'#{File.dirname(__FILE__)}/../scripts/init.bash'` if
31
- $stdin.gets.chomp == 'yes'
31
+ raise "You must initialize MiGA before creating the first project.\n" +
32
+ "Please use miga init."
32
33
  end
33
34
 
34
35
  $stderr.puts "Creating project." unless o[:q]
@@ -37,11 +38,8 @@ raise "Project already exists, aborting." unless
37
38
  p = MiGA::Project.new(o[:project], o[:update])
38
39
  # The following check is redundant with MiGA::Project#create,
39
40
  # but allows upgrading projects from (very) early code versions
40
- o[:name] = File.basename(p.path) if
41
- o[:update] and o[:name].nil?
42
- [:name, :description, :user, :comments, :type].each do |k|
43
- p.metadata[k] = o[k] unless o[k].nil?
44
- end
41
+ o[:name] = File.basename(p.path) if o[:update] and o[:name].nil?
42
+ p = add_metadata(o, p)
45
43
  p.save
46
44
 
47
45
  $stderr.puts "Done." unless o[:q]
data/actions/init.rb CHANGED
@@ -7,7 +7,7 @@ require "shellwords"
7
7
 
8
8
  o = {q:true, mytaxa:nil, config:File.expand_path(".miga_modules", ENV["HOME"]),
9
9
  ask: false, auto:false, dtype: "bash"}
10
- opts = OptionParser.new do |opt|
10
+ OptionParser.new do |opt|
11
11
  opt_banner(opt)
12
12
  opt.on("-c","--config PATH",
13
13
  "Path to the Bash configuration file.",
@@ -83,7 +83,7 @@ unless File.exist? o[:config]
83
83
  o[:config] = ask_user(
84
84
  "Is there a script I need to load at startup?", o[:config])
85
85
  end
86
- if File.exists? o[:config]
86
+ if File.exist? o[:config]
87
87
  o[:config] = File.expand_path o[:config]
88
88
  $stderr.puts "Found bash configuration script: #{o[:config]}."
89
89
  rc_fh.puts "MIGA_STARTUP='#{o[:config]}'"
data/actions/run_local.rb CHANGED
@@ -6,7 +6,7 @@
6
6
  require "shellwords"
7
7
 
8
8
  o = {q:true, try_load:false, thr:1}
9
- opts = OptionParser.new do |opt|
9
+ OptionParser.new do |opt|
10
10
  opt_banner(opt)
11
11
  opt_object(opt, o, [:project, :dataset_opt, :result])
12
12
  opt.on("-t", "--threads INT",
data/bin/miga CHANGED
@@ -71,7 +71,7 @@ def opt_object(opt, o, what=[:project, :dataset])
71
71
  what.include? :dataset_type_req
72
72
  opt.on("-t", "--type STRING",
73
73
  (what.include?(:project_type_req) ? "(Mandatory) " : "") +
74
- "Type of dataset. Recognized types include:",
74
+ "Type of project. Recognized types include:",
75
75
  *MiGA::Project.KNOWN_TYPES.map{ |k,v| "~ #{k}: #{v[:description]}"}
76
76
  ){ |v| o[:type]=v.to_sym } if what.include? :project_type or
77
77
  what.include? :project_type_req
@@ -116,6 +116,11 @@ def opt_require(o, req={project:"-P", dataset:"-D"})
116
116
  end
117
117
  end
118
118
 
119
+ def opt_require_type(o, klass)
120
+ opt_require(o, type:"-t")
121
+ raise "Unrecognized type: #{o[:type]}." if klass.KNOWN_TYPES[o[:type]].nil?
122
+ end
123
+
119
124
  # Filters datasets by keys set in +opt_filter_datasets+.
120
125
  def filter_datasets!(ds, o)
121
126
  ds.select!{|d| d.is_ref? == o[:ref] } unless o[:ref].nil?
@@ -128,6 +133,22 @@ def filter_datasets!(ds, o)
128
133
  ds
129
134
  end
130
135
 
136
+ def add_metadata(o, obj)
137
+ o[:metadata].split(",").each do |pair|
138
+ (k,v) = pair.split("=")
139
+ case v
140
+ when "true"; v = true
141
+ when "false"; v = false
142
+ when "nil"; v = nil
143
+ end
144
+ obj.metadata[k] = v
145
+ end
146
+ [:type, :name, :user, :description, :comments].each do |k|
147
+ obj.metadata[k] = o[k] unless o[k].nil?
148
+ end
149
+ obj
150
+ end
151
+
131
152
  ##=> Main <=
132
153
 
133
154
  execs = $task_desc.keys.map{ |k| k.to_s }
data/lib/miga/project.rb CHANGED
@@ -283,16 +283,26 @@ class MiGA::Project < MiGA::MiGA
283
283
  ##
284
284
  # Get the next distances task, saving intermediate results if +save+. Returns
285
285
  # a Symbol.
286
- def next_distances(save=true)
287
- @@DISTANCE_TASKS.find{ |t| add_result(t, save).nil? }
288
- end
286
+ def next_distances(save=true) ; next_task(@@DISTANCE_TASKS, save) ; end
289
287
 
290
288
  ##
291
289
  # Get the next inclade task, saving intermediate results if +save+. Returns a
292
290
  # Symbol.
293
- def next_inclade(save=true)
294
- return nil unless metadata[:type]==:clade
295
- @@INCLADE_TASKS.find{ |t| add_result(t, save).nil? }
291
+ def next_inclade(save=true) ; next_task(@@INCLADE_TASKS, save) ; end
292
+
293
+ ##
294
+ # Get the next task from +tasks+, saving intermediate results if +save+.
295
+ # Returns a Symbol.
296
+ def next_task(tasks=@@DISTANCE_TASKS+@@INCLADE_TASKS, save=true)
297
+ tasks.find do |t|
298
+ if metadata["run_#{t}"]==false or
299
+ (!is_clade? and @@INCLADE_TASKS.include?(t) and
300
+ metadata["run_#{t}"]!=true)
301
+ false
302
+ else
303
+ add_result(t, save).nil?
304
+ end
305
+ end
296
306
  end
297
307
 
298
308
  ##
data/lib/miga/result.rb CHANGED
@@ -114,7 +114,7 @@ class MiGA::Result < MiGA::MiGA
114
114
  json = File.read(path)
115
115
  @data = JSON.parse(json, {:symbolize_names=>true})
116
116
  @data[:files] ||= {}
117
- @results = self[:results].map{ |rs| MiGA::Result.new rs }
117
+ @results = (self[:results] || []).map{ |rs| MiGA::Result.new rs }
118
118
  end
119
119
 
120
120
  ##
data/lib/miga/version.rb CHANGED
@@ -10,7 +10,7 @@ module MiGA
10
10
  # - Float representing the major.minor version.
11
11
  # - Integer representing gem releases of the current version.
12
12
  # - Integer representing minor changes that require new version number.
13
- VERSION = [0.3, 0, 1]
13
+ VERSION = [0.3, 0, 2]
14
14
 
15
15
  ##
16
16
  # Nickname for the current major.minor version.
@@ -18,7 +18,7 @@ module MiGA
18
18
 
19
19
  ##
20
20
  # Date of the current gem release.
21
- VERSION_DATE = Date.new(2017, 6, 6)
21
+ VERSION_DATE = Date.new(2017, 6, 14)
22
22
 
23
23
  ##
24
24
  # Reference of MiGA.
data/test/project_test.rb CHANGED
@@ -86,6 +86,16 @@ class ProjectTest < Test::Unit::TestCase
86
86
  assert_equal(MiGA::Result, p1.add_result(:haai_distances).class)
87
87
  end
88
88
 
89
+ def test_result
90
+ p1 = $p1
91
+ assert_nil(p1.result :n00b)
92
+ assert_nil(p1.result :project_stats)
93
+ File.open(File.expand_path("data/90.stats/miga-project.json",p1.path),
94
+ "w"){ |fh| fh.puts "{}" }
95
+ assert_not_nil(p1.result :project_stats)
96
+ assert_equal(1, p1.results.size)
97
+ end
98
+
89
99
  def test_preprocessing
90
100
  p1 = $p1
91
101
  assert(p1.done_preprocessing?)
@@ -142,6 +152,7 @@ class ProjectTest < Test::Unit::TestCase
142
152
  "Impossible to add #{r} result.")
143
153
  end
144
154
  assert_nil(p1.next_inclade)
155
+
145
156
  end
146
157
 
147
158
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: miga-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0.1
4
+ version: 0.3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luis M. Rodriguez-R
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-06 00:00:00.000000000 Z
11
+ date: 2017-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client