class Tool
Attributes
option_parser[R]
The option parser used to parse command-line options.
options[R]
Options set from the command-line
options_defined_by_user[R]
Public Class Methods
default_output_path(input_path,newext,prefix,suffix)
click to toggle source
# File lib/protk/tool.rb, line 154 def self.default_output_path(input_path,newext,prefix,suffix) path="" input_path=input_path[0] if (input_path.instance_of?(Array) && input_path.length==1) if input_path.instance_of?(Array) dir=Pathname.new(input_path[0]).dirname.realpath.to_s basename="collected_outputs" path="#{dir}/#{prefix}#{basename}#{suffix}#{newext}" else dir=Pathname.new(input_path).dirname.realpath.to_s basename=Pathname.new(input_path).basename.to_s oldext=Tool.extension_from_filename(input_path) basename=basename.gsub(/#{oldext}$/,"") path="#{dir}/#{prefix}#{basename}#{suffix}#{newext}" end path end
extension_from_filename(filename)
click to toggle source
# File lib/protk/tool.rb, line 141 def self.extension_from_filename(filename) ext="" case filename.chomp when /\.pep\.xml/ ext=".pep.xml" when /\.prot\.xml/ ext=".prot.xml" else ext=Pathname.new(filename.chomp).extname end ext end
new(option_support=[])
click to toggle source
Creates an empty options object to hold commandline options Also creates an option_parser
with default options common to all tools
# File lib/protk/tool.rb, line 95 def initialize(option_support=[]) @jobid_prefix = "x" @options = OpenStruct.new options.library = [] options.inplace = false options.encoding = "utf8" options.transfer_type = :auto options.verbose = false @options_defined_by_user={} @option_parser=OptionParser.new do |opts| opts.on( '-h', '--help', 'Display this screen' ) do puts opts exit end end if ( option_support.include? :prefix) add_value_option(:output_prefix,"",['-b','--output-prefix pref', 'A string to prepend to the name of output files']) end if ( option_support.include? :over_write) add_boolean_option(:over_write,false,['-r', '--replace-output', 'Dont skip analyses for which the output file already exists']) end if ( option_support.include? :explicit_output ) add_value_option(:explicit_output,nil,['-o', '--output out', 'An explicitly named output file.']) end if ( option_support.include? :threads ) add_value_option(:threads,1,['-n','--threads num','Number of processing threads to use. Set to 0 to autodetect an appropriate value']) end if ( option_support.include? :database) add_value_option(:database,"sphuman",['-d', '--database dbname', 'Specify the database to use for this search. Can be a named protk database or the path to a fasta file']) end if (option_support.include? :debug) add_boolean_option(:debug,false,['--debug','Run in debug mode']) end end
Public Instance Methods
add_boolean_option(symbol,default_value,opts)
click to toggle source
# File lib/protk/tool.rb, line 82 def add_boolean_option(symbol,default_value,opts) @options[symbol]=default_value opts=add_default_to_help(default_value,opts) @option_parser.on(*opts) do @options[symbol]=!default_value @options_defined_by_user[symbol]=opts end end
add_default_to_help(default_value,opts)
click to toggle source
# File lib/protk/tool.rb, line 66 def add_default_to_help(default_value,opts) if default_value!=nil && default_value!=" " && default_value!="" opts[-1] = "#{opts.last} [#{default_value.to_s}]" end opts end
add_value_option(symbol,default_value,opts)
click to toggle source
# File lib/protk/tool.rb, line 73 def add_value_option(symbol,default_value,opts) @options[symbol]=default_value opts=add_default_to_help(default_value,opts) @option_parser.on(*opts) do |val| @options[symbol]=val @options_defined_by_user[symbol]=opts end end
check_options(require_input_file=false,mandatory=[])
click to toggle source
# File lib/protk/tool.rb, line 171 def check_options(require_input_file=false,mandatory=[]) # Checking for required options begin self.option_parser.parse! if has_override return true end missing = mandatory.select{ |param| self.send(param).nil? } if not missing.empty? puts "Missing options: #{missing.join(', ')}" puts self.option_parser return false end rescue OptionParser::InvalidOption, OptionParser::MissingArgument puts $!.to_s puts self.option_parser return false end if ( require_input_file && ARGV[0].nil? ) puts "You must supply an input file" puts self.option_parser return false end return true end
database_info()
click to toggle source
# File lib/protk/tool.rb, line 208 def database_info case when Pathname.new(@options.database).exist? # It's an explicitly named db db_path=Pathname.new(@options.database).expand_path.to_s db_name=Pathname.new(@options.database).basename.to_s else db_path=Constants.instance.current_database_for_name @options.database db_name=@options.database end FastaDatabase.new(db_name,db_path) end
jobid_prefix()
click to toggle source
Prefix for background jobs x = X!Tandem, o=OMSSA, p=“Phenyx”, m=“Mascot” Can't use attr_accessor here because we want this available to subclasses
# File lib/protk/tool.rb, line 40 def jobid_prefix @jobid_prefix end
jobid_prefix=(p)
click to toggle source
# File lib/protk/tool.rb, line 44 def jobid_prefix=(p) @jobid_prefix=p end
method_missing(meth, *args, &block)
click to toggle source
Provides direct access to options through methods of the same name
Calls superclass method
# File lib/protk/tool.rb, line 58 def method_missing(meth, *args, &block) if ( args.length==0 && block==nil) @options.send meth else super end end
run(cmd,genv,autodelete=true)
click to toggle source
Run the search tool using the given command string and global environment
# File lib/protk/tool.rb, line 202 def run(cmd,genv,autodelete=true) cmd_runner=CommandRunner.new(genv) cmd_runner.run_local(cmd) end
supported_options()
click to toggle source
# File lib/protk/tool.rb, line 48 def supported_options os_hash=@options.to_h # Remove entries entirely related to internal use internal_keys=[:library, :inplace, :encoding, :transfer_type, :verbose] os_hash.delete_if { |key,val| internal_keys.include? key } os_hash end