Back to index

python-biopython  1.60
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
Bio.Phylo.PAML._paml.Paml Class Reference

List of all members.

Public Member Functions

def __init__
def write_ctl_file
def read_ctl_file
def print_options
def set_options
def get_option
def get_all_options
def run

Public Attributes

 working_dir
 alignment
 out_file

Private Member Functions

def _set_rel_paths

Private Attributes

 _rel_working_dir
 _rel_alignment
 _rel_out_file

Detailed Description

Definition at line 44 of file _paml.py.


Constructor & Destructor Documentation

def Bio.Phylo.PAML._paml.Paml.__init__ (   self,
  alignment = None,
  working_dir = None,
  out_file = None 
)

Definition at line 47 of file _paml.py.

00047 
00048                 out_file = None):
00049         if working_dir is None:
00050             self.working_dir = os.getcwd()
00051         else:
00052             self.working_dir = working_dir
00053         if alignment is not None:
00054             if not os.path.exists(alignment):
00055                 raise IOError, "The specified alignment file does not exist."
00056         self.alignment = alignment
00057         self.out_file = out_file
        

Member Function Documentation

def Bio.Phylo.PAML._paml.Paml._set_rel_paths (   self) [private]
Convert all file/directory locations to paths relative to the current working directory.

paml requires that all paths specified in the control file be
relative to the directory from which it is called rather than 
absolute paths.

Definition at line 92 of file _paml.py.

00092 
00093     def _set_rel_paths(self):
00094         """Convert all file/directory locations to paths relative to the current working directory.
00095         
00096         paml requires that all paths specified in the control file be
00097         relative to the directory from which it is called rather than 
00098         absolute paths.
00099         """
00100         if self.working_dir is not None:
00101             self._rel_working_dir = _relpath(self.working_dir)
00102         if self.alignment is not None:
00103             self._rel_alignment = _relpath(self.alignment, 
00104                 self.working_dir)
00105         if self.out_file is not None:
00106             self._rel_out_file = _relpath(self.out_file, self.working_dir)
        

Here is the caller graph for this function:

Return the values of all the options.

Definition at line 88 of file _paml.py.

00088 
00089     def get_all_options(self):
00090         """Return the values of all the options."""        
00091         return self._options.items()
        
def Bio.Phylo.PAML._paml.Paml.get_option (   self,
  option 
)
Return the value of an option.

Definition at line 81 of file _paml.py.

00081 
00082     def get_option(self, option):
00083         """Return the value of an option."""
00084         if not self._options.has_key(option):
00085             raise KeyError, "Invalid option: " + option
00086         else:
00087             return self._options.get(option)
    
Print out all of the options and their current settings.

Definition at line 64 of file _paml.py.

00064 
00065     def print_options(self):
00066         """Print out all of the options and their current settings."""
00067         for option in self._options.items():
00068             print "%s = %s" % (option[0], option[1])
 

Definition at line 61 of file _paml.py.

00061 
00062     def read_ctl_file(self):
00063         pass
        
def Bio.Phylo.PAML._paml.Paml.run (   self,
  ctl_file,
  verbose,
  command 
)
Run a paml program using the current configuration and then parse the results. 

Return a process signal so the user can determine if
the execution was successful (return code 0 is successful, -N
indicates a failure). The arguments may be passed as either 
absolute or relative paths, despite the fact that paml 
requires relative paths.

Definition at line 107 of file _paml.py.

00107 
00108     def run(self, ctl_file, verbose, command):
00109         """Run a paml program using the current configuration and then parse the results. 
00110         
00111         Return a process signal so the user can determine if
00112         the execution was successful (return code 0 is successful, -N
00113         indicates a failure). The arguments may be passed as either 
00114         absolute or relative paths, despite the fact that paml 
00115         requires relative paths.
00116         """
00117         if self.alignment is None:
00118             raise ValueError, "Alignment file not specified."
00119         if not os.path.exists(self.alignment):
00120             raise IOError, "The specified alignment file does not exist."
00121         if self.out_file is None:
00122             raise ValueError, "Output file not specified."
00123         if self.working_dir is None:
00124             raise ValueError, "Working directory not specified."
00125         # Get the current working directory
00126         cwd = os.getcwd()
00127         # Move to the desired working directory
00128         if not os.path.exists(self.working_dir):
00129             os.mkdir(self.working_dir)
00130         os.chdir(self.working_dir)
00131         # If no external control file was specified...
00132         if ctl_file is None:
00133             # Dynamically build a control file
00134             self.write_ctl_file()
00135             if verbose:
00136                 result_code = subprocess.call([command, self.ctl_file])
00137             else:
00138                 # To suppress output, redirect it to a pipe to nowhere
00139                 result_code = subprocess.call([command, self.ctl_file],
00140                     stdout=subprocess.PIPE)
00141         else:
00142             if not os.path.exists(ctl_file):
00143                 raise IOError, "The specified control file does not exist."
00144             if verbose:
00145                 result_code = subprocess.call([command, ctl_file])
00146             else:
00147                 result_code = subprocess.call([command, ctl_file],
00148                     stdout=subprocess.PIPE)
00149         os.chdir(cwd)
00150         if result_code > 0:
00151             # If the program fails for any reason
00152             raise PamlError, \
00153             "%s has failed (return code %i). Run with verbose = True to view error message" \
00154             % (command, result_code)
00155         if result_code < 0:
00156             # If the paml process is killed by a signal somehow
00157             raise EnvironmentError, "The %s process was killed (return code %i)." \
00158                   % (command, result_code)

Here is the call graph for this function:

def Bio.Phylo.PAML._paml.Paml.set_options (   self,
  kwargs 
)
Set the value of an option. 

This function abstracts the options dict to prevent the user from 
adding options that do not exist or mispelling options.

Definition at line 69 of file _paml.py.

00069 
00070     def set_options(self, **kwargs):
00071         """Set the value of an option. 
00072         
00073         This function abstracts the options dict to prevent the user from 
00074         adding options that do not exist or mispelling options.
00075         """
00076         for option, value in kwargs.items():
00077             if not self._options.has_key(option):
00078                 raise KeyError, "Invalid option: " + option
00079             else:
00080                 self._options[option] = value
        

Here is the call graph for this function:

Definition at line 58 of file _paml.py.

00058 
00059     def write_ctl_file(self):
00060         pass
        

Here is the caller graph for this function:


Member Data Documentation

Definition at line 102 of file _paml.py.

Definition at line 105 of file _paml.py.

Definition at line 100 of file _paml.py.

Definition at line 55 of file _paml.py.

Definition at line 56 of file _paml.py.

Definition at line 49 of file _paml.py.


The documentation for this class was generated from the following file: