class Bio::PAML::Common
Description¶ ↑
Bio::PAML::Common
is a basic wrapper class for PAML
programs. The class provides methods for generating the necessary configuration file, and running a program.
Constants
- DEFAULT_PARAMETERS
-
Default parameters. Should be redefined in subclass.
- DEFAULT_PARAMETERS_ORDER
-
Preferred order of parameters.
- DEFAULT_PROGRAM
-
Default program. Should be redifined in subclass.
Attributes
the last executed command (Array of String)
the last output to the stdout (String)
the last exit status of the program
the last result of the program (String)
Parameters described in the control file. (Hash) Each key of the hash must be a Symbol object, and each value must be a String object or nil.
Report
object created from the last result
contents of supplemental output files (Hash). Each key is a file name and value is content of the file.
Public Class Methods
Source
# File lib/bio/appl/paml/common.rb 74 def initialize(program = nil, params = {}) 75 @program = program || self.class::DEFAULT_PROGRAM 76 set_default_parameters 77 self.parameters.update(params) 78 end
Creates a wrapper instance, which will run using the specified binary location or the command in the PATH. If program is specified as nil, DEFAULT_PROGRAM
is used. Default parameters are automatically loaded and merged with the specified parameters.
Arguments:
-
(optional) program: path to the program, or command name (String)
-
(optional) params: parameters (Hash)
Public Instance Methods
Source
# File lib/bio/appl/paml/common.rb 271 def dump_parameters 272 keyorder = DEFAULT_PARAMETERS_ORDER 273 keys = parameters.keys 274 str = String.new 275 keys.sort do |x, y| 276 (keyorder.index(x) || (keyorder.size + keys.index(x))) <=> 277 (keyorder.index(y) || (keyorder.size + keys.index(y))) 278 end.each do |key| 279 value = parameters[key] 280 # Note: spaces are required in both side of the "=". 281 str.concat "#{key.to_s} = #{value.to_s}\n" if value 282 end 283 str 284 end
Shows parameters (content of control file) as a string. The string can be used for control file.
- Returns
-
string representation of the parameters (String)
Source
# File lib/bio/appl/paml/common.rb 249 def load_parameters(str) 250 hash = {} 251 str.each_line do |line| 252 param, value = parse_parameter(line) 253 hash[param] = value if param 254 end 255 self.parameters = hash 256 end
Loads parameters from the specified string. Note that all previous parameters are erased. Returns the parameters as a hash.
Arguments:
-
(required) str: contents of a
PAML
control file (String)
- Returns
-
parameters (Hash)
Source
# File lib/bio/appl/paml/common.rb 118 def query(alignment, tree = nil) 119 astr = alignment.output(:phylipnon) 120 if tree then 121 tstr = [ sprintf("%3d %2d\n", tree.leaves.size, 1), "\n", 122 tree.output(:newick, 123 { :indent => false, 124 :bootstrap_style => :disabled, 125 :branch_length_style => :disabled }) 126 ].join('') 127 else 128 tstr = nil 129 end 130 str = _query_by_string(astr, tstr) 131 @report = self.class::Report.new(str) 132 @report 133 end
Runs the program on the internal parameters with the specified sequence alignment and tree.
Note that parameters and parameters are always modified, and parameters is modified when tree is specified.
To prevent overwrite of existing files by PAML
, this method automatically creates a temporary directory and the program is run inside the directory. After the end of the program, the temporary directory is automatically removed.
Arguments:
-
(required) alignment:
Bio::Alignment
object or similar object -
(optional) tree:
Bio::Tree
object
- Returns
-
Report
object
Source
# File lib/bio/appl/paml/common.rb 152 def query_by_string(alignment = nil, tree = nil) 153 _query_by_string(alignment, tree) 154 end
Runs the program on the internal parameters with the specified sequence alignment data string and tree data string.
Note that parameters is always modified, and parameters and parameters are modified when alignment and tree are specified respectively.
It raises RuntimeError if seqfile is not specified in the argument or in the parameter.
For other information, see the document of query method.
Arguments:
-
(optional) alignment: String
-
(optional) tree: String or nil
- Returns
-
contents of output file (String)
Source
# File lib/bio/appl/paml/common.rb 96 def run(control_file) 97 exec_local([ control_file ]) 98 end
Runs the program on the parameters in the passed control file. No parameters checks are performed. All internal parameters are ignored and are kept untouched. The output and report attributes are cleared in this method.
Warning about PAML’s behavior: PAML
writes supplemental output files in the current directory with fixed file names which can not be changed with parameters or command-line options, for example, rates, rst, and rub. This behavior may ovarwrite existing files, especially previous supplemental results.
Arguments:
-
(optional) control_file: file name of control file (String)
- Returns
-
messages printed to the standard output (String)
Source
# File lib/bio/appl/paml/common.rb 263 def set_default_parameters 264 self.parameters = self.class::DEFAULT_PARAMETERS.merge(Hash.new) 265 end
Loads system-wide default parameters. Note that all previous parameters are erased. Returns the parameters as a hash.
- Returns
-
parameters (Hash)