Class: Bio::Velvet::Runner
- Inherits:
-
Object
- Object
- Bio::Velvet::Runner
- Includes:
- Logging, Parallel::ProcessorCount
- Defined in:
- lib/bio-velvet/runner.rb
Instance Method Summary collapse
-
#binary_version(velveth_path = 'velveth') ⇒ Object
Detect the binary version currently in use and return as a String.
-
#set_num_cpus(num_cpus = nil) ⇒ Object
According to the manual, “Velvet will the use up to OMP_NUM_THREADS+1 or OMP_THREAD_LIMIT threads.”.
-
#velvet(kmer_length, velveth_options_string, velvetg_options_string = '', options = {}) ⇒ Object
Run velveth and then velvetg, with the given kmer size.
-
#velvetg(velveth_result_object, velvetg_arguments, options = {}) ⇒ Object
Run velvetg, with a Bio::Velvet::Result object generated with velveth, and velvetg arguments as a String (no need to specify the velvet directory, just the extra arguments).
-
#velveth(kmer_length, velveth_arguments, options = {}) ⇒ Object
Run velveth with the given kmer and return a Bio::Velvet::Result object.
Methods included from Logging
Instance Method Details
#binary_version(velveth_path = 'velveth') ⇒ Object
Detect the binary version currently in use and return as a String
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/bio-velvet/runner.rb', line 85 def binary_version(velveth_path='velveth') cmd = velveth_path log.info "Running velveth: #{cmd}" if log.info? status, stdout, stderr = systemu cmd if status.exitstatus != 0 raise VelvetRunnerException, "Error running velveth: #{stderr}\n#{stdout}" end splits = stdout.split("\n") if splits.length > 1 and matches = splits[1].match(/^Version (.+)$/) return matches[1] else raise "Unable to parse the version number from running `#{cmd}', the output was: #{stdout}" end end |
#set_num_cpus(num_cpus = nil) ⇒ Object
According to the manual, “Velvet will the use up to OMP_NUM_THREADS+1 or OMP_THREAD_LIMIT threads.”
Argument is the number of CPUs, or nil if all CPUs on the machine are to be used
105 106 107 108 109 110 |
# File 'lib/bio-velvet/runner.rb', line 105 def set_num_cpus(num_cpus=nil) num_cpus ||= processor_count #from the parallel gem log.debug "Setting number of CPUs to run velvet with to #{num_cpus}." ENV['OMP_NUM_THREADS'] = (num_cpus - 1).to_s ENV['OMP_THREAD_LIMIT'] = num_cpus.to_s end |
#velvet(kmer_length, velveth_options_string, velvetg_options_string = '', options = {}) ⇒ Object
Run velveth and then velvetg, with the given kmer size. Returned is a Bio::Velvet::Result class, stored in a temporary directory. The temporary directory is removed upon program exit.
The velveth_options and velvetg_options are strings to pass as arguments to velveth and velvetg, respectively.
The final options argument is used to specify bio-velvet wrapper options. Currently: :output_assembly_path: a directory where the assembly takes place [default: a temporary directory] :velveth_path: path to the velveth binary [default: ‘velveth’] :velvetg_path: path to the velvetg binary [default: ‘velvetg’] :threads: number of threads to use [default: all threads on the machine]
23 24 25 26 |
# File 'lib/bio-velvet/runner.rb', line 23 def velvet(kmer_length, , ='', ={}) res = velveth kmer_length, , velvetg res, , end |
#velvetg(velveth_result_object, velvetg_arguments, options = {}) ⇒ Object
Run velvetg, with a Bio::Velvet::Result object generated with velveth, and velvetg arguments as a String (no need to specify the velvet directory, just the extra arguments).
Further options (the third argument): :velvetg_path: path to the velvetg binary [default: ‘velvetg’]
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/bio-velvet/runner.rb', line 66 def velvetg(velveth_result_object, velvetg_arguments, ={}) binary = [:velvetg_path] binary ||= 'velvetg' cmd = "#{binary} #{velveth_result_object.result_directory} #{velvetg_arguments}" log.info "Running velvetg: #{cmd}" if log.info? status, stdout, stderr = systemu cmd if status.exitstatus != 0 raise VelvetRunnerException, "Error running velvetg: #{stderr}\n#{stdout}" end velveth_result_object.velvetg_stdout = stdout velveth_result_object.velvetg_stderr = stderr return velveth_result_object end |
#velveth(kmer_length, velveth_arguments, options = {}) ⇒ Object
Run velveth with the given kmer and return a Bio::Velvet::Result object
Options: :velveth_path: path to the velveth binary [default: ‘velveth’]
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 |
# File 'lib/bio-velvet/runner.rb', line 32 def velveth(kmer_length, velveth_arguments, ={}) set_num_cpus([:threads]) result = Result.new outdir = nil if [:output_assembly_path] log.debug "Using pre-defined assembly directory: #{[:output_assembly_path] }" outdir = [:output_assembly_path] else outdir = Files.create.root end result.result_directory = outdir binary = [:velveth_path] binary ||= 'velveth' # Run velveth cmd = "#{binary} #{result.result_directory} #{kmer_length} #{velveth_arguments}" log.info "Running velveth: #{cmd}" if log.info? status, stdout, stderr = systemu cmd if status.exitstatus != 0 raise VelvetRunnerException, "Error running velveth: #{stderr}\n#{stdout}" end result.velveth_stdout = stdout result.velveth_stderr = stderr return result end |