Class | Bio::Blast::NCBIOptions |
In: |
lib/bio/appl/blast/ncbioptions.rb
|
Parent: | Object |
A class to parse and store NCBI-tools style command-line options. It is internally used in Bio::Blast and some other classes.
option_pairs | [R] | (protected) option pairs. internal use only. |
If self == other, returns true. Otherwise, returns false.
# File lib/bio/appl/blast/ncbioptions.rb, line 198 198: def ==(other) 199: return true if super(other) 200: begin 201: oopts = other.options 202: rescue 203: return false 204: end 205: return self.options == oopts 206: end
Delete the given option.
Arguments:
Returns: | String or nil |
# File lib/bio/appl/blast/ncbioptions.rb, line 135 135: def delete(key) 136: re = _key_to_regexp(key) 137: 138: # Note: the last option is used for return value 139: # when two or more same option exist. 140: oldvalue = nil 141: @option_pairs = @option_pairs.delete_if do |pair| 142: if re =~ pair[0] then 143: oldvalue = pair[1] 144: true 145: else 146: false 147: end 148: end 149: return oldvalue 150: end
Return the option.
Arguments:
Returns: | String or nil |
# File lib/bio/appl/blast/ncbioptions.rb, line 116 116: def get(key) 117: re = _key_to_regexp(key) 118: 119: # Note: the last option is used when two or more same option exist. 120: value = nil 121: @option_pairs.reverse_each do |pair| 122: if re =~ pair[0] then 123: value = pair[1] 124: break 125: end 126: end 127: return value 128: end
Returns an array for command-line options. prior_options are preferred to be used.
# File lib/bio/appl/blast/ncbioptions.rb, line 210 210: def make_command_line_options(prior_options = []) 211: newopts = self.class.new(self.options) 212: #newopts.normalize! 213: prior_pairs = _parse_options(prior_options) 214: prior_pairs.each do |pair| 215: newopts.delete(pair[0]) 216: end 217: newopts.option_pairs[0, 0] = prior_pairs 218: newopts.options 219: end
Normalize options. For two or more same options (e.g. ’-p blastn -p blastp’), only the last option is used. (e.g. ’-p blastp’ for above example).
Note that completely illegal options are left untouched.
Returns: | self |
# File lib/bio/appl/blast/ncbioptions.rb, line 74 74: def normalize! 75: hash = {} 76: newpairs = [] 77: @option_pairs.reverse_each do |pair| 78: if pair.size == 2 then 79: key = pair[0] 80: unless hash[key] then 81: newpairs.push pair 82: hash[key] = pair 83: end 84: else 85: newpairs.push pair 86: end 87: end 88: newpairs.reverse! 89: @option_pairs = newpairs 90: self 91: end
Sets the option to given value.
For example, if you want to set ’-p blastall’ option,
obj.set('p', 'blastall')
or
obj.set('-p', 'blastall')
(above two are equivalent).
Arguments:
Returns: | previous value; String or nil |
# File lib/bio/appl/blast/ncbioptions.rb, line 165 165: def set(key, value) 166: re = _key_to_regexp(key) 167: oldvalue = nil 168: flag = false 169: # Note: only the last options is modified for multiple same options. 170: @option_pairs.reverse_each do |pair| 171: if re =~ pair[0] then 172: oldvalue = pair[1] 173: pair[1] = value 174: flag = true 175: break 176: end 177: end 178: unless flag then 179: key = "-#{key}" unless key[0, 1] == '-' 180: @option_pairs.push([ key, value ]) 181: end 182: oldvalue 183: end