Skip to content

Instantly share code, notes, and snippets.

@shujishigenobu
Last active December 25, 2015 08:49
Show Gist options
  • Select an option

  • Save shujishigenobu/6949360 to your computer and use it in GitHub Desktop.

Select an option

Save shujishigenobu/6949360 to your computer and use it in GitHub Desktop.
An example snippet to parse option using OptionParser.
### Parse command-line options
require 'optparse'
opt = OptionParser.new
opt.on('-i', '--in FASTA', 'predicted protein files in fasta format [required]') {|v| $pepf = v}
opt.on('-d', '--db BLASTDB', 'blastdb [required]') {|v| $blastdb = v}
opt.on('-m', '--min [MIN_LEN]', 'min aa length to predict [default:50]') {|v| $min_len = v.to_i}
opt.on('-h', '--help', 'show this message'){
puts opt; exit
}
opt.parse!(ARGV)
## check mandatory options
unless $blastdb || $pepf
raise "\nError: Required option missing.\n"
end
## set default value if options are not specified
$min_len = 50 unless $min_len
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment