Back to index

python-biopython  1.60
Public Member Functions | Public Attributes | Static Public Attributes
test_PAML_baseml.ModTest Class Reference

List of all members.

Public Member Functions

def tearDown
def setUp
def testAlignmentFileIsValid
def testAlignmentExists
def testTreeFileValid
def testTreeExists
def testWorkingDirValid
def testOutputFileValid
def testOptionExists
def testAlignmentSpecified
def testTreeSpecified
def testOutputFileSpecified
def testPamlErrorsCaught
def testCtlFileValidOnRun
def testCtlFileExistsOnRun
def testCtlFileValidOnRead
def testCtlFileExistsOnRead
def testResultsValid
def testResultsExist
def testResultsParsable
def testParseAllVersions
def testParseModel
def testParseAlpha1Rho1
def testParseNhomo
def testParseSEs

Public Attributes

 bml

Static Public Attributes

tuple align_dir = os.path.join("PAML", "Alignments")
tuple tree_dir = os.path.join("PAML", "Trees")
tuple ctl_dir = os.path.join("PAML", "Control_files")
tuple results_dir = os.path.join("PAML", "Results")
tuple working_dir = os.path.join("PAML", "baseml_test")
tuple align_file = os.path.join(align_dir, "alignment.phylip")
tuple tree_file = os.path.join(tree_dir, "species.tree")
tuple bad_tree_file = os.path.join(tree_dir, "bad.tree")
tuple out_file = os.path.join(results_dir, "test.out")
tuple results_file = os.path.join(results_dir, "bad_results.out")
tuple bad_ctl_file1 = os.path.join(ctl_dir, "bad1.ctl")
tuple bad_ctl_file2 = os.path.join(ctl_dir, "bad2.ctl")
tuple ctl_file = os.path.join(ctl_dir, "baseml.ctl")

Detailed Description

Definition at line 13 of file test_PAML_baseml.py.


Member Function Documentation

Definition at line 43 of file test_PAML_baseml.py.

00043 
00044     def setUp(self):
00045         self.bml = baseml.Baseml()
        
Just in case BASEML creates some junk files, do a clean-up.

Definition at line 29 of file test_PAML_baseml.py.

00029 
00030     def tearDown(self):
00031         """Just in case BASEML creates some junk files, do a clean-up."""
00032         del_files = [self.out_file, "2base.t", 
00033             "in.basemlg", "baseml.ctl", "lnf", "rates", "rst", "rst1", 
00034             "rub"]
00035         for filename in del_files:
00036             if os.path.exists(filename):
00037                 os.remove(filename)
00038         if os.path.exists(self.working_dir):
00039             for filename in os.listdir(self.working_dir):
00040                 filepath = os.path.join(self.working_dir, filename)
00041                 os.remove(filepath)
00042             os.rmdir(self.working_dir)
    

Definition at line 55 of file test_PAML_baseml.py.

00055 
00056     def testAlignmentExists(self):
00057         self.assertRaises((EnvironmentError, IOError), baseml.Baseml, 
00058             alignment = "nonexistent")
00059         self.bml.alignment = "nonexistent"
00060         self.bml.tree = self.tree_file
00061         self.bml.out_file = self.out_file
00062         self.assertRaises((EnvironmentError, IOError), 
00063             self.bml.run)
    

Definition at line 46 of file test_PAML_baseml.py.

00046 
00047     def testAlignmentFileIsValid(self):
00048         self.assertRaises((AttributeError, TypeError),
00049             baseml.Baseml, alignment = 1)
00050         self.bml.alignment = 1
00051         self.bml.tree = self.tree_file
00052         self.bml.out_file = self.out_file
00053         self.assertRaises((AttributeError, TypeError),
00054             self.bml.run)
        

Definition at line 103 of file test_PAML_baseml.py.

00103 
00104     def testAlignmentSpecified(self):
00105         self.bml.tree = self.tree_file
00106         self.bml.out_file = self.out_file
00107         self.assertRaises((AttributeError, ValueError),
00108             self.bml.run)
        

Definition at line 181 of file test_PAML_baseml.py.

00181 
00182     def testCtlFileExistsOnRead(self):
00183         self.assertRaises(IOError,
00184             self.bml.read_ctl_file, ctl_file = "nonexistent")
        

Definition at line 135 of file test_PAML_baseml.py.

00135 
00136     def testCtlFileExistsOnRun(self):
00137         self.bml.alignment = self.align_file
00138         self.bml.tree = self.tree_file
00139         self.bml.out_file = self.out_file
00140         self.assertRaises((EnvironmentError, IOError),
00141             self.bml.run, ctl_file = "nonexistent")
            

