#!/usr/bin/env ruby $LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__)) require 'trollop' require 'active_record' require 'search_tools/blast' # Quorum search tools and dependencies. SEARCH_TOOLS = { "blastn" => ["blastn"], "blastx" => ["blastx"], "tblastn" => ["tblastn"], "blastp" => ["blastp"] } module Quorum # # Parse Options for Quorum Search Tools # class Search def initialize opts = Trollop::options do text <<-HEAD Quorum A flexible bioinformatics search tool. Options: HEAD # Search tool opt :search_tool, "Search tool to execute. Available tools: " << "#{SEARCH_TOOLS.keys.join(', ')}", :type => :string, :required => true, :short => "-s" # General settings opt :log_directory, "Path to log directory", :type => :string, :required => true, :short => "-l" opt :tmp_directory, "Path to tmp directory", :type => :string, :required => true, :short => "-m" # ActiveRecord database settings opt :id, "Database record ID", :type => :int, :required => true, :short => "-i" opt :database, "Database name", :type => :string, :required => true, :short => "-d" opt :database_adapter, "ActiveRecord database adapter", :type => :string, :required => true, :short => "-a" opt :database_host, "Database host", :type => :string, :required => true, :short => "-k" opt :database_user, "Database username", :type => :string, :required => true, :short => "-u" opt :database_password, "Database password", :type => :string, :required => true, :short => "-p" # Global settings opt :search_database, "Path to search tool database", :type => :string, :short => "-b" opt :threads, "Number of threads to spawn for search tool", :type => :int, :short => "-t" end @args = {} # Contains valid opts. ## Additional opt validation. ## unless SEARCH_TOOLS.keys.include?(opts[:search_tool].downcase) Trollop::die :search_tool, "search_tool not found\n" << "Available search tools: " + SEARCH_TOOLS.keys.join(", ") end @args[:search_tool] = opts[:search_tool].downcase unless opts[:search_database] && Dir.exists?(opts[:search_database]) Trollop::die :search_database, "search tool database not found\n" << "Supplied directory: " + opts[:search_database] end @args[:search_database] = opts[:search_database] @args[:id] = opts[:id] @args[:threads] = opts[:threads] unless Dir.exists?(opts[:log_directory]) Trollop::die :log_directory, "log directory not found\n" << "Supplied directory: " + opts[:log_directory] end @args[:log_directory] = opts[:log_directory] @args[:tmp_directory] = opts[:tmp_directory] ## Check System Dependancies ## check_dependencies ## Establish ActiveRecord Connection ## begin ActiveRecord::Base.establish_connection( :adapter => opts[:database_adapter], :host => opts[:database_host], :username => opts[:database_user], :password => opts[:database_password], :database => opts[:database] ) rescue Exception => e Trollop::die puts e.message end ## Execute search tool ## if @args[:search_tool].include? "blast" blast = Quorum::SearchTools::Blast.new(@args) blast.execute_blast end end # # Check system dependencies. # def check_dependencies SEARCH_TOOLS[@args[:search_tool]].each do |b| system("which #{b} > /dev/null 2>&1") if $?.exitstatus > 0 Trollop::die "Quorum dependency not found for tool " << "#{@args[:search_tool].to_s}. Please add `#{b}` to your PATH." end end end end end if __FILE__ == $0 Quorum::Search.new end