Back to index

python-biopython  1.60
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
Bio.Phylo.PAML.baseml.Baseml Class Reference
Inheritance diagram for Bio.Phylo.PAML.baseml.Baseml:
Inheritance graph
[legend]
Collaboration diagram for Bio.Phylo.PAML.baseml.Baseml:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def write_ctl_file
def read_ctl_file
def run

Public Attributes

 tree
 ctl_file
 alignment
 out_file

Private Member Functions

def _set_rel_paths

Private Attributes

 _options
 _rel_tree

Detailed Description

This class implements an interface to BASEML, part of the PAML package.

Definition at line 18 of file baseml.py.


Constructor & Destructor Documentation

def Bio.Phylo.PAML.baseml.Baseml.__init__ (   self,
  alignment = None,
  tree = None,
  working_dir = None,
  out_file = None 
)
Initialize the Baseml instance. 

The user may optionally pass in strings specifying the locations
of the input alignment and tree files, the working directory and
the final output file. 

Definition at line 22 of file baseml.py.

00022 
00023                 out_file = None):
00024         """Initialize the Baseml instance. 
00025         
00026         The user may optionally pass in strings specifying the locations
00027         of the input alignment and tree files, the working directory and
00028         the final output file. 
00029         """
00030         Paml.__init__(self, alignment, working_dir, out_file)
00031         if tree is not None:
00032             if not os.path.exists(tree):
00033                 raise IOError, "The specified tree file does not exist."
00034         self.tree = tree
00035         self.ctl_file = "baseml.ctl"
00036         self._options = {"noisy": None,
00037                         "verbose": None,
00038                         "runmode": None,
00039                         "model": None,
00040                         "model_options": None,
00041                         "Mgene": None,
00042                         "ndata": None,
00043                         "clock": None,
00044                         "fix_kappa": None,
00045                         "kappa": None,
00046                         "fix_alpha": None,
00047                         "alpha": None,
00048                         "Malpha": None,
00049                         "ncatG": None,
00050                         "fix_rho": None,
00051                         "rho": None,
00052                         "nparK": None,
00053                         "nhomo": None,
00054                         "getSE": None,
00055                         "RateAncestor": None,
00056                         "Small_Diff": None,
00057                         "cleandata": None,
00058                         "icode": None,
00059                         "fix_blength": None,
00060                         "method": None}


Member Function Documentation

Convert all file/directory locations to paths relative to the current working directory.

BASEML 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 152 of file baseml.py.

00152 
00153     def _set_rel_paths(self):
00154         """Convert all file/directory locations to paths relative to the current working directory.
00155 
00156         BASEML requires that all paths specified in the control file be
00157         relative to the directory from which it is called rather than 
00158         absolute paths.
00159         """
00160         Paml._set_rel_paths(self)
00161         if self.tree is not None:
00162             self._rel_tree = _relpath(self.tree, self.working_dir)

Here is the caller graph for this function:

def Bio.Phylo.PAML.baseml.Baseml.read_ctl_file (   self,
  ctl_file 
)
Parse a control file and load the options into the Baseml instance.

Definition at line 96 of file baseml.py.

00096 
00097     def read_ctl_file(self, ctl_file):
00098         """Parse a control file and load the options into the Baseml instance.
00099         """
00100         temp_options = {}
00101         if not os.path.isfile(ctl_file):
00102             raise IOError("File not found: %r" % ctl_file)
00103         else:
00104             ctl_handle = open(ctl_file)
00105             for line in ctl_handle:
00106                 line = line.strip()
00107                 uncommented = line.split("*",1)[0]
00108                 if uncommented != "":
00109                     if "=" not in uncommented:
00110                         ctl_handle.close()
00111                         raise AttributeError, \
00112                             "Malformed line in control file:\n%r" % line
00113                     (option, value) = uncommented.split("=")
00114                     option = option.strip()
00115                     value = value.strip()
00116                     if option == "seqfile":
00117                         self.alignment = value
00118                     elif option == "treefile":
00119                         self.tree = value
00120                     elif option == "outfile":
00121                         self.out_file = value
00122                     elif option not in self._options:
00123                         ctl_handle.close()
00124                         raise KeyError, "Invalid option: %s" % option
00125                     elif option == "model":
00126                         if len(value) <= 2 and value.isdigit():
00127                             temp_options["model"] = int(value)
00128                             temp_options["model_options"] = None
00129                         else:
00130                             model_num = value.partition(" ")[0]
00131                             model_opt = value.partition(" ")[2].strip()
00132                             temp_options["model"] = int(model_num)
00133                             temp_options["model_options"] = model_opt
00134                     else:
00135                         if "." in value or "e-" in value:
00136                             try:
00137                                 converted_value = float(value)
00138                             except:
00139                                 converted_value = value
00140                         else:
00141                             try:
00142                                 converted_value = int(value)
00143                             except:
00144                                 converted_value = value
00145                         temp_options[option] = converted_value
00146             ctl_handle.close()
00147         for option in self._options.keys():
00148             if option in temp_options.keys():
00149                 self._options[option] = temp_options[option]
00150             else:
00151                 self._options[option] = None

Here is the call graph for this function:

def Bio.Phylo.PAML.baseml.Baseml.run (   self,
  ctl_file = None,
  verbose = False,
  command = "baseml",
  parse = True 
)
Run baseml 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 BASEML 
requires relative paths.

Definition at line 164 of file baseml.py.

00164 
00165                 parse = True):
00166         """Run baseml using the current configuration and then parse the results. 
00167 
00168         Return a process signal so the user can determine if
00169         the execution was successful (return code 0 is successful, -N
00170         indicates a failure). The arguments may be passed as either 
00171         absolute or relative paths, despite the fact that BASEML 
00172         requires relative paths.
00173         """
00174         if self.tree is None:
00175             raise ValueError, "Tree file not specified."
00176         if not os.path.exists(self.tree):
00177             raise IOError, "The specified tree file does not exist."
00178         Paml.run(self, ctl_file, verbose, command)
00179         if parse:
00180             results = read(self.out_file)
00181         else:
00182             results = None
00183         return results

Here is the call graph for this function:

Dynamically build a BASEML control file from the options.

The control file is written to the location specified by the 
ctl_file property of the baseml class.

Definition at line 61 of file baseml.py.

00061 
00062     def write_ctl_file(self):
00063         """Dynamically build a BASEML control file from the options.
00064 
00065         The control file is written to the location specified by the 
00066         ctl_file property of the baseml class.
00067         """
00068         # Make sure all paths are relative to the working directory
00069         self._set_rel_paths()
00070         if True: #Dummy statement to preserve indentation for diff
00071             ctl_handle = open(self.ctl_file, 'w')
00072             ctl_handle.write("seqfile = %s\n" % self._rel_alignment)
00073             ctl_handle.write("outfile = %s\n" % self._rel_out_file)
00074             ctl_handle.write("treefile = %s\n" % self._rel_tree)
00075             for option in self._options.items():
00076                 if option[1] == None:
00077                     # If an option has a value of None, there's no need
00078                     # to write it in the control file; it's normally just
00079                     # commented out.
00080                     continue
00081                 if option[0] == "model_options":
00082                     continue
00083                 # If "model" is 9 or 10, it may be followed in the cotnrol
00084                 # file by further options such as
00085                 # [1 (TC CT AG GA)]
00086                 # or
00087                 # [5 (AC CA) (AG GA) (AT TA) (CG GC) (CT TC)]
00088                 # which are to be stored in "model_options" as a string.
00089                 if option[0] == "model" and option[1] in [9, 10]:
00090                     if self._options["model_options"] is not None:
00091                         ctl_handle.write("model = %s  %s" % (option[1],
00092                                          self._options["model_options"]))
00093                         continue
00094                 ctl_handle.write("%s = %s\n" % (option[0], option[1]))
00095             ctl_handle.close()

Here is the call graph for this function:


Member Data Documentation

Definition at line 35 of file baseml.py.

Definition at line 161 of file baseml.py.

Definition at line 116 of file baseml.py.

Definition at line 34 of file baseml.py.

Definition at line 120 of file baseml.py.

Definition at line 33 of file baseml.py.


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