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 195 195: def ==(other) 196: return true if super(other) 197: begin 198: oopts = other.options 199: rescue 200: return false 201: end 202: return self.options == oopts 203: end
Delete the given option.
Arguments:
Returns: | String or nil |
# File lib/bio/appl/blast/ncbioptions.rb, line 132 132: def delete(key) 133: re = _key_to_regexp(key) 134: 135: # Note: the last option is used for return value 136: # when two or more same option exist. 137: oldvalue = nil 138: @option_pairs = @option_pairs.delete_if do |pair| 139: if re =~ pair[0] then 140: oldvalue = pair[1] 141: true 142: else 143: false 144: end 145: end 146: return oldvalue 147: end
Return the option.
Arguments:
Returns: | String or nil |
# File lib/bio/appl/blast/ncbioptions.rb, line 113 113: def get(key) 114: re = _key_to_regexp(key) 115: 116: # Note: the last option is used when two or more same option exist. 117: value = nil 118: @option_pairs.reverse_each do |pair| 119: if re =~ pair[0] then 120: value = pair[1] 121: break 122: end 123: end 124: return value 125: end
Returns an array for command-line options. prior_options are preferred to be used.
# File lib/bio/appl/blast/ncbioptions.rb, line 207 207: def make_command_line_options(prior_options = []) 208: newopts = self.class.new(self.options) 209: #newopts.normalize! 210: prior_pairs = _parse_options(prior_options) 211: prior_pairs.each do |pair| 212: newopts.delete(pair[0]) 213: end 214: newopts.option_pairs[0, 0] = prior_pairs 215: newopts.options 216: 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 71 71: def normalize! 72: hash = {} 73: newpairs = [] 74: @option_pairs.reverse_each do |pair| 75: if pair.size == 2 then 76: key = pair[0] 77: unless hash[key] then 78: newpairs.push pair 79: hash[key] = pair 80: end 81: else 82: newpairs.push pair 83: end 84: end 85: newpairs.reverse! 86: @option_pairs = newpairs 87: self 88: 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 162 162: def set(key, value) 163: re = _key_to_regexp(key) 164: oldvalue = nil 165: flag = false 166: # Note: only the last options is modified for multiple same options. 167: @option_pairs.reverse_each do |pair| 168: if re =~ pair[0] then 169: oldvalue = pair[1] 170: pair[1] = value 171: flag = true 172: break 173: end 174: end 175: unless flag then 176: key = "-#{key}" unless key[0, 1] == '-' 177: @option_pairs.push([ key, value ]) 178: end 179: oldvalue 180: end