class BioDSL::Usearch
Class with methods to execute Usearch
and parse the results.
Public Class Methods
Execute cluster_otus.
@param options [Hash] Options Hash @option options [String] :input @option options [String] :output @option options [String] :database @option options [Float] :identity @option options [Fixnum] :cpus @option options [String] :strand
# File lib/BioDSL/usearch.rb, line 62 def self.cluster_otus(options) usearch = new(options) usearch.cluster_otus end
Execute cluster_smallmem.
@param options [Hash] Options Hash @option options [String] :input @option options [String] :output @option options [String] :database @option options [Float] :identity @option options [Fixnum] :cpus @option options [String] :strand
# File lib/BioDSL/usearch.rb, line 48 def self.cluster_smallmem(options) usearch = new(options) usearch.cluster_smallmem end
Constructor for Usearch
class.
@param options [Hash] Options Hash @option options [String] :input @option options [String] :output @option options [String] :database @option options [Float] :identity @option options [Fixnum] :cpus @option options [String] :strand
@return [Usearch] Class instance.
# File lib/BioDSL/usearch.rb, line 136 def initialize(options) @options = options @stderr = nil return self unless File.size(@options[:input]) == 0 fail UsearchError, %(Empty input file -> "#{@options[:input]}") end
Open a Usearch
file.
@param [Array] List of open arguments.
@yield [IO] stream. @return [IO] stream.
# File lib/BioDSL/usearch.rb, line 115 def self.open(*args) ios = IO.open(*args) if block_given? yield ios else return ios end end
Execute uchime_ref.
@param options [Hash] Options Hash @option options [String] :input @option options [String] :output @option options [String] :database @option options [Float] :identity @option options [Fixnum] :cpus @option options [String] :strand
# File lib/BioDSL/usearch.rb, line 76 def self.uchime_ref(options) usearch = new(options) usearch.uchime_ref end
Execute usearch_local.
@param options [Hash] Options Hash @option options [String] :input @option options [String] :output @option options [String] :database @option options [Float] :identity @option options [Fixnum] :cpus @option options [String] :strand
# File lib/BioDSL/usearch.rb, line 90 def self.usearch_global(options) usearch = new(options) usearch.usearch_global end
Execute usearch_local.
@param options [Hash] Options Hash @option options [String] :input @option options [String] :output @option options [String] :database @option options [Float] :identity @option options [Fixnum] :cpus @option options [String] :strand
# File lib/BioDSL/usearch.rb, line 104 def self.usearch_local(options) usearch = new(options) usearch.usearch_local end
Public Instance Methods
Combose a command list and execute cluster_otus
with this.
@return [self]
# File lib/BioDSL/usearch.rb, line 170 def cluster_otus command = [] command << 'usearch' command << "-cluster_otus #{@options[:input]}" command << "-otus #{@options[:output]}" command << "-id #{@options[:identity]}" command << "-threads #{@options[:cpus]}" if @options[:cpus] execute(command) self end
Combose a command list and execute cluster_smallmem
with this.
@return [self]
# File lib/BioDSL/usearch.rb, line 148 def cluster_smallmem command = [] command << 'usearch' command << "-cluster_smallmem #{@options[:input]}" command << "-id #{@options[:identity]}" command << "-threads #{@options[:cpus]}" if @options[:cpus] command << "-strand #{@options[:strand]}" if @options[:align] command << "-msaout #{@options[:output]}" else command << "-uc #{@options[:output]}" end execute(command) self end
Combose a command list and execute uchime_ref
with this.
@return [self]
# File lib/BioDSL/usearch.rb, line 186 def uchime_ref command = [] command << 'usearch' command << "-uchime_ref #{@options[:input]}" command << "-db #{@options[:database]}" command << "-strand #{@options[:strand]}" command << "-threads #{@options[:cpus]}" if @options[:cpus] command << "-nonchimeras #{@options[:output]}" execute(command) self end
Combose a command list and execute usearch_global
with this.
@return [self]
# File lib/BioDSL/usearch.rb, line 203 def usearch_global command = [] command << 'usearch' command << '-notrunclabels' command << "-usearch_global #{@options[:input]}" command << "-db #{@options[:database]}" command << "-strand #{@options[:strand]}" if @options[:strand] command << "-threads #{@options[:cpus]}" if @options[:cpus] command << "-id #{@options[:identity]}" command << "-uc #{@options[:output]}" execute(command) self end
Combose a command list and execute usearch_local
with this.
@return [self]
# File lib/BioDSL/usearch.rb, line 222 def usearch_local command = [] command << 'usearch' command << '-notrunclabels' command << "-usearch_local #{@options[:input]}" command << "-db #{@options[:database]}" command << "-strand #{@options[:strand]}" if @options[:strand] command << "-threads #{@options[:cpus]}" if @options[:cpus] command << "-id #{@options[:identity]}" command << "-uc #{@options[:output]}" execute(command) self end
Private Instance Methods
Execute Usearch
on a given command.
@param command [Array] Usearch
command list.
# File lib/BioDSL/usearch.rb, line 243 def execute(command) command << '--quiet' unless @options[:verbose] command_str = command.join(' ') $stderr.puts "Running command: #{command_str}" if @options[:verbose] Open3.popen3(command_str) do |_stdin, _stdout, stderr, wait_thr| @stderr = stderr.read.split $INPUT_RECORD_SEPARATOR exit_status = wait_thr.value # Process::Status object returned. unless exit_status.success? # TODO: write error message to log. fail UsearchError, "Command failed: #{command_str} + \ #{@stderr.join $INPUT_RECORD_SEPARATOR}" end end end