Definition at line 142 of file test_PAML_baseml.py.

00142 
00143     def testCtlFileValidOnRead(self):
00144         self.assertRaises((AttributeError, TypeError),
00145             self.bml.read_ctl_file, 1)
00146         self.assertRaises((AttributeError, KeyError), 
00147             self.bml.read_ctl_file, self.bad_ctl_file1)
00148         self.assertRaises(AttributeError, 
00149             self.bml.read_ctl_file, self.bad_ctl_file2)
00150         target_options = {"noisy": 0,
00151                         "verbose": 0,
00152                         "runmode": 0,
00153                         "model": 6,
00154                         "model_options": None,
00155                         "Mgene": 1,
00156                         "ndata": None,
00157                         "clock": 0,
00158                         "fix_kappa": 0,
00159                         "kappa": 5,
00160                         "fix_alpha": 0,
00161                         "alpha": 0.5,
00162                         "Malpha": 0,
00163                         "ncatG": 5,
00164                         "fix_rho": 1,
00165                         "rho": 0,
00166                         "nparK": 0,
00167                         "nhomo": 0,
00168                         "getSE": 0,
00169                         "RateAncestor": 0,
00170                         "Small_Diff": 7e-6,
00171                         "cleandata": 1,
00172                         "icode": None,
00173                         "fix_blength": None,
00174                         "method": 0}
00175         self.bml.read_ctl_file(self.ctl_file)
00176         self.assertEqual(sorted(self.bml._options.keys()), sorted(target_options.keys()))
00177         for key in target_options:
00178             self.assertEqual(self.bml._options[key], target_options[key], \
00179                              "%s: %r vs %r" \
00180                              % (key, self.bml._options[key], target_options[key]))
        

Definition at line 128 of file test_PAML_baseml.py.

00128 
00129     def testCtlFileValidOnRun(self):
00130         self.bml.alignment = self.align_file
00131         self.bml.tree = self.tree_file
00132         self.bml.out_file = self.out_file
00133         self.assertRaises((AttributeError, TypeError),
00134             self.bml.run, ctl_file = 1)
        

Definition at line 97 of file test_PAML_baseml.py.

00097 
00098     def testOptionExists(self):
00099         self.assertRaises((AttributeError, KeyError),
00100                           self.bml.set_options, xxxx=1)
00101         self.assertRaises((AttributeError, KeyError),
00102                           self.bml.get_option, "xxxx")
    

Definition at line 115 of file test_PAML_baseml.py.

00115 
00116     def testOutputFileSpecified(self):
00117         self.bml.alignment = self.align_file
00118         self.bml.tree = self.tree_file
00119         self.assertRaises((AttributeError, ValueError),
00120             self.bml.run)
        

Definition at line 90 of file test_PAML_baseml.py.

00090 
00091     def testOutputFileValid(self):
00092         self.bml.tree = self.tree_file
00093         self.bml.alignment = self.align_file
00094         self.bml.out_file = 1
00095         self.assertRaises((AttributeError, TypeError),
00096             self.bml.run)
    

Definition at line 121 of file test_PAML_baseml.py.

00121 
00122     def testPamlErrorsCaught(self):
00123         self.bml.alignment = self.align_file
00124         self.bml.tree = self.bad_tree_file
00125         self.bml.out_file = self.out_file
00126         self.assertRaises((EnvironmentError, PamlError),
00127             self.bml.run)
        

Definition at line 195 of file test_PAML_baseml.py.

00195 
00196     def testParseAllVersions(self):
00197         folder = os.path.join("PAML","Results", "baseml", "versions")
00198         for results_file in os.listdir(folder):
00199             file_path = os.path.join(folder, results_file)
00200             if os.path.isfile(file_path) and results_file[:6] == "baseml":
00201                 results = baseml.read(file_path)
00202                 self.assertEqual(len(results), 6)
00203                 self.assertEqual(len(results["parameters"]), 7)
    

Definition at line 235 of file test_PAML_baseml.py.

00235 
00236     def testParseAlpha1Rho1(self):
00237         # Test the auto-discrete gamma model
00238         # Cannot test for baseml 4.3-4.5 due to bug in the program which
00239         # prevents this analysis from completing
00240         res_dir = os.path.join(self.results_dir, "baseml", "alpha1rho1")
00241         for results_file in os.listdir(res_dir):
00242             version = results_file.split('-')[1].split('.')[0]
00243             model = results_file[5]
00244             version_msg = "Improper parsing for model %s version %s" \
00245                         % (model, version.replace('_', '.'))
00246             results_path = os.path.join(res_dir, results_file)
00247             results = baseml.read(results_path)
00248             # There are 6 top-levels: parameters, tree, lnL, version,
00249             # tree length and lnL max
00250             self.assertEqual(len(results), 6, version_msg)
00251             self.assertTrue("parameters" in results, version_msg)
00252             params = results["parameters"]
00253             self.assertTrue("rho" in params, version_msg)
00254             self.assertTrue("transition probs." in params, version_msg)
00255             trans_p = params["transition probs."]
00256             self.assertEqual(len(trans_p), 5, version_msg)
00257             self.assertEqual(len(trans_p[0]), 5, version_msg)
 

Definition at line 204 of file test_PAML_baseml.py.

00204 
00205     def testParseModel(self):
00206         res_dir = os.path.join(self.results_dir, "baseml", "model")
00207         for results_file in os.listdir(res_dir):
00208             version = results_file.split('-')[1].split('.')[0]
00209             model = results_file[5]
00210             version_msg = "Improper parsing for model %s version %s" \
00211                         % (model, version.replace('_', '.'))
00212             results_path = os.path.join(res_dir, results_file)
00213             results = baseml.read(results_path)
00214             # There are 6 top-levels: parameters, tree, lnL, version,
00215             # tree length and lnL max
00216             self.assertEqual(len(results), 6, version_msg)
00217             self.assertTrue("parameters" in results, version_msg)
00218             params = results["parameters"]
00219             self.assertTrue("alpha" in params, version_msg)
00220             self.assertTrue("rates" in params, version_msg)
00221             self.assertTrue("parameter list" in params, version_msg)
00222             self.assertTrue("rate frequencies" in params, version_msg)
00223             if model in ["1", "3", "4", "5", "6"]:
00224                 self.assertTrue("kappa" in params, version_msg)
00225             if model in ["7", "8"]:
00226                 self.assertTrue("base frequencies" in params, version_msg)
00227                 self.assertTrue("rate parameters" in params, version_msg)
00228                 self.assertTrue("Q matrix" in params, version_msg)
00229                 qmat = params["Q matrix"]
00230                 self.assertEqual(len(qmat), 2, version_msg)
00231                 self.assertTrue("matrix" in qmat)
00232                 matrix = qmat["matrix"]
00233                 self.assertEqual(len(matrix), 4, version_msg)
00234                 self.assertEqual(len(matrix[0]), 4, version_msg)
            

Definition at line 258 of file test_PAML_baseml.py.

00258 
00259     def testParseNhomo(self):
00260         res_dir = os.path.join(self.results_dir, "baseml", "nhomo")
00261         for results_file in os.listdir(res_dir):
00262             version = results_file.split('-')[1].split('.')[0]
00263             n = results_file[5]
00264             version_msg = "Improper parsing for nhomo %s version %s" \
00265                         % (n, version.replace('_', '.'))
00266             results_path = os.path.join(res_dir, results_file)
00267             results = baseml.read(results_path)
00268             # There are 6 top-levels: parameters, tree, lnL, version,
00269             # tree length and lnL max
00270             self.assertEqual(len(results), 6, version_msg)
00271             self.assertTrue("parameters" in results, version_msg)
00272             params = results["parameters"]
00273             if n == "1":
00274                 self.assertTrue("base frequencies" in params, version_msg)
00275             else:
00276                 self.assertTrue("nodes" in params)
00277                 nodes = params["nodes"]
00278                 self.assertEqual(len(nodes), 8, version_msg)
00279                 self.assertEqual(len(nodes[1]), 2, version_msg)

Definition at line 280 of file test_PAML_baseml.py.

00280 
00281     def testParseSEs(self):
00282         res_dir = os.path.join(self.results_dir, "baseml", "SE")
00283         for results_file in os.listdir(res_dir):
00284             version = results_file.split('-')[1].split('.')[0]
00285             version_msg = "Improper parsing for version %s" \
00286                         % version.replace('_', '.')
00287             results_path = os.path.join(res_dir, results_file)
00288             results = baseml.read(results_path)
00289             # There are 6 top-levels: parameters, tree, lnL, version,
00290             # tree length and lnL max
00291             self.assertEqual(len(results), 6, version_msg)
00292             self.assertTrue("parameters" in results, version_msg)
00293             params = results["parameters"]
00294             self.assertTrue("SEs" in params, version_msg)
00295         

Definition at line 189 of file test_PAML_baseml.py.

00189 
00190     def testResultsExist(self):
00191         self.assertRaises(IOError, baseml.read, "nonexistent")
        

Definition at line 192 of file test_PAML_baseml.py.

00192 
00193     def testResultsParsable(self):
00194         self.assertRaises(ValueError, baseml.read, self.results_file)
        

Definition at line 185 of file test_PAML_baseml.py.

00185 
00186     def testResultsValid(self):
00187         self.assertRaises((AttributeError, TypeError),
00188             baseml.read, 1)
    

Definition at line 73 of file test_PAML_baseml.py.

00073 
00074     def testTreeExists(self):
00075         self.assertRaises((EnvironmentError, IOError), baseml.Baseml, 
00076             tree = "nonexistent")
00077         self.bml.alignment = self.align_file
00078         self.bml.tree = "nonexistent"
00079         self.bml.out_file = self.out_file
00080         self.assertRaises((EnvironmentError, IOError),
00081             self.bml.run)
    

Definition at line 64 of file test_PAML_baseml.py.

00064 
00065     def testTreeFileValid(self):
00066         self.assertRaises((AttributeError, TypeError),
00067             baseml.Baseml, tree = 1)
00068         self.bml.alignment = self.align_file
00069         self.bml.tree = 1
00070         self.bml.out_file = self.out_file
00071         self.assertRaises((AttributeError, TypeError),
00072             self.bml.run)
        

Definition at line 109 of file test_PAML_baseml.py.

00109 
00110     def testTreeSpecified(self):
00111         self.bml.alignment = self.align_file
00112         self.bml.out_file = self.out_file
00113         self.assertRaises((AttributeError, ValueError),
00114             self.bml.run)
        

Definition at line 82 of file test_PAML_baseml.py.

00082 
00083     def testWorkingDirValid(self):
00084         self.bml.tree = self.tree_file
00085         self.bml.alignment = self.align_file
00086         self.bml.out_file = self.out_file
00087         self.bml.working_dir = 1
00088         self.assertRaises((AttributeError, TypeError),
00089             self.bml.run)
    

Member Data Documentation

tuple test_PAML_baseml.ModTest.align_dir = os.path.join("PAML", "Alignments") [static]

Definition at line 14 of file test_PAML_baseml.py.

tuple test_PAML_baseml.ModTest.align_file = os.path.join(align_dir, "alignment.phylip") [static]

Definition at line 20 of file test_PAML_baseml.py.

tuple test_PAML_baseml.ModTest.bad_ctl_file1 = os.path.join(ctl_dir, "bad1.ctl") [static]

Definition at line 25 of file test_PAML_baseml.py.

tuple test_PAML_baseml.ModTest.bad_ctl_file2 = os.path.join(ctl_dir, "bad2.ctl") [static]

Definition at line 26 of file test_PAML_baseml.py.

tuple test_PAML_baseml.ModTest.bad_tree_file = os.path.join(tree_dir, "bad.tree") [static]

Definition at line 22 of file test_PAML_baseml.py.

Definition at line 44 of file test_PAML_baseml.py.

tuple test_PAML_baseml.ModTest.ctl_dir = os.path.join("PAML", "Control_files") [static]

Definition at line 16 of file test_PAML_baseml.py.

tuple test_PAML_baseml.ModTest.ctl_file = os.path.join(ctl_dir, "baseml.ctl") [static]

Definition at line 27 of file test_PAML_baseml.py.

tuple test_PAML_baseml.ModTest.out_file = os.path.join(results_dir, "test.out") [static]

Definition at line 23 of file test_PAML_baseml.py.

tuple test_PAML_baseml.ModTest.results_dir = os.path.join("PAML", "Results") [static]

Definition at line 17 of file test_PAML_baseml.py.

tuple test_PAML_baseml.ModTest.results_file = os.path.join(results_dir, "bad_results.out") [static]

Definition at line 24 of file test_PAML_baseml.py.

tuple test_PAML_baseml.ModTest.tree_dir = os.path.join("PAML", "Trees") [static]

Definition at line 15 of file test_PAML_baseml.py.

tuple test_PAML_baseml.ModTest.tree_file = os.path.join(tree_dir, "species.tree") [static]

Definition at line 21 of file test_PAML_baseml.py.

tuple test_PAML_baseml.ModTest.working_dir = os.path.join("PAML", "baseml_test") [static]

Definition at line 18 of file test_PAML_baseml.py.


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