Class: Bio::Velvet::Runner

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/bio-velvet/runner.rb

Instance Method Summary collapse

Methods included from Logging

#log

Instance Method Details

#binary_versionObject

Detect the binary version currently in use and return as a String



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/bio-velvet/runner.rb', line 65

def binary_version
  cmd = 'velveth'
  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

#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 (by default, a temporary directory)



18
19
20
21
# File 'lib/bio-velvet/runner.rb', line 18

def velvet(kmer_length, velveth_options_string, velvetg_options_string='', options={})
  res = velveth kmer_length, velveth_options_string, options
  velvetg res, velvetg_options_string
end

#velvetg(velveth_result_object, velvetg_arguments) ⇒ 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).



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/bio-velvet/runner.rb', line 50

def velvetg(velveth_result_object, velvetg_arguments)
  cmd = "velvetg #{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



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/bio-velvet/runner.rb', line 23

def velveth(kmer_length, velveth_arguments, options={})
  result = Result.new
  outdir = nil
  if options[:output_assembly_path]
    log.debug "Using pre-defined assembly directory: #{options[:output_assembly_path] }"
    outdir = options[:output_assembly_path]
  else
    outdir = Files.create.root
  end
  result.result_directory = outdir

  # Run velveth
  cmd = "velveth #{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