Last active
December 25, 2015 08:49
-
-
Save shujishigenobu/6949360 to your computer and use it in GitHub Desktop.
An example snippet to parse option using OptionParser.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### 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