miga-base 0.7.23.0 → 0.7.24.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -0
  3. data/Rakefile +1 -0
  4. data/lib/miga/cli/action/add.rb +1 -2
  5. data/lib/miga/cli/action/classify_wf.rb +12 -11
  6. data/lib/miga/cli/action/derep_wf.rb +3 -9
  7. data/lib/miga/cli/action/edit.rb +0 -1
  8. data/lib/miga/cli/action/find.rb +1 -1
  9. data/lib/miga/cli/action/generic.rb +1 -1
  10. data/lib/miga/cli/action/get.rb +7 -2
  11. data/lib/miga/cli/action/ncbi_get.rb +1 -1
  12. data/lib/miga/cli/action/new.rb +15 -9
  13. data/lib/miga/cli/action/option.rb +44 -0
  14. data/lib/miga/cli/action/quality_wf.rb +3 -3
  15. data/lib/miga/cli/action/tax_dist.rb +1 -1
  16. data/lib/miga/cli/action/tax_test.rb +1 -1
  17. data/lib/miga/cli/action/wf.rb +32 -30
  18. data/lib/miga/cli/base.rb +1 -0
  19. data/lib/miga/cli/objects_helper.rb +23 -18
  20. data/lib/miga/common.rb +1 -1
  21. data/lib/miga/common/with_option.rb +83 -0
  22. data/lib/miga/common/with_result.rb +2 -1
  23. data/lib/miga/dataset/base.rb +20 -2
  24. data/lib/miga/dataset/result.rb +1 -1
  25. data/lib/miga/metadata.rb +25 -13
  26. data/lib/miga/project/base.rb +82 -2
  27. data/lib/miga/project/result.rb +4 -4
  28. data/lib/miga/result/stats.rb +2 -2
  29. data/lib/miga/version.rb +2 -2
  30. data/scripts/essential_genes.bash +1 -2
  31. data/scripts/ogs.bash +2 -3
  32. data/test/dataset_test.rb +5 -5
  33. data/test/with_option_test.rb +115 -0
  34. data/utils/cleanup-databases.rb +1 -2
  35. data/utils/distance/commands.rb +2 -2
  36. data/utils/distance/database.rb +1 -1
  37. data/utils/distance/pipeline.rb +2 -4
  38. data/utils/distance/runner.rb +15 -23
  39. data/utils/index_metadata.rb +1 -2
  40. data/utils/subclade/runner.rb +9 -10
  41. metadata +6 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ed8981c0dfc266aea53be66e06b77eaf277444a094ef460021c2713aef3bf73
4
- data.tar.gz: d9f0bd3934dd5e3ba27cb58adfd1236a74ba6b003a06cd74b9da96e594a27e99
3
+ metadata.gz: 82ca84b468df712ab38eba74071c26e8dcb1d87335764dde2ba86075abc8c8d5
4
+ data.tar.gz: 36583e298fc020faa5cc16af2f6a3fcc88c30619a4f529fd6f03772f6c437bb9
5
5
  SHA512:
6
- metadata.gz: f40242b96f36ce5528e2206aa4f366d047b5969a45d69cff5ac825297563f9adddaee957e562eddae34c96b8a0651fd2fec39a42d2cd278d66ea03ac35afabfc
7
- data.tar.gz: ab01b09ab020c1bfcf5dd5be7a01c971e83e02066ad35f4b6a9f0c525351c81b5cdb0e80910cf4237b9e59a33c518995a073c1f625f049b6b722802541d11c1f
6
+ metadata.gz: d78a3709fecba4594d8dc9a2351f217b3605022237e424eb1a194ccf62ddf2059eb1df274f68a15cda74936dfece3f2123485483773172cc62cfba9ff454c5d2
7
+ data.tar.gz: fbf11b04c062701b204f4ba93425dea6f8ff1492fe48f7182472e65b16fccbde98e86d396a79cf51c6e410a246c3b9e9509043eaf952b320191ec086e2efa573
data/Gemfile CHANGED
@@ -1,6 +1,9 @@
1
1
  source "https://rubygems.org"
2
2
  gemspec name: "miga-base"
3
+
3
4
  group :test do
4
5
  gem "simplecov"
5
6
  gem "codeclimate-test-reporter", "~> 1.0.0"
6
7
  end
8
+
9
+ gem "rake", "~> 12.0"
data/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
+ require 'bundler/gem_tasks'
1
2
  require 'rake/testtask'
2
3
 
3
4
  SOURCES = FileList['lib/**/*.rb']
@@ -65,8 +65,7 @@ class MiGA::Cli::Action::Add < MiGA::Cli::Action
65
65
  next if d.nil?
66
66
 
67
67
  copy_file_to_project(file, file_type, d, p)
68
- d = cli.add_metadata(d)
69
- d.save
68
+ cli.add_metadata(d)
70
69
  p.add_dataset(d.name)
71
70
  res = d.first_preprocessing(true)
72
71
  cli.say " result: #{res}"
@@ -49,23 +49,24 @@ class MiGA::Cli::Action::ClassifyWf < MiGA::Cli::Action
49
49
  def perform
50
50
  # Input data
51
51
  ref_db = reference_db
52
- p_metadata = Hash[
53
- %w[project_stats haai_distances aai_distances ani_distances clade_finding]
54
- .map { |i| ["run_#{i}", false] }
52
+ norun = %w[
53
+ project_stats haai_distances aai_distances ani_distances clade_finding
55
54
  ]
56
- p_metadata[:ref_project] = ref_db.path
57
- p_metadata[:tax_pvalue] = cli[:pvalue]
58
- p = create_project(:assembly, p_metadata,
59
- run_ssu: false, run_mytaxa_scan: false, run_distances: false)
55
+ p_metadata = Hash[norun.map { |i| ["run_#{i}", false] }]
56
+ p = create_project(
57
+ :assembly,
58
+ p_metadata,
59
+ run_ssu: false, run_mytaxa_scan: false, run_distances: false
60
+ )
61
+ p.set_option(:ref_project, ref_db.path)
62
+ p.set_option(:tax_pvalue, cli[:pvalue], true)
60
63
  # Run
61
64
  run_daemon
62
65
  summarize(%w[cds assembly essential_genes]) if cli[:summaries]
63
66
  summarize(['taxonomy'])
64
67
  cli.say "Summary: classification"
65
- call_cli([
66
- 'ls', '-P', cli[:outdir], '-m', 'tax', '--tab',
67
- '-o', File.expand_path('classification.tsv', cli[:outdir])
68
- ])
68
+ ofile = File.expand_path('classification.tsv', cli[:outdir])
69
+ call_cli(['ls', '-P', cli[:outdir], '-m', 'tax', '--tab', '-o', ofile])
69
70
  cleanup
70
71
  end
71
72
 
@@ -52,17 +52,11 @@ class MiGA::Cli::Action::DerepWf < MiGA::Cli::Action
52
52
  # Input data
53
53
  p = create_project(
54
54
  :assembly,
55
- {
56
- run_project_stats: false,
57
- run_clades: false,
58
- gsp_metric: cli[:metric],
59
- :"gsp_#{cli[:metric]}" => cli[:threshold]
60
- },
55
+ { run_project_stats: false, run_clades: false },
61
56
  { run_mytaxa_scan: false, run_ssu: false }
62
57
  )
63
- unless cli[:threshold] >= 0.0 && cli[:threshold] <= 100.0
64
- raise 'The threshold of identity must be in the range [0,100]'
65
- end
58
+ p.set_option(:gsp_metric, cli[:metric])
59
+ p.set_option(:"gsp_#{cli[:metric]}", cli[:threshold])
66
60
 
67
61
  # Run
68
62
  run_daemon
@@ -34,6 +34,5 @@ class MiGA::Cli::Action::Edit < MiGA::Cli::Action
34
34
  cli[:activate] ? obj.activate! : obj.inactivate!(cli[:reason])
35
35
  end
36
36
  cli.add_metadata(obj)
37
- obj.save
38
37
  end
39
38
  end
@@ -37,7 +37,7 @@ class MiGA::Cli::Action::Find < MiGA::Cli::Action
37
37
  if cli[:add]
38
38
  cli.say "Registering: #{dn}"
39
39
  d = Dataset.new(p, dn, cli[:ref])
40
- d = add_metadata(d)
40
+ add_metadata(d)
41
41
  p.add_dataset(dn)
42
42
  res = d.first_preprocessing(true)
43
43
  cli.say "- #{res}"
@@ -20,7 +20,7 @@ class MiGA::Cli::Action::Generic < MiGA::Cli::Action
20
20
  opt.on(
21
21
  '-v', '--version',
22
22
  'Show MiGA version'
23
- ) { puts MiGA::MiGA.VERSION; exit }
23
+ ) { puts MiGA::MiGA.FULL_VERSION; exit }
24
24
  opt.on(
25
25
  '-V', '--long-version',
26
26
  'Show complete MiGA version'
@@ -6,8 +6,9 @@ require 'miga/remote_dataset'
6
6
 
7
7
  class MiGA::Cli::Action::Get < MiGA::Cli::Action
8
8
  def parse_cli
9
- cli.defaults = { query: false, universe: :ncbi, db: :nuccore,
10
- get_md: false, only_md: false }
9
+ cli.defaults = {
10
+ query: false, universe: :ncbi, db: :nuccore, get_md: false, only_md: false
11
+ }
11
12
  cli.parse do |opt|
12
13
  cli.opt_object(opt, [:project, :dataset, :dataset_type])
13
14
  opt.on(
@@ -141,6 +142,10 @@ class MiGA::Cli::Action::Get < MiGA::Cli::Action
141
142
 
142
143
  def create_dataset(sub_cli, p, rd)
143
144
  sub_cli.say 'Creating dataset'
145
+ if Dataset.exist?(p, sub_cli[:dataset])
146
+ raise "Dataset already exists: #{sub_cli[:dataset]}"
147
+ end
148
+
144
149
  dummy_d = Dataset.new(p, sub_cli[:dataset])
145
150
  md = sub_cli.add_metadata(dummy_d).metadata.data
146
151
  md[:metadata_only] = true if cli[:only_md]
@@ -269,7 +269,7 @@ class MiGA::Cli::Action::NcbiGet < MiGA::Cli::Action
269
269
  else
270
270
  cli.say ' Creating dataset'
271
271
  rd.save_to(p, name, !cli[:query], body[:md])
272
- cli.add_metadata(p.add_dataset(name)).save
272
+ cli.add_metadata(p.add_dataset(name))
273
273
  end
274
274
  end
275
275
  end
@@ -24,6 +24,11 @@ class MiGA::Cli::Action::New < MiGA::Cli::Action
24
24
  'Use faster identity engines (Diamond-AAI and FastANI)',
25
25
  'Equivalent to: -m aai_p=diamond,ani_p=fastani'
26
26
  ) { |v| cli[:fast] = v }
27
+ opt.on(
28
+ '--sensitive',
29
+ 'Use more sensitive identity engines (BLAST+)',
30
+ 'Equivalent to: -m aai_p=blast+,ani_p=blast+'
31
+ ) { |v| cli[:sensitive] = v }
27
32
  opt.on(
28
33
  '-m', '--metadata STRING',
29
34
  'Metadata as key-value pairs separated by = and delimited by comma',
@@ -35,20 +40,21 @@ class MiGA::Cli::Action::New < MiGA::Cli::Action
35
40
  def perform
36
41
  cli.ensure_type(MiGA::Project)
37
42
  cli.ensure_par(project: '-P')
38
- unless File.exist?(File.join(ENV['HOME'], '.miga_rc')) &&
39
- File.exist?(File.join(ENV['HOME'], '.miga_daemon.json'))
40
- raise "You must initialize MiGA before creating the first project.\n" +
41
- 'Please use "miga init".'
43
+ unless MiGA::MiGA.initialized?
44
+ raise 'MiGA has not been initialized, please use "miga init" first'
42
45
  end
43
46
  cli.say "Creating project: #{cli[:project]}"
44
- raise 'Project already exists, aborting.' if Project.exist? cli[:project]
47
+ raise 'Project already exists, aborting' if Project.exist?(cli[:project])
45
48
 
46
49
  p = Project.new(cli[:project], false)
47
50
  p = cli.add_metadata(p)
48
- if cli[:fast]
49
- p.metadata[:aai_p] = 'diamond'
50
- p.metadata[:ani_p] = 'fastani'
51
+
52
+ if cli[:sensitive]
53
+ p.set_option(:aai_p, 'blast+')
54
+ p.set_option(:ani_p, 'blast+')
55
+ elsif cli[:fast]
56
+ p.set_option(:aai_p, 'diamond')
57
+ p.set_option(:ani_p, 'fastani')
51
58
  end
52
- p.save
53
59
  end
54
60
  end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'miga/cli/action'
4
+
5
+ ##
6
+ # CLI: `miga option`
7
+ class MiGA::Cli::Action::Option < MiGA::Cli::Action
8
+ def parse_cli
9
+ cli.parse do |opt|
10
+ cli.opt_object(opt, %i[project dataset_opt])
11
+ opt.on(
12
+ '-k', '--key STRING',
13
+ 'Option name to get or set (by default, all options are printed)'
14
+ ) { |v| cli[:key] = v }
15
+ opt.on(
16
+ '--value STRING',
17
+ 'Value of the option to set (by default, option value is not changed)',
18
+ 'Recognized tokens: nil, true, false'
19
+ ) { |v| cli[:value] = v }
20
+ opt.on(
21
+ '-o', '--output PATH',
22
+ 'Create output file instead of returning to STDOUT'
23
+ ) { |v| cli[:output] = v }
24
+ end
25
+ end
26
+
27
+ def perform
28
+ unless cli[:value].nil?
29
+ cli.ensure_par(
30
+ { key: '-k' },
31
+ '%<name>s is mandatory when --value is set: please provide %<flag>s'
32
+ )
33
+ end
34
+ obj = cli.load_project_or_dataset
35
+ io = cli[:output].nil? ? $stdout : File.open(cli[:output], 'w')
36
+ if cli[:key].nil?
37
+ cli.table(%w[Key Value], obj.all_options.to_a, io)
38
+ else
39
+ obj.set_option(cli[:key], cli[:value], true) unless cli[:value].nil?
40
+ io.puts obj.option(cli[:key])
41
+ end
42
+ io.close unless cli[:output].nil?
43
+ end
44
+ end
@@ -21,10 +21,10 @@ class MiGA::Cli::Action::QualityWf < MiGA::Cli::Action
21
21
 
22
22
  def perform
23
23
  # Input data
24
- p_metadata = Hash[
25
- %w[project_stats haai_distances aai_distances ani_distances clade_finding]
26
- .map { |i| ["run_#{i}", false] }
24
+ norun = %w[
25
+ project_stats haai_distances aai_distances ani_distances clade_finding
27
26
  ]
27
+ p_metadata = Hash[norun.map { |i| ["run_#{i}", false] }]
28
28
  d_metadata = { run_distances: false }
29
29
  d_metadata[:run_mytaxa_scan] = false unless cli[:mytaxa]
30
30
  p = create_project(:assembly, p_metadata, d_metadata)
@@ -47,7 +47,7 @@ class MiGA::Cli::Action::TaxDist < MiGA::Cli::Action
47
47
 
48
48
  def read_distances
49
49
  p = cli.load_project
50
- cli[:metric] ||= p.is_clade? ? 'ani' : 'aai'
50
+ cli[:metric] ||= p.clade? ? 'ani' : 'aai'
51
51
  res_n = "#{cli[:metric]}_distances"
52
52
  cli.say "Reading distances: 1-#{cli[:metric].upcase}"
53
53
  res = p.result(res_n)
@@ -59,7 +59,7 @@ class MiGA::Cli::Action::TaxTest < MiGA::Cli::Action
59
59
  cli.puts "Closest relative: #{cr[0]} with AAI: #{cr[1]}."
60
60
  p = cli.load_project
61
61
  if cli[:ref_project]
62
- if (ref = p.metadata[:ref_project]).nil?
62
+ if (ref = p.option(:ref_project)).nil?
63
63
  raise '--ref-project requested but no reference project has been set'
64
64
  end
65
65
  if (q = MiGA::Project.load(ref)).nil?
@@ -9,7 +9,7 @@ module MiGA::Cli::Action::Wf
9
9
  cli.defaults = {
10
10
  clean: false, regexp: MiGA::Cli.FILE_REGEXP,
11
11
  project_type: :genomes, dataset_type: :popgenome,
12
- ncbi_draft: true, min_qual: 25.0
12
+ ncbi_draft: true, min_qual: MiGA::Project.OPTIONS[:min_qual][:default]
13
13
  }
14
14
  end
15
15
 
@@ -125,32 +125,34 @@ module MiGA::Cli::Action::Wf
125
125
  dataset_type: '--dataset-type'
126
126
  )
127
127
  # Create empty project
128
- call_cli([
129
- 'new',
130
- '-P', cli[:outdir],
131
- '-t', cli[:project_type]
132
- ]) unless MiGA::Project.exist? cli[:outdir]
128
+ call_cli(
129
+ ['new', '-P', cli[:outdir], '-t', cli[:project_type]]
130
+ ) unless MiGA::Project.exist? cli[:outdir]
133
131
  # Define project metadata
134
132
  p = cli.load_project(:outdir, '-o')
135
- %i[haai_p aai_p ani_p ess_coll min_qual].each { |i| p_metadata[i] = cli[i] }
136
133
  p_metadata[:type] = cli[:project_type]
137
134
  transfer_metadata(p, p_metadata)
135
+ %i[haai_p aai_p ani_p ess_coll min_qual].each do |i|
136
+ p.set_option(i, cli[i])
137
+ end
138
138
  # Download datasets
139
- call_cli([
140
- 'ncbi_get',
141
- '-P', cli[:outdir],
142
- '-T', cli[:ncbi_taxon],
143
- (cli[:ncbi_draft] ? '--all' : '--complete')
144
- ]) unless cli[:ncbi_taxon].nil?
139
+ unless cli[:ncbi_taxon].nil?
140
+ what = cli[:ncbi_draft] ? '--all' : '--complete'
141
+ call_cli(
142
+ ['ncbi_get', '-P', cli[:outdir], '-T', cli[:ncbi_taxon], what]
143
+ )
144
+ end
145
145
  # Add datasets
146
- call_cli([
147
- 'add',
148
- '--ignore-dups',
149
- '-P', cli[:outdir],
150
- '-t', cli[:dataset_type],
151
- '-i', stage,
152
- '-R', cli[:regexp]
153
- ] + cli.files) unless cli.files.empty?
146
+ call_cli(
147
+ [
148
+ 'add',
149
+ '--ignore-dups',
150
+ '-P', cli[:outdir],
151
+ '-t', cli[:dataset_type],
152
+ '-i', stage,
153
+ '-R', cli[:regexp]
154
+ ] + cli.files
155
+ ) unless cli.files.empty?
154
156
  # Define datasets metadata
155
157
  p.load
156
158
  d_metadata[:type] = cli[:dataset_type]
@@ -161,13 +163,13 @@ module MiGA::Cli::Action::Wf
161
163
  def summarize(which = %w[cds assembly essential_genes ssu])
162
164
  which.each do |r|
163
165
  cli.say "Summary: #{r}"
164
- call_cli([
165
- 'summary',
166
- '-P', cli[:outdir],
167
- '-r', r,
168
- '-o', File.expand_path("#{r}.tsv", cli[:outdir]),
169
- '--tab', '--ref', '--active'
170
- ])
166
+ call_cli(
167
+ [
168
+ 'summary',
169
+ '-P', cli[:outdir], '-r', r, '--tab', '--ref', '--active',
170
+ '-o', File.join(cli[:outdir], "#{r}.tsv")
171
+ ]
172
+ )
171
173
  end
172
174
  call_cli(['browse', '-P', cli[:outdir]])
173
175
  end
@@ -193,14 +195,14 @@ module MiGA::Cli::Action::Wf
193
195
  cmd += ['--max-jobs', cli[:jobs]] unless cli[:jobs].nil?
194
196
  cmd += ['--ppn', cli[:threads]] unless cli[:threads].nil?
195
197
  cwd = Dir.pwd
196
- call_cli cmd
198
+ call_cli(cmd)
197
199
  Dir.chdir(cwd)
198
200
  end
199
201
 
200
202
  def transfer_metadata(obj, md)
201
203
  # Clear old metadata
202
204
  obj.metadata.each do |k, v|
203
- obj.metadata[k] = nil if k.to_s =~ /^run_/ || k == :ref_project
205
+ obj.metadata[k] = nil if k.to_s =~ /^run_/ || obj.option?(k)
204
206
  end
205
207
  # Transfer and save
206
208
  md.each { |k, v| obj.metadata[k] = v }
data/lib/miga/cli/base.rb CHANGED
@@ -34,6 +34,7 @@ module MiGA::Cli::Base
34
34
  next_step: 'Return the next task to run in a dataset or project',
35
35
  # Objects (Datasets or Projects)
36
36
  edit: 'Edit the metadata of a dataset or project',
37
+ option: 'Get or set options of a dataset or project',
37
38
  # System
38
39
  init: 'Initialize MiGA to process new projects',
39
40
  daemon: 'Control the daemon of a MiGA project',
@@ -57,12 +57,12 @@ module MiGA::Cli::ObjectsHelper
57
57
  ds.select! do |d|
58
58
  advance('Datasets:', k += 1, n, false)
59
59
  o = true
60
- o &&= (d.is_ref? == self[:ref]) unless self[:ref].nil?
61
- o &&= (d.is_active? == self[:active]) unless self[:active].nil?
62
- o &&= (self[:multi] ? d.is_multi? :
63
- d.is_nonmulti?) unless self[:multi].nil?
64
- o &&= (not d.metadata[:tax].nil?) &&
65
- d.metadata[:tax].in?(self[:taxonomy]) unless self[:taxonomy].nil?
60
+ o &&= (d.ref? == self[:ref]) unless self[:ref].nil?
61
+ o &&= (d.active? == self[:active]) unless self[:active].nil?
62
+ o &&= (self[:multi] ? d.multi? : d.nonmulti?) unless self[:multi].nil?
63
+ unless self[:taxonomy].nil?
64
+ o &&= !d.metadata[:tax].nil? && d.metadata[:tax].in?(self[:taxonomy])
65
+ end
66
66
  o
67
67
  end
68
68
  say ''
@@ -90,22 +90,27 @@ module MiGA::Cli::ObjectsHelper
90
90
  def add_metadata(obj, cli = self)
91
91
  raise "Unsupported object: #{obj.class}" unless obj.respond_to? :metadata
92
92
 
93
- cli[:metadata].split(',').each do |pair|
93
+ (cli[:metadata] || '').split(',').each do |pair|
94
94
  (k, v) = pair.split('=')
95
- case v
96
- when 'true'; v = true
97
- when 'false'; v = false
98
- when 'nil'; v = nil
99
- end
100
- if k == '_step'
101
- obj.metadata["_try_#{v}"] ||= 0
102
- obj.metadata["_try_#{v}"] += 1
95
+ if obj.option?(k)
96
+ obj.set_option(k, v, true)
97
+ else
98
+ case v
99
+ when 'true'; v = true
100
+ when 'false'; v = false
101
+ when 'nil'; v = nil
102
+ end
103
+ if k == '_step'
104
+ obj.metadata["_try_#{v}"] ||= 0
105
+ obj.metadata["_try_#{v}"] += 1
106
+ end
107
+ obj.metadata[k] = v
103
108
  end
104
- obj.metadata[k] = v
105
- end unless cli[:metadata].nil?
106
- [:type, :name, :user, :description, :comments].each do |k|
109
+ end
110
+ %i[type name user description comments].each do |k|
107
111
  obj.metadata[k] = cli[k] unless cli[k].nil?
108
112
  end
113
+ obj.save
109
114
  obj
110
115
  end
111
116
  end