1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
#!/bin/env python
__author__ = "Jesse Stombaugh"
__copyright__ = "Copyright 2007-2012, The Cogent Project"
__credits__ = ["Jesse Stombaugh"]
__license__ = "GPL"
__version__ = "1.5.3"
__maintainer__ = "Jesse Stombaugh"
__email__ = "jesse.stombaugh@colorado.edu"
__status__ = "Production"
from os import getcwd, remove, rmdir, mkdir
from os.path import splitext
from cogent.util.unit_test import TestCase, main
from cogent.util.misc import flatten
from random import randint
from cogent.app.guppy import Guppy, build_tree_from_json_using_params
from cogent.app.util import ApplicationError,get_tmp_filename
from cogent.core.tree import PhyloNode
from cogent.parse.tree import DndParser
class Genericguppy(TestCase):
def setUp(self):
'''setup the files for testing guppy'''
# create a list of files to cleanup
self._paths_to_clean_up = []
self._dirs_to_clean_up = []
# get a tmp filename to use
basename=splitext(get_tmp_filename())[0]
# create and write out RAxML stats file
self.json_fname=basename+'.json'
json_out=open(self.json_fname,'w')
json_out.write(JSON_RESULT)
json_out.close()
self._paths_to_clean_up.append(self.json_fname)
def tearDown(self):
"""cleans up all files initially created"""
# remove the tempdir and contents
map(remove,self._paths_to_clean_up)
map(rmdir,self._dirs_to_clean_up)
class guppyTests(Genericguppy):
"""Tests for the guppy application controller"""
def test_guppy(self):
"""Base command-calls"""
app=Guppy()
self.assertEqual(app.BaseCommand, \
''.join(['cd "',getcwd(),'/"; ','guppy']))
app.Parameters['--help'].on()
self.assertEqual(app.BaseCommand, \
''.join(['cd "',getcwd(),'/"; ','guppy --help']))
def test_change_working_dir(self):
"""Change working dir"""
# define working directory for output
working_dir='/tmp/Guppy'
self._dirs_to_clean_up.append(working_dir)
app = Guppy(WorkingDir=working_dir)
self.assertEqual(app.BaseCommand, \
''.join(['cd "','/tmp/Guppy','/"; ','guppy']))
def test_build_tree_from_alignment_using_params(self):
"""Builds a tree from a json file"""
# define working directory for output
outdir='/tmp/'
# set params
params={}
params["tog"] = None
# build tree
tree = build_tree_from_json_using_params(self.json_fname,
output_dir=outdir,
params=params)
self.assertEqual(tree.getNewick(),
DndParser(TREE_RESULT, constructor=PhyloNode).getNewick())
JSON_RESULT="""\
{"tree":
"((seq0000004:0.08408[0],seq0000005:0.13713[1])0.609:0.00215[2],seq0000003:0.02032[3],(seq0000001:0.00014[4],seq0000002:0.00014[5])0.766:0.00015[6]):0[7];",
"placements":
[
{"p":
[[0, -113.210938, 0.713818, 0.064504, 0.000006],
[1, -114.929894, 0.127954, 0.137122, 0.000007],
[2, -114.932766, 0.127587, 0.000008, 0.000006],
[6, -117.743534, 0.007675, 0.000141, 0.027211],
[3, -117.743759, 0.007674, 0.020310, 0.027207],
[4, -117.747386, 0.007646, 0.000131, 0.027266],
[5, -117.747396, 0.007646, 0.000131, 0.027266]
], "n": ["seq0000006"]
},
{"p": [[0, -113.476305, 1.000000, 0.035395, 0.000006]], "n":
["seq0000007"]
}
], "metadata":
{"invocation":
"guppy -t %s -r %s -s %s --out-dir \/tmp %s"
}, "version": 1, "fields":
["edge_num", "likelihood", "like_weight_ratio", "distal_length",
"pendant_length"
]
}
""".replace('\n','').replace(' ','')
TREE_RESULT="""\
((((seq0000004:0.035395,seq0000007:6e-06)\
:0.029109,seq0000006:6e-06)\
:0.019576,seq0000005:0.13713)\
0.609:0.00215,seq0000003:0.02032,(seq0000001:0.00014,seq0000002:0.00014)\
0.766:0.00015)\
:0;
"""
if __name__ == '__main__':
main()
|