Class: Seqtk::Seqtk
- Inherits:
-
Object
- Object
- Seqtk::Seqtk
- Includes:
- Which
- Defined in:
- lib/seqtkrb.rb,
lib/seqtkrb/sample.rb
Instance Method Summary collapse
-
#initialize ⇒ Seqtk
constructor
A new instance of Seqtk.
- #run(cmd) ⇒ Object
- #sample(infile, outfile, n, seed = -1)) ⇒ Object
- #sample_lowmem(infile, outfile, n, seed = -1)) ⇒ Object
- #seedstr(seed) ⇒ Object
Constructor Details
#initialize ⇒ Seqtk
Returns a new instance of Seqtk.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/seqtkrb.rb', line 12 def initialize # check seqtk is installed - install it if not gem_dir = Gem.loaded_specs['seqtkrb'].full_gem_path gem_deps = File.join(gem_dir, 'deps.yaml') Bindeps.require gem_deps missing = Bindeps.missing gem_deps unless missing.empty? raise StandardError.new('seqtk was not found and ' + 'could not be installed') end @bin = which('seqtk').first end |
Instance Method Details
#run(cmd) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/seqtkrb.rb', line 29 def run cmd task = Cmd.new "#{@bin} #{cmd}" task.run unless task.status.success? msg = "seqtk command #{cmd} failed\n" msg << "stdout:\n" msg << task.stdout msg << "\nstderr:\n" msg << task.stderr raise StandardError.new(msg) end end |
#sample(infile, outfile, n, seed = -1)) ⇒ Object
5 6 7 |
# File 'lib/seqtkrb/sample.rb', line 5 def sample(infile, outfile, n, seed=-1) run "sample #{seedstr seed} #{infile} #{n} > #{outfile}" end |
#sample_lowmem(infile, outfile, n, seed = -1)) ⇒ Object
9 10 11 |
# File 'lib/seqtkrb/sample.rb', line 9 def sample_lowmem(infile, outfile, n, seed=-1) run "sample -2 #{seedstr seed} #{infile} #{n} > #{outfile}" end |
#seedstr(seed) ⇒ Object
13 14 15 |
# File 'lib/seqtkrb/sample.rb', line 13 def seedstr seed seed == -1 ? "" : "-s #{seed}" end |