miga-base 0.4.1.0 → 0.4.2.0
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/bin/miga +2 -244
- data/lib/miga/cli/action/about.rb +44 -0
- data/lib/miga/cli/action/add.rb +139 -0
- data/lib/miga/cli/action/add_result.rb +26 -0
- data/lib/miga/cli/action/console.rb +19 -0
- data/lib/miga/cli/action/daemon.rb +74 -0
- data/lib/miga/cli/action/date.rb +18 -0
- data/lib/miga/cli/action/doctor.rb +210 -0
- data/lib/miga/cli/action/edit.rb +24 -0
- data/lib/miga/cli/action/files.rb +31 -0
- data/lib/miga/cli/action/find.rb +48 -0
- data/lib/miga/cli/action/generic.rb +44 -0
- data/lib/miga/cli/action/get.rb +132 -0
- data/lib/miga/cli/action/init.rb +343 -0
- data/lib/miga/cli/action/ln.rb +42 -0
- data/lib/miga/cli/action/ls.rb +55 -0
- data/lib/miga/cli/action/ncbi_get.rb +218 -0
- data/lib/miga/cli/action/new.rb +45 -0
- data/lib/miga/cli/action/next_step.rb +27 -0
- data/lib/miga/cli/action/plugins.rb +28 -0
- data/lib/miga/cli/action/rm.rb +25 -0
- data/lib/miga/cli/action/run.rb +39 -0
- data/lib/miga/cli/action/stats.rb +140 -0
- data/lib/miga/cli/action/summary.rb +49 -0
- data/lib/miga/cli/action/tax_dist.rb +102 -0
- data/lib/miga/cli/action/tax_index.rb +47 -0
- data/lib/miga/cli/action/tax_set.rb +59 -0
- data/lib/miga/cli/action/tax_test.rb +77 -0
- data/lib/miga/cli/action.rb +66 -0
- data/lib/miga/cli/base.rb +90 -0
- data/lib/miga/cli.rb +426 -0
- data/lib/miga/project/result.rb +14 -6
- data/lib/miga/remote_dataset.rb +1 -1
- data/lib/miga/tax_index.rb +5 -4
- data/lib/miga/taxonomy/base.rb +63 -0
- data/lib/miga/taxonomy.rb +87 -92
- data/lib/miga/version.rb +6 -6
- data/test/taxonomy_test.rb +49 -9
- data/utils/distance/commands.rb +11 -11
- data/utils/distance/pipeline.rb +5 -5
- metadata +43 -49
- data/actions/about.rb +0 -43
- data/actions/add.rb +0 -129
- data/actions/add_result.rb +0 -30
- data/actions/daemon.rb +0 -55
- data/actions/date.rb +0 -14
- data/actions/doctor.rb +0 -201
- data/actions/edit.rb +0 -33
- data/actions/files.rb +0 -43
- data/actions/find.rb +0 -41
- data/actions/get.rb +0 -105
- data/actions/init.rb +0 -301
- data/actions/ln.rb +0 -47
- data/actions/ls.rb +0 -61
- data/actions/ncbi_get.rb +0 -192
- data/actions/new.rb +0 -44
- data/actions/next_step.rb +0 -33
- data/actions/plugins.rb +0 -25
- data/actions/rm.rb +0 -29
- data/actions/run.rb +0 -45
- data/actions/stats.rb +0 -149
- data/actions/summary.rb +0 -57
- data/actions/tax_dist.rb +0 -106
- data/actions/tax_index.rb +0 -46
- data/actions/tax_set.rb +0 -63
- data/actions/tax_test.rb +0 -80
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d83a4e140647fdcfdd062c0f503e8ad5fefacef870fe5c8c3528e4edeb1e44f
|
4
|
+
data.tar.gz: f8248690dde4d6441658ab6f75181c4786ca7ad6d8d26fa83f195ebdef801c26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36bd4f0122601175a09f3e61ef81618f8db323b41acda67c927bc9578b86ca1d9da4d714a0a02b91541a320cccbbb5b396da7ebe03c6b7f03b5ccd0880ea5953
|
7
|
+
data.tar.gz: 4874ebeabbebdcd0661ec8b7de879f075fd9847c921319192f3272861ed9f41c5a9954000ef60542164240d2dee8a01a2c752256d32323dc7ded0a5b50b2f099
|
data/bin/miga
CHANGED
@@ -4,249 +4,7 @@
|
|
4
4
|
# @license Artistic-2.0
|
5
5
|
|
6
6
|
$:.push File.expand_path('../../lib', __FILE__)
|
7
|
-
|
8
|
-
require 'optparse'
|
9
7
|
require 'miga'
|
8
|
+
require 'miga/cli'
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
$task_desc = {
|
14
|
-
# Projects
|
15
|
-
new: 'Creates an empty MiGA project',
|
16
|
-
about: 'Displays information about a MiGA project',
|
17
|
-
plugins: 'Lists or (un)installs plugins in a MiGA project',
|
18
|
-
doctor: 'Performs consistency checks on a MiGA project',
|
19
|
-
# Datasets
|
20
|
-
add: 'Creates a dataset in a MiGA project',
|
21
|
-
get: 'Downloads a dataset from public databases into a MiGA project',
|
22
|
-
ncbi_get: 'Downloads all genomes in a taxon from NCBI into a MiGA project',
|
23
|
-
rm: 'Removes a dataset from an MiGA project',
|
24
|
-
find: 'Finds unregistered datasets based on result files',
|
25
|
-
ln: 'Link datasets (including results) from one project to another',
|
26
|
-
ls: 'Lists all registered datasets in an MiGA project',
|
27
|
-
# Results
|
28
|
-
add_result: 'Registers a result',
|
29
|
-
stats: 'Extracts statistics for the given result',
|
30
|
-
files: 'Lists registered files from the results of a dataset or project',
|
31
|
-
run: 'Executes locally one step analysis producing the given result',
|
32
|
-
summary: 'Generates a summary table for the statistics of all datasets',
|
33
|
-
next_step: 'Returns the next task to run in a dataset or project',
|
34
|
-
# Objects (Datasets or Projects)
|
35
|
-
edit: 'Edits the metadata of a dataset or project',
|
36
|
-
# System
|
37
|
-
init: 'Initialize MiGA to process new projects',
|
38
|
-
daemon: 'Controls the daemon of a MiGA project',
|
39
|
-
date: 'Returns the current date in standard MiGA format',
|
40
|
-
console: 'Opens an IRB console with MiGA',
|
41
|
-
# Taxonomy
|
42
|
-
tax_set: 'Registers taxonomic information for datasets',
|
43
|
-
tax_test: 'Returns test of taxonomic distributions for query datasets',
|
44
|
-
tax_index: 'Creates a taxonomy-indexed list of the datasets',
|
45
|
-
tax_dist: 'Estimates distributions of distance by taxonomy',
|
46
|
-
}
|
47
|
-
|
48
|
-
$task_alias = {
|
49
|
-
# Projects
|
50
|
-
create_project: :new,
|
51
|
-
project_info: :about,
|
52
|
-
# Datasets
|
53
|
-
create_dataset: :add,
|
54
|
-
download_dataset: :get,
|
55
|
-
unlink_dataset: :rm,
|
56
|
-
find_datasets: :find,
|
57
|
-
import_datasets: :ln,
|
58
|
-
list_datasets: :ls,
|
59
|
-
# Results
|
60
|
-
result_stats: :stats,
|
61
|
-
list_files: :files,
|
62
|
-
run_local: :run,
|
63
|
-
sum_stats: :summary,
|
64
|
-
next_task: :next_step,
|
65
|
-
# Objects
|
66
|
-
update_metadata: :edit,
|
67
|
-
# System
|
68
|
-
c: :console,
|
69
|
-
# Taxonomy
|
70
|
-
add_taxonomy: :tax_set,
|
71
|
-
test_taxonomy: :tax_test,
|
72
|
-
index_taxonomy: :tax_index,
|
73
|
-
tax_distributions: :tax_dist,
|
74
|
-
}
|
75
|
-
|
76
|
-
$task_alias.each do |nick, task|
|
77
|
-
$task_desc[task] = (
|
78
|
-
($task_desc[task] =~ /\(alias: .*\)\./) ?
|
79
|
-
$task_desc[task].sub(/\)\.$/, ", #{nick}).") :
|
80
|
-
$task_desc[task].sub(/\.$/, " (alias: #{nick}).")
|
81
|
-
)
|
82
|
-
end
|
83
|
-
|
84
|
-
##=> Functions <=
|
85
|
-
|
86
|
-
# OptParse banner
|
87
|
-
def opt_banner(opt, files = false)
|
88
|
-
opt.banner = <<BAN
|
89
|
-
#{$task_desc[$task]}
|
90
|
-
|
91
|
-
Usage: #{$0} #{$task} [options]#{ ' FILES...' if files}
|
92
|
-
BAN
|
93
|
-
opt.separator ""
|
94
|
-
end
|
95
|
-
|
96
|
-
# OptParse flags that determine the object to load
|
97
|
-
def opt_object(opt, o, what = [:project, :dataset])
|
98
|
-
opt.on('-P', '--project PATH', '(Mandatory) Path to the project.'
|
99
|
-
){ |v| o[:project]=v } if what.include? :project
|
100
|
-
opt.on('-D', '--dataset STRING',
|
101
|
-
(what.include?(:dataset) ? '(Mandatory) ' : '') +
|
102
|
-
'Name of the dataset.'){ |v| o[:dataset]=v } if what.include? :dataset or
|
103
|
-
what.include? :dataset_opt
|
104
|
-
opt.on('-D', '--dataset STRING', 'Name of the dataset.'
|
105
|
-
){ |v| o[:dataset]=v } if what.include? :dataset_opt
|
106
|
-
opt.on('-t', '--type STRING',
|
107
|
-
(what.include?(:dataset_type_req) ? '(Mandatory) ' : '')+
|
108
|
-
'Type of dataset. Recognized types include:',
|
109
|
-
*MiGA::Dataset.KNOWN_TYPES.map{ |k,v| "~ #{k}: #{v[:description]}" }
|
110
|
-
){ |v| o[:type]=v.to_sym } if what.include? :dataset_type or
|
111
|
-
what.include? :dataset_type_req
|
112
|
-
opt.on('-t', '--type STRING',
|
113
|
-
(what.include?(:project_type_req) ? '(Mandatory) ' : '') +
|
114
|
-
'Type of project. Recognized types include:',
|
115
|
-
*MiGA::Project.KNOWN_TYPES.map{ |k,v| "~ #{k}: #{v[:description]}"}
|
116
|
-
){ |v| o[:type]=v.to_sym } if what.include? :project_type or
|
117
|
-
what.include? :project_type_req
|
118
|
-
opt.on('-r', '--result STRING',
|
119
|
-
'(Mandatory) Name of the result.',
|
120
|
-
'Recognized names for dataset-specific results include:',
|
121
|
-
*MiGA::Dataset.RESULT_DIRS.keys.map{|n| " ~ #{n}"},
|
122
|
-
'Recognized names for project-wide results include:',
|
123
|
-
*MiGA::Project.RESULT_DIRS.keys.map{|n| " ~ #{n}"}
|
124
|
-
){ |v| o[:name]=v.downcase.to_sym } if what.include? :result
|
125
|
-
opt.on('-r', '--result STRING',
|
126
|
-
'(Mandatory) Name of the result. One of:',
|
127
|
-
*MiGA::Dataset.RESULT_DIRS.keys.map{|n| " ~ #{n}"}
|
128
|
-
){ |v| o[:name]=v.downcase.to_sym } if what.include? :result_dataset
|
129
|
-
end
|
130
|
-
|
131
|
-
# OptParse flags common to all actions.
|
132
|
-
def opt_common(opt, o)
|
133
|
-
opt.on('-v', '--verbose',
|
134
|
-
'Print additional information to STDERR.'){ o[:q]=false }
|
135
|
-
opt.on('-d', '--debug INT',
|
136
|
-
'Print debugging information to STDERR (1: debug, 2: trace).') do |v|
|
137
|
-
v.to_i>1 ? MiGA::MiGA.DEBUG_TRACE_ON : MiGA::MiGA.DEBUG_ON
|
138
|
-
end
|
139
|
-
opt.on('-h', '--help', 'Display this screen.') do
|
140
|
-
puts opt
|
141
|
-
exit
|
142
|
-
end
|
143
|
-
opt.separator ''
|
144
|
-
end
|
145
|
-
|
146
|
-
# OptParse flags to filter lists of datasets.
|
147
|
-
def opt_filter_datasets(opt, o, what = [:ref, :multi, :active, :taxonomy])
|
148
|
-
opt.on('--[no-]ref',
|
149
|
-
'If set, uses only reference (or only non-reference) datasets.'
|
150
|
-
){ |v| o[:ref]=v } if what.include? :ref
|
151
|
-
opt.on('--[no-]multi',
|
152
|
-
'If set, uses only multi-species (or only single-species) datasets.'
|
153
|
-
){ |v| o[:multi]=v } if what.include? :multi
|
154
|
-
opt.on('--[no-]active',
|
155
|
-
'If set, uses only active (or inactive) datasets.'
|
156
|
-
){ |v| o[:active]=v } if what.include? :active
|
157
|
-
opt.on('-t', '--taxonomy RANK:TAXON', 'Filter by taxonomy.'
|
158
|
-
){ |v| o[:taxonomy]=MiGA::Taxonomy.new v } if what.include? :taxonomy
|
159
|
-
opt.on('-k', '--key INTEGER',
|
160
|
-
'Returns only the k-th dataset in the list.'){ |v| o[:key]=v.to_i }
|
161
|
-
end
|
162
|
-
|
163
|
-
def opt_require(o, req = {project: '-P', dataset: '-D'})
|
164
|
-
req.each do |k,v|
|
165
|
-
raise "#{v} is mandatory: please provide #{k}." if o[k].nil?
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
def opt_require_type(o, klass)
|
170
|
-
opt_require(o, type: '-t')
|
171
|
-
raise "Unrecognized type: #{o[:type]}." if klass.KNOWN_TYPES[o[:type]].nil?
|
172
|
-
end
|
173
|
-
|
174
|
-
# Filters datasets by keys set in +opt_filter_datasets+.
|
175
|
-
def filter_datasets!(ds, o)
|
176
|
-
ds.select! { |d| d.is_ref? == o[:ref] } unless o[:ref].nil?
|
177
|
-
ds.select! { |d| d.is_active? == o[:active] } unless o[:active].nil?
|
178
|
-
ds.select! do |d|
|
179
|
-
o[:multi] ? d.is_multi? : d.is_nonmulti?
|
180
|
-
end unless o[:multi].nil?
|
181
|
-
ds.select! do |d|
|
182
|
-
(not d.metadata[:tax].nil?) and d.metadata[:tax].is_in?(o[:taxonomy])
|
183
|
-
end unless o[:taxonomy].nil?
|
184
|
-
o[:key].nil? ? ds : ds.values_at(o[:key]-1)
|
185
|
-
end
|
186
|
-
|
187
|
-
def add_metadata(o, obj)
|
188
|
-
o[:metadata].split(',').each do |pair|
|
189
|
-
(k,v) = pair.split('=')
|
190
|
-
case v
|
191
|
-
when 'true'; v = true
|
192
|
-
when 'false'; v = false
|
193
|
-
when 'nil'; v = nil
|
194
|
-
end
|
195
|
-
if k == '_step'
|
196
|
-
obj.metadata["_try_#{v}"] ||= 0
|
197
|
-
obj.metadata["_try_#{v}"] += 1
|
198
|
-
end
|
199
|
-
obj.metadata[k] = v
|
200
|
-
end unless o[:metadata].nil?
|
201
|
-
[:type, :name, :user, :description, :comments].each do |k|
|
202
|
-
obj.metadata[k] = o[k] unless o[k].nil?
|
203
|
-
end
|
204
|
-
obj
|
205
|
-
end
|
206
|
-
|
207
|
-
##=> Main <=
|
208
|
-
|
209
|
-
execs = $task_desc.keys.map{ |k| k.to_s }
|
210
|
-
|
211
|
-
ARGV[0] = $task_alias[ARGV[0].to_sym] unless
|
212
|
-
ARGV[0].nil? or $task_alias[ARGV[0].to_sym].nil?
|
213
|
-
|
214
|
-
case ARGV[0].to_s
|
215
|
-
when '-v', '--version'
|
216
|
-
puts MiGA::MiGA.VERSION
|
217
|
-
when '-V', '--long-version'
|
218
|
-
puts MiGA::MiGA.LONG_VERSION
|
219
|
-
when '-C', '--citation'
|
220
|
-
puts MiGA::MiGA.CITATION
|
221
|
-
when 'console'
|
222
|
-
require 'irb'
|
223
|
-
require 'irb/completion'
|
224
|
-
ARGV.shift
|
225
|
-
IRB.start
|
226
|
-
when *execs
|
227
|
-
$task = ARGV.shift.to_sym
|
228
|
-
ARGV << '-h' if ARGV.empty? and not [:date, :init].include? $task
|
229
|
-
begin
|
230
|
-
load File.expand_path("../actions/#{$task}.rb", File.dirname(__FILE__))
|
231
|
-
rescue => err
|
232
|
-
$stderr.puts "Exception: #{err}\n\n"
|
233
|
-
err.backtrace.each { |l| $stderr.puts l + "\n" }
|
234
|
-
err
|
235
|
-
end
|
236
|
-
else
|
237
|
-
print <<HELP
|
238
|
-
|
239
|
-
Microbial Genomes Atlas.
|
240
|
-
|
241
|
-
Usage: #{$0} {action} [options]
|
242
|
-
|
243
|
-
#{ MiGA::MiGA.tabulate([:action, :description], $task_desc.to_a).join("\n") }
|
244
|
-
|
245
|
-
generic options:
|
246
|
-
-h, --help Display this screen.
|
247
|
-
-v, --version Show MiGA version.
|
248
|
-
-V, --long-version Show complete MiGA version.
|
249
|
-
-C, --citation How to cite MiGA.
|
250
|
-
|
251
|
-
HELP
|
252
|
-
end
|
10
|
+
MiGA::Cli.new(ARGV).launch
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# @package MiGA
|
2
|
+
# @license Artistic-2.0
|
3
|
+
|
4
|
+
require 'miga/cli/action'
|
5
|
+
|
6
|
+
class MiGA::Cli::Action::About < MiGA::Cli::Action
|
7
|
+
|
8
|
+
def parse_cli
|
9
|
+
cli.defaults = {info: false, processing: false, tabular: false}
|
10
|
+
cli.parse do |opt|
|
11
|
+
cli.opt_object(opt, [:project])
|
12
|
+
opt.on(
|
13
|
+
'-p', '--processing',
|
14
|
+
'Print information on processing advance'
|
15
|
+
){ |v| cli[:processing] = v }
|
16
|
+
opt.on(
|
17
|
+
'-m', '--metadata STRING',
|
18
|
+
'Print name and metadata field only'
|
19
|
+
){ |v| cli[:datum] = v }
|
20
|
+
opt.on(
|
21
|
+
'--tab',
|
22
|
+
'Return a tab-delimited table'
|
23
|
+
){ |v| cli[:tabular] = v }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def perform
|
28
|
+
p = cli.load_project
|
29
|
+
if not cli[:datum].nil?
|
30
|
+
v = p.metadata[cli[:datum]]
|
31
|
+
cli.puts v.nil? ? '?' : v
|
32
|
+
elsif cli[:processing]
|
33
|
+
keys = Project.DISTANCE_TASKS + Project.INCLADE_TASKS
|
34
|
+
cli.puts MiGA.tabulate([:task, :status], keys.map do |k|
|
35
|
+
[k, p.add_result(k, false).nil? ? 'queued' : 'done']
|
36
|
+
end, cli[:tabular])
|
37
|
+
else
|
38
|
+
cli.puts MiGA.tabulate([:key, :value], p.metadata.data.keys.map do |k|
|
39
|
+
v = p.metadata[k]
|
40
|
+
[k, k==:datasets ? v.size : v]
|
41
|
+
end, cli[:tabular])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
# @package MiGA
|
2
|
+
# @license Artistic-2.0
|
3
|
+
|
4
|
+
require 'miga/cli/action'
|
5
|
+
|
6
|
+
class MiGA::Cli::Action::Add < MiGA::Cli::Action
|
7
|
+
|
8
|
+
def parse_cli
|
9
|
+
cli.expect_files = true
|
10
|
+
cli.defaults = {ref: true, ignore_dups: false,
|
11
|
+
regexp: /^(?:.*\/)?(.+?)(?:\..*(?:[12]|Reads|Contigs))?(?i:\.f[nastq]+)?$/}
|
12
|
+
cli.parse do |opt|
|
13
|
+
opt.separator 'You can create multiple datasets with a single command; ' \
|
14
|
+
'simply pass all the files at the end: {FILES...}'
|
15
|
+
opt.separator 'If -D is passed, only one dataset will be added. ' \
|
16
|
+
'Otherwise, dataset names will be determined by the file paths (see -R)'
|
17
|
+
opt.separator ''
|
18
|
+
cli.opt_object(opt, [:project, :dataset_opt, :dataset_type_req])
|
19
|
+
opt.on(
|
20
|
+
'-q', '--query',
|
21
|
+
'Register the dataset as a query, not a reference dataset'
|
22
|
+
){ |v| cli[:ref] = !v }
|
23
|
+
opt.on(
|
24
|
+
'-d', '--description STRING',
|
25
|
+
'Description of the dataset'
|
26
|
+
){ |v| cli[:description] = v }
|
27
|
+
opt.on('-c', '--comments STRING',
|
28
|
+
'Comments on the dataset'
|
29
|
+
){ |v| cli[:comments] = v }
|
30
|
+
opt.on('-m', '--metadata STRING',
|
31
|
+
'Metadata as key-value pairs separated by = and delimited by comma',
|
32
|
+
'Values are saved as strings except for booleans (true / false) or nil'
|
33
|
+
){ |v| cli[:metadata] = v }
|
34
|
+
opt.on(
|
35
|
+
'-R', '--name-regexp REGEXP', Regexp,
|
36
|
+
'Regular expression indicating how to extract the name from the path',
|
37
|
+
"By default: '#{cli[:regexp]}'"
|
38
|
+
){ |v| cli[:regexp] = v }
|
39
|
+
opt.on(
|
40
|
+
'-i', '--input-type STRING',
|
41
|
+
'Type of input data, one of the following:',
|
42
|
+
*self.class.INPUT_TYPES.map{ |k,v| "~ #{k}: #{v[0]}." }
|
43
|
+
){ |v| cli[:input_type] = v.downcase.to_sym }
|
44
|
+
opt.on(
|
45
|
+
'--ignore-dups',
|
46
|
+
'Continue with a warning if a dataset already exists'
|
47
|
+
){ |v| cli[:ignore_dups] = v }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def perform
|
52
|
+
p = cli.load_project
|
53
|
+
files = cli.files
|
54
|
+
file_type = nil
|
55
|
+
if files.empty?
|
56
|
+
cli.ensure_par({dataset: '-D'},
|
57
|
+
'dataset is mandatory (-D) unless files are provided')
|
58
|
+
cli.ensure_type(Dataset)
|
59
|
+
files = [nil]
|
60
|
+
else
|
61
|
+
raise 'Please specify input type (-i).' if cli[:input_type].nil?
|
62
|
+
file_type = self.class.INPUT_TYPES[cli[:input_type]]
|
63
|
+
raise "Unrecognized input type: #{cli[:input_type]}." if file_type.nil?
|
64
|
+
raise 'Some files are duplicated, files must be unique.' if
|
65
|
+
files.size != files.uniq.size
|
66
|
+
if cli[:input_type].to_s =~ /_paired$/
|
67
|
+
raise 'Odd number of files incompatible with input type.' if files.size.odd?
|
68
|
+
files = Hash[*files].to_a
|
69
|
+
else
|
70
|
+
files = files.map{ |i| [i] }
|
71
|
+
end
|
72
|
+
raise 'The dataset name (-D) can only be specified with one input file.' if
|
73
|
+
files.size > 1 && !cli[:dataset].nil?
|
74
|
+
end
|
75
|
+
|
76
|
+
cli.say 'Creating datasets:'
|
77
|
+
files.each do |file|
|
78
|
+
name = cli[:dataset]
|
79
|
+
if name.nil?
|
80
|
+
ref_file = file.is_a?(Array) ? file.first : file
|
81
|
+
m = cli[:regexp].match(ref_file)
|
82
|
+
raise "Cannot extract name from file: #{ref_file}" if m.nil? or m[1].nil?
|
83
|
+
name = m[1].miga_name
|
84
|
+
end
|
85
|
+
if Dataset.exist?(p, name)
|
86
|
+
msg = "Dataset already exists: #{name}."
|
87
|
+
cli[:ignore_dups] ? (warn(msg); next) : raise(msg)
|
88
|
+
end
|
89
|
+
|
90
|
+
cli.say "o #{name}"
|
91
|
+
d = Dataset.new(p, name, cli[:ref])
|
92
|
+
raise "Unexpected: Couldn't create dataset: #{name}." if d.nil?
|
93
|
+
|
94
|
+
unless file.nil?
|
95
|
+
r_dir = Dataset.RESULT_DIRS[ file_type[1] ]
|
96
|
+
r_path = File.expand_path("data/#{r_dir}/#{d.name}", p.path)
|
97
|
+
file_type[2].each_with_index do |ext, i|
|
98
|
+
gz = file[i] =~ /\.gz/ ? '.gz' : ''
|
99
|
+
FileUtils.cp(file[i], "#{r_path}#{ext}#{gz}")
|
100
|
+
cli.say " file: #{file[i]}"
|
101
|
+
end
|
102
|
+
File.open("#{r_path}.done", 'w') { |f| f.print Time.now.to_s }
|
103
|
+
end
|
104
|
+
|
105
|
+
d = cli.add_metadata(d)
|
106
|
+
d.save
|
107
|
+
p.add_dataset(name)
|
108
|
+
res = d.first_preprocessing(true)
|
109
|
+
cli.say " result: #{res}"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
@@INPUT_TYPES = {
|
114
|
+
raw_reads_single:
|
115
|
+
['Single raw reads in a single FastQ file',
|
116
|
+
:raw_reads, %w[.1.fastq]],
|
117
|
+
raw_reads_paired:
|
118
|
+
['Paired raw reads in two FastQ files',
|
119
|
+
:raw_reads, %w[.1.fastq .2.fastq]],
|
120
|
+
trimmed_reads_single:
|
121
|
+
['Single trimmed reads in a single FastA file',
|
122
|
+
:trimmed_fasta, %w[.SingleReads.fa]],
|
123
|
+
trimmed_reads_paired:
|
124
|
+
['Paired trimmed reads in two FastA files',
|
125
|
+
:trimmed_fasta, %w[.1.fasta .2.fasta]],
|
126
|
+
trimmed_reads_interleaved:
|
127
|
+
['Paired trimmed reads in a single FastA file',
|
128
|
+
:trimmed_fasta, %w[.CoupledReads.fa]],
|
129
|
+
assembly:
|
130
|
+
['Assembled contigs or scaffolds in FastA format',
|
131
|
+
:assembly, %w[.LargeContigs.fna]]
|
132
|
+
}
|
133
|
+
|
134
|
+
class << self
|
135
|
+
def INPUT_TYPES
|
136
|
+
@@INPUT_TYPES
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# @package MiGA
|
2
|
+
# @license Artistic-2.0
|
3
|
+
|
4
|
+
require 'miga/cli/action'
|
5
|
+
|
6
|
+
class MiGA::Cli::Action::AddResult < MiGA::Cli::Action
|
7
|
+
|
8
|
+
def parse_cli
|
9
|
+
cli.defaults = {force: false}
|
10
|
+
cli.parse do |opt|
|
11
|
+
cli.opt_object(opt, [:project, :dataset_opt, :result])
|
12
|
+
opt.on(
|
13
|
+
'-f', '--force',
|
14
|
+
'Force re-indexing of the result even if it\'s already registered'
|
15
|
+
){ |v| cli[:force] = v }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def perform
|
20
|
+
cli.ensure_par(result: '-r')
|
21
|
+
obj = cli.load_project_or_dataset
|
22
|
+
cli.say "Registering result: #{cli[:result]}"
|
23
|
+
r = obj.add_result(cli[:result], true, force: cli[:force])
|
24
|
+
raise "Cannot add result, incomplete expected files." if r.nil?
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# @package MiGA
|
2
|
+
# @license Artistic-2.0
|
3
|
+
|
4
|
+
require 'miga/cli/action'
|
5
|
+
|
6
|
+
class MiGA::Cli::Action::Console < MiGA::Cli::Action
|
7
|
+
|
8
|
+
def parse_cli
|
9
|
+
end
|
10
|
+
|
11
|
+
def perform
|
12
|
+
require 'irb'
|
13
|
+
require 'irb/completion'
|
14
|
+
IRB.start
|
15
|
+
end
|
16
|
+
|
17
|
+
def empty_action
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# @package MiGA
|
2
|
+
# @license Artistic-2.0
|
3
|
+
|
4
|
+
require 'miga/cli/action'
|
5
|
+
require 'miga/daemon'
|
6
|
+
|
7
|
+
class MiGA::Cli::Action::Daemon < MiGA::Cli::Action
|
8
|
+
|
9
|
+
def parse_cli
|
10
|
+
cli.defaults = {daemon_opts: []}
|
11
|
+
cli.expect_operation = true
|
12
|
+
cli.parse do |opt|
|
13
|
+
opt.separator 'Available operations:'
|
14
|
+
{ start: 'Start an instance of the application.',
|
15
|
+
stop: 'Start an instance of the application.',
|
16
|
+
restart: 'Stop all instances and restart them afterwards.',
|
17
|
+
reload: 'Send a SIGHUP to all instances of the application.',
|
18
|
+
run: 'Start the application and stay on top.',
|
19
|
+
zap: 'Set the application to a stopped state.',
|
20
|
+
status: 'Show status (PID) of application instances.'
|
21
|
+
}.each{ |k,v| opt.separator sprintf ' %*s%s', -33, k, v }
|
22
|
+
opt.separator ''
|
23
|
+
|
24
|
+
opt.separator 'MiGA options:'
|
25
|
+
cli.opt_object(opt, [:project])
|
26
|
+
opt.on(
|
27
|
+
'--shutdown-when-done',
|
28
|
+
'Exit the daemon when all processing is done',
|
29
|
+
'Otherwise, it will stay idle awaiting for new data (default)'
|
30
|
+
){ |v| cli[:shutdown_when_done] = v }
|
31
|
+
opt.on(
|
32
|
+
'--latency INT',
|
33
|
+
'Number of seconds the daemon will be sleeping'
|
34
|
+
){ |v| cli[:latency]=v.to_i }
|
35
|
+
opt.on(
|
36
|
+
'--max-jobs INT',
|
37
|
+
'Maximum number of jobs to use simultaneously'
|
38
|
+
){ |v| cli[:maxjobs]=v.to_i }
|
39
|
+
opt.on(
|
40
|
+
'--ppn INT',
|
41
|
+
'Maximum number of cores to use in a single job'
|
42
|
+
){ |v| cli[:ppn]=v.to_i }
|
43
|
+
cli.opt_common(opt)
|
44
|
+
|
45
|
+
opt.separator 'Daemon options:'
|
46
|
+
opt.on(
|
47
|
+
'-t', '--ontop',
|
48
|
+
'Stay on top (does not daemonize)'
|
49
|
+
){ cli[:daemon_opts] << '-t' }
|
50
|
+
opt.on(
|
51
|
+
'-f', '--force',
|
52
|
+
'Force operation'
|
53
|
+
){ cli[:daemon_opts] << '-f' }
|
54
|
+
opt.on(
|
55
|
+
'-n', '--no_wait',
|
56
|
+
'Do not wait for processes to stop'
|
57
|
+
){ cli[:daemon_opts] << '-n' }
|
58
|
+
opt.on(
|
59
|
+
'--shush',
|
60
|
+
'Silence the daemon'
|
61
|
+
){ cli[:daemon_opts] << '--shush' }
|
62
|
+
opt.separator ''
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def perform
|
67
|
+
p = cli.load_project
|
68
|
+
d = MiGA::Daemon.new(p)
|
69
|
+
[:latency, :maxjobs, :ppn, :shutdown_when_done].each do |k|
|
70
|
+
d.runopts(k, cli[k]) unless cli[k].nil?
|
71
|
+
end
|
72
|
+
d.daemon(cli.operation, cli[:daemon_opts])
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# @package MiGA
|
2
|
+
# @license Artistic-2.0
|
3
|
+
|
4
|
+
require 'miga/cli/action'
|
5
|
+
|
6
|
+
class MiGA::Cli::Action::Date < MiGA::Cli::Action
|
7
|
+
|
8
|
+
def parse_cli
|
9
|
+
cli.parse { |_| }
|
10
|
+
end
|
11
|
+
|
12
|
+
def perform
|
13
|
+
puts Time.now.to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
def empty_action
|
17
|
+
end
|
18
|
+
end
|