Module: MiGA::Cli::Action::Wf
- Included in:
- ClassifyWf, DerepWf, IndexWf, PreprocWf, QualityWf
- Defined in:
- lib/miga/cli/action/wf.rb
Overview
Helper module for workflows
Instance Method Summary collapse
- #call_cli(cmd) ⇒ Object
- #cleanup ⇒ Object
- #create_project(stage, p_metadata = {}, d_metadata = {}) ⇒ Object
- #default_opts_for_wf ⇒ Object
- #opts_for_wf(opt, files_desc, params = {}) ⇒ Object
- #opts_for_wf_distances(opt) ⇒ Object
- #run_daemon ⇒ Object
- #summarize(which = %w[cds assembly essential_genes ssu])) ⇒ Object
- #transfer_metadata(obj, md) ⇒ Object
Instance Method Details
#call_cli(cmd) ⇒ Object
179 180 181 182 183 |
# File 'lib/miga/cli/action/wf.rb', line 179 def call_cli(cmd) cmd << '-v' if cli[:verbose] MiGA::MiGA.DEBUG "Cli::Action::Wf.call_cli #{cmd}" MiGA::Cli.new(cmd.map(&:to_s)).launch(true) end |
#cleanup ⇒ Object
170 171 172 173 174 175 176 177 |
# File 'lib/miga/cli/action/wf.rb', line 170 def cleanup return unless cli[:clean] cli.say 'Cleaning up intermediate files' %w[data daemon metadata miga.project.json].each do |f| FileUtils.rm_rf(File.(f, cli[:outdir])) end end |
#create_project(stage, p_metadata = {}, d_metadata = {}) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/miga/cli/action/wf.rb', line 107 def create_project(stage, = {}, = {}) cli.ensure_par( outdir: '-o', project_type: '--project-type', dataset_type: '--dataset-type' ) paired = cli[:input_type].to_s.include?('_paired') cli[:regexp] ||= MiGA::Cli.FILE_REGEXP(paired) # Create empty project call_cli( ['new', '-P', cli[:outdir], '-t', cli[:project_type]] ) unless MiGA::Project.exist? cli[:outdir] # Define project metadata p = cli.load_project(:outdir, '-o') [:type] = cli[:project_type] (p, ) %i[haai_p aai_p ani_p ess_coll min_qual].each do |i| p.set_option(i, cli[i]) end # Download datasets unless cli[:ncbi_taxon].nil? what = cli[:ncbi_draft] ? '--all' : '--complete' cmd = ['ncbi_get', '-P', cli[:outdir], '-T', cli[:ncbi_taxon], what] cmd += ['--max', cli[:ncbi_max]] if cli[:ncbi_max] call_cli(cmd) end # Add datasets call_cli( [ 'add', '--ignore-dups', '-P', cli[:outdir], '-t', cli[:dataset_type], '-i', stage, '-R', cli[:regexp] ] + cli.files ) unless cli.files.empty? # Define datasets metadata p.load [:type] = cli[:dataset_type] p.each_dataset { |d| (d, ) } p end |
#default_opts_for_wf ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/miga/cli/action/wf.rb', line 7 def default_opts_for_wf cli.expect_files = true cli.defaults = { clean: false, project_type: :genomes, dataset_type: :popgenome, ncbi_draft: true, min_qual: MiGA::Project.OPTIONS[:min_qual][:default] } end |
#opts_for_wf(opt, files_desc, params = {}) ⇒ Object
15 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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/miga/cli/action/wf.rb', line 15 def opts_for_wf(opt, files_desc, params = {}) { multi: false, cleanup: true, project_type: false, ncbi: true, qual: true }.each { |k, v| params[k] = v if params[k].nil? } opt.on( '-o', '--out_dir PATH', '(Mandatory) Directory to be created with all output data' ) { |v| cli[:outdir] = v } opt.separator '' opt.separator " FILES...: #{files_desc}" opt.separator '' opt.separator 'Workflow Control Options' opt.on( '-C', '--collection STRING', 'Collection of essential genes to use as reference', 'One of: dupont_2012 (default), lee_2019' ) { |v| cli[:ess_coll] = v } if params[:ncbi] opt.on( '-T', '--ncbi-taxon STRING', 'Download all the genomes in NCBI classified as this taxon' ) { |v| cli[:ncbi_taxon] = v } opt.on( '--no-draft', 'Only download complete genomes, not drafts' ) { |v| cli[:ncbi_draft] = v } opt.on( '--max-download INT', Integer, 'Maximum number of genomes to download (by default: unlimited)' ) { |v| cli[:ncbi_max] = v } end if params[:qual] opt.on( '--min-qual FLOAT', 'Minimum genome quality to include in analysis', "By default: #{cli[:min_qual]}" ) { |v| cli[:min_qual] = v == 'no' ? v : v.to_f } end if params[:cleanup] opt.on( '-c', '--clean', 'Clean all intermediate files after generating the reports' ) { |v| cli[:clean] = v } end opt.on( '-R', '--name-regexp REGEXP', Regexp, 'Regular expression indicating how to extract the name from the path', "By default: '#{MiGA::Cli.FILE_REGEXP}'" ) { |v| cli[:regexp] = v } opt_object_type(opt, :dataset, params[:multi]) opt_object_type(opt, :project, params[:multi]) if params[:project_type] opt.on( '--daemon PATH', 'Use custom daemon configuration in JSON format', 'By default: ~/.miga_daemon.json' ) { |v| cli[:daemon_json] = v } opt.on( '-j', '--jobs INT', 'Number of parallel jobs to execute', 'By default controlled by the daemon configuration (maxjobs)' ) { |v| cli[:jobs] = v.to_i } opt.on( '-t', '--threads INT', 'Number of CPUs to use per job', 'By default controlled by the daemon configuration (ppn)' ) { |v| cli[:threads] = v.to_i } end |
#opts_for_wf_distances(opt) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/miga/cli/action/wf.rb', line 83 def opts_for_wf_distances(opt) opt.on('--sensitive', 'Alias to: --aai-p blast+ --ani-p blast+') do cli[:aai_p] = 'blast+' cli[:ani_p] = 'blast+' end opt.on('--fast', 'Alias to: --aai-p diamond --ani-p fastani (default)') do cli[:aai_p] = 'diamond' cli[:ani_p] = 'fastani' end opt.on( '--haai-p STRING', 'hAAI search engine. One of: blast+, fastaai, blat, diamond, fastaai, no', 'The default is "no" for clade projects and "fastaai" otherwise' ) { |v| cli[:haai_p] = v } opt.on( '--aai-p STRING', 'AAI search engine. One of: blast+, blat, diamond (default)' ) { |v| cli[:aai_p] = v } opt.on( '--ani-p STRING', 'ANI search engine. One of: blast+, blat, fastani (default)' ) { |v| cli[:ani_p] = v } end |
#run_daemon ⇒ Object
185 186 187 188 189 190 191 192 193 194 |
# File 'lib/miga/cli/action/wf.rb', line 185 def run_daemon cmd = ['daemon', 'run', '-P', cli[:outdir], '--shutdown-when-done'] cmd += ['--json', cli[:daemon_json]] unless cli[:daemon_json].nil? cmd += ['--max-jobs', cli[:jobs]] unless cli[:jobs].nil? cmd += ['--ppn', cli[:threads]] unless cli[:threads].nil? cmd += ['--debug', MiGA::MiGA.debug_trace? ? '2' : '1'] if MiGA::MiGA.debug? cwd = Dir.pwd call_cli(cmd) Dir.chdir(cwd) end |
#summarize(which = %w[cds assembly essential_genes ssu])) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/miga/cli/action/wf.rb', line 156 def summarize(which = %w[cds assembly essential_genes ssu]) which.each do |r| cli.say "Summary: #{r}" call_cli( [ 'summary', '-P', cli[:outdir], '-r', r, '--tab', '--ref', '--active', '-o', File.join(cli[:outdir], "#{r}.tsv") ] ) end call_cli(['browse', '-P', cli[:outdir]]) end |
#transfer_metadata(obj, md) ⇒ Object
196 197 198 199 200 201 202 203 204 |
# File 'lib/miga/cli/action/wf.rb', line 196 def (obj, md) # Clear old metadata obj..each do |k, v| obj.[k] = nil if k.to_s =~ /^run_/ || obj.option?(k) end # Transfer and save md.each { |k, v| obj.[k] = v } obj.save end |