]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_ruby/lib/maasha/usearch.rb
finished refactoring s/has_key?/[]/
[biopieces.git] / code_ruby / lib / maasha / usearch.rb
index 7aa14b43c879a0d019a3012468915833b604ea79..837585010f41fda3d18ea91292bdef452ba3076d 100644 (file)
@@ -37,6 +37,8 @@ class Usearch
     @outfile = outfile
     @options = options
     @command = []
+
+    raise UsearchError, %{Empty input file -> "#{@infile}"} if File.size(@infile) == 0
   end
 
   # Method that calls Usearch sorting for sorting a FASTA file
@@ -76,13 +78,20 @@ class Usearch
   def usearch
     @command << "usearch --query #{@infile} --db #{@options[:database]} --userout #{@outfile}"
     @command << "--userfields target+tloz+thiz+query+bits+strand"
-    @command << "--id #{@options[:identity]}"  if @options.has_key? :identity
-    @command << "--evalue #{@options[:e_val]}" if @options.has_key? :e_val
+    @command << "--id #{@options[:identity]}"  if @options[:identity]
+    @command << "--evalue #{@options[:e_val]}" if @options[:e_val]
     @command << "--rev"
 
                execute
   end
 
+  # Method to execute uchime chimera detection.
+  def uchime
+    @command << "usearch --uchime #{@infile} --db #{@options[:database]} --uchimeout #{@outfile}"
+
+    execute
+  end
+
   # Method to execute ustar alignment.
   def ustar
     command = %Q{grep "^[SH]" #{@outfile} > #{@outfile}.sub}
@@ -176,6 +185,8 @@ class Usearch
           entries << entry
         end
       end
+
+      yield Align.new(entries) unless entries.empty?
     end
   end