class BioDSL::Usearch

Class with methods to execute Usearch and parse the results.

Public Class Methods

cluster_otus(options) click to toggle source

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
cluster_smallmem(options) click to toggle source

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
new(options) click to toggle source

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(*args) { |ios| ... } click to toggle source

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
uchime_ref(options) click to toggle source

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
usearch_global(options) click to toggle source

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
usearch_local(options) click to toggle source

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

cluster_otus() click to toggle source

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
cluster_smallmem() click to toggle source

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
uchime_ref() click to toggle source

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
usearch_global() click to toggle source

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
usearch_local() click to toggle source

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(command) click to toggle source

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