Back to index

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

List of all members.

Public Member Functions

def __init__
def write_ctl_file
def read_ctl_file
def print_options
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 CODEML, part of the PAML package.

Definition at line 18 of file codeml.py.


Constructor & Destructor Documentation

def Bio.Phylo.PAML.codeml.Codeml.__init__ (   self,
  alignment = None,
  tree = None,
  working_dir = None,
  out_file = None 
)
Initialize the codeml 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. Other options found in the CODEML control
have typical settings by default to run site class models 0, 1 and
2 on a nucleotide alignment.

Definition at line 22 of file codeml.py.

00022 
00023                 out_file = None):
00024         """Initialize the codeml 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. Other options found in the CODEML control
00029         have typical settings by default to run site class models 0, 1 and
00030         2 on a nucleotide alignment.
00031         """
00032         Paml.__init__(self, alignment, working_dir, out_file)
00033         if tree is not None:
00034             if not os.path.exists(tree):
00035                 raise IOError, "The specified tree file does not exist."
00036         self.tree = tree
00037         self.ctl_file = "codeml.ctl"
00038         self._options = {"noisy": None, 
00039                         "verbose": None, 
00040                         "runmode": None,
00041                         "seqtype": None, 
00042                         "CodonFreq": None, 
00043                         "ndata": None,
00044                         "clock": None, 
00045                         "aaDist": None,
00046                         "aaRatefile": None, 
00047                         "model": None,
00048                         "NSsites": None, 
00049                         "icode": None, 
00050                         "Mgene": None,
00051                         "fix_kappa": None, 
00052                         "kappa": None, 
00053                         "fix_omega": None,
00054                         "omega": None, 
00055                         "fix_alpha": None, 
00056                         "alpha": None,
00057                         "Malpha": None, 
00058                         "ncatG": None, 
00059                         "getSE": None,
00060                         "RateAncestor": None, 
00061                         "Small_Diff": None,
00062                         "cleandata": None, 
00063                         "fix_blength": None, 
00064                         "method": None,
00065                         "rho": None,
00066                         "fix_rho": None}
        

Member Function Documentation

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

CODEML 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 165 of file codeml.py.

00165 
00166     def _set_rel_paths(self):
00167         """Convert all file/directory locations to paths relative to the current working directory.
00168         
00169         CODEML requires that all paths specified in the control file be
00170         relative to the directory from which it is called rather than 
00171         absolute paths.
00172         """
00173         Paml._set_rel_paths(self)
00174         if self.tree is not None:
00175             self._rel_tree = _relpath(self.tree, self.working_dir)
        

Here is the caller graph for this function:

Print out all of the options and their current settings.

Definition at line 153 of file codeml.py.

00153 
00154     def print_options(self):
00155         """Print out all of the options and their current settings."""
00156         for option in self._options.items():
00157             if option[0] == "NSsites" and option[1] is not None:
00158                 # NSsites is stored in Python as a list but in the 
00159                 # control file it is specified as a series of numbers
00160                 # separated by spaces.
00161                 NSsites = " ".join([str(site) for site in option[1]])
00162                 print "%s = %s" % (option[0], NSsites)
00163             else:
00164                 print "%s = %s" % (option[0], option[1])
        
def Bio.Phylo.PAML.codeml.Codeml.read_ctl_file (   self,
  ctl_file 
)
Parse a control file and load the options into the Codeml instance.

Definition at line 96 of file codeml.py.

00096 
00097     def read_ctl_file(self, ctl_file):
00098         """Parse a control file and load the options into the Codeml 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 == "NSsites":
00123                         site_classes = value.split(" ")
00124                         for n in range(len(site_classes)):
00125                             try:
00126                                 site_classes[n] = int(site_classes[n])
00127                             except:
00128                                 ctl_handle.close()
00129                                 raise TypeError, \
00130                                     "Invalid site class: %s" % site_classes[n]
00131                         temp_options["NSsites"] = site_classes
00132                     elif option not in self._options:
00133                         ctl_handle.close()
00134                         raise KeyError, "Invalid option: %s" % option
00135                     else:
00136                         if "." in value:
00137                             try:
00138                                 converted_value = float(value)
00139                             except:
00140                                 converted_value = value
00141                         else:
00142                             try:
00143                                 converted_value = int(value)
00144                             except:
00145                                 converted_value = value
00146                         temp_options[option] = converted_value
00147             ctl_handle.close()
00148         for option in self._options.keys():
00149             if option in temp_options.keys():
00150                 self._options[option] = temp_options[option]
00151             else:
00152                 self._options[option] = None
                            

Here is the call graph for this function:

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

Definition at line 177 of file codeml.py.

00177 
00178                 parse = True):
00179         """Run codeml using the current configuration and then parse the results. 
00180         
00181         Return a process signal so the user can determine if
00182         the execution was successful (return code 0 is successful, -N
00183         indicates a failure). The arguments may be passed as either 
00184         absolute or relative paths, despite the fact that CODEML 
00185         requires relative paths.
00186         """
00187         if self.tree is None:
00188             raise ValueError, "Tree file not specified."
00189         if not os.path.exists(self.tree):
00190             raise IOError, "The specified tree file does not exist."
00191         Paml.run(self, ctl_file, verbose, command)
00192         if parse:
00193             results = read(self.out_file)
00194         else:
00195             results = None
00196         return results        

Here is the call graph for this function:

Dynamically build a CODEML control file from the options.

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

Definition at line 67 of file codeml.py.

00067 
00068     def write_ctl_file(self):
00069         """Dynamically build a CODEML control file from the options.
00070         
00071         The control file is written to the location specified by the 
00072         ctl_file property of the codeml class.
00073         """
00074         # Make sure all paths are relative to the working directory
00075         self._set_rel_paths()
00076         if True: #Dummy statement to preserve indentation for diff
00077             ctl_handle = open(self.ctl_file, 'w')
00078             ctl_handle.write("seqfile = %s\n" % self._rel_alignment)
00079             ctl_handle.write("outfile = %s\n" % self._rel_out_file)
00080             ctl_handle.write("treefile = %s\n" % self._rel_tree)
00081             for option in self._options.items():
00082                 if option[1] == None:
00083                     # If an option has a value of None, there's no need
00084                     # to write it in the control file; it's normally just
00085                     # commented out.
00086                     continue
00087                 if option[0] == "NSsites":
00088                     # NSsites is stored in Python as a list but in the 
00089                     # control file it is specified as a series of numbers
00090                     # separated by spaces.
00091                     NSsites = " ".join([str(site) for site in option[1]])
00092                     ctl_handle.write("%s = %s\n" % (option[0], NSsites))
00093                 else:
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 37 of file codeml.py.

Definition at line 174 of file codeml.py.

Definition at line 116 of file codeml.py.

Definition at line 36 of file codeml.py.

Definition at line 120 of file codeml.py.

Definition at line 35 of file codeml.py.


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