# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-#
+# Run Uclust on sequences in the stream.
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
class Uclust
include Enumerable
- def initialize(infile, outfile)
+ def initialize(infile, outfile, options)
@infile = infile
@outfile = outfile
+ @options = options
+ @command = []
end
# Method that calls Uclusts sorting for sorting a FASTA file
# according to decending sequence length.
- def sort(options)
- command = "nice -n 19"
- command << " uclust --sort #{@infile} --output #{@infile}.sort"
- command << " > /dev/null 2>&1" unless options[:verbose]
- system(command)
- raise "Failed sorting file: #{@infile}" unless $?.success?
+ def sort
+ @command << "uclust --sort #{@infile} --output #{@infile}.sort"
+
+ execute
File.rename "#{@infile}.sort", @infile
end
- def ublast(options)
+ def ublast
# uclust --ublast query_seqs.fasta --db database.fasta --blast6out filename --evalue E
- options[:e_val] = 10 if options[:e_val].is_nil?
- command = "nice -n 19"
- command << " uclust --ublast #{@infile} --db #{options[:database]} --uc #{@outfile} --evalue #{options[:e_val]}"
- command << " > /dev/null 2>&1" unless options[:verbose]
- system(command)
- raise "Command failed: #{command}" unless $?.success?
+ @options[:e_val] = 10 if @options[:e_val].is_nil?
+ @command << "uclust --ublast #{@infile} --db #{@options[:database]} --uc #{@outfile} --evalue #{@options[:e_val]}"
+ @command << "--gapopen *I" if @options.has_key? :no_gaps
+
+ execute
end
- def usearch(options)
+ # Method to execute database search.
+ def usearch
# uclust --query query.fasta --db db.fasta --uc results.uc --id 0.90 [--evalue E]
- command = "nice -n 19"
- command << " uclust --query #{@infile} --db #{options[:database]} --uc #{@outfile} --id #{options[:identity]}"
- command << " --evalue #{options[:e_val]}" if options.has_key? :e_val
- command << " > /dev/null 2>&1" unless options[:verbose]
- system(command)
- raise "Command failed: #{command}" unless $?.success?
+ @command << "uclust --query #{@infile} --db #{@options[:database]} --uc #{@outfile} --id #{@options[:identity]}"
+ @command << "--evalue #{@options[:e_val]}" if @options.has_key? :e_val
+ @command << "--gapopen *I" if @options.has_key? :no_gaps
+
+ execute
end
- def uclust(options)
+ # Method to execute clustering de novo.
+ def uclust
# uclust --input seqs_sorted.fasta --uc results.uc --id 0.90
- command = "nice -n 19"
- command << " uclust --input #{@infile} --uc #{@outfile} --id #{options[:identity]}"
- command << " > /dev/null 2>&1" unless options[:verbose]
- system(command)
- raise "Command failed: #{command}" unless $?.success?
+ @command << "uclust --input #{@infile} --uc #{@outfile} --id #{@options[:identity]}"
+ @command << "--gapopen *I" if @options.has_key? :no_gaps
+
+ execute
end
- def usearch_uclust(options)
+ # Method to execute clustering to database plus de novo if not matched.
+ def usearch_uclust
# uclust --input seqs_sorted.fasta --lib db.fasta --uc results.uc --id 0.90
- command = "nice -n 19"
- command << " uclust --input #{@infile} --lib #{options[:database]} --uc #{@outfile} --id #{options[:identity]}"
- command << " --lib #{options[:database]}" if options.has_key? :database
- command << " > /dev/null 2>&1" unless options[:verbose]
+ @command << "uclust --input #{@infile} --lib #{@options[:database]} --uc #{@outfile} --id #{@options[:identity]}"
+ @command << "--lib #{@options[:database]}" if @options.has_key? :database
+ @command << "--gapopen *I" if @options.has_key? :no_gaps
+
+ execute
+ end
+
+ # Method to execute a command using a system() call.
+ # The command is composed of bits from the @command variable.
+ def execute
+ @command.unshift "nice -n 19"
+ @command << "> /dev/null 2>&1" unless @options[:verbose]
+ command = @command.join(" ")
system(command)
raise "Command failed: #{command}" unless $?.success?
- end
+ @command = []
+ end
+
+ # Method to parse a Uclust .uc file and for each line of data
+ # yield a Biopiece record.
def each
record = {}
casts << {:long=>'method', :short=>'m', :type=>'string', :mandatory=>true, :default=>"uclust", :allowed=>ok_methods, :disallowed=>nil}
casts << {:long=>'database', :short=>'d', :type=>'file!', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
casts << {:long=>'identity', :short=>'i', :type=>'float', :mandatory=>true, :default=>0.9, :allowed=>nil, :disallowed=>nil}
+casts << {:long=>'no_gaps', :short=>'g', :type=>'flag', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
casts << {:long=>'e_val', :short=>'e', :type=>'float', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
bp = Biopieces.new
end
end
-uclust = Uclust.new(infile, outfile)
-uclust.sort(options) unless options[:no_sort]
+uclust = Uclust.new(infile, outfile, options)
+uclust.sort unless options[:no_sort]
case options[:method].to_s
-when "ublast" then uclust.ublast(options)
-when "usearch" then uclust.usearch(options)
-when "uclust" then uclust.uclust(options)
-when "usearch_uclust" then uclust.usearch_uclust(options)
+when "ublast" then uclust.ublast
+when "usearch" then uclust.usearch
+when "uclust" then uclust.uclust
+when "usearch_uclust" then uclust.usearch_uclust
else raise "Unknown method: #{options[:method]}"
end