3
__author__ = "Jesse Stombaugh"
4
__copyright__ = "Copyright 2007-2011, The Cogent Project"
5
__credits__ = ["Jesse Stombaugh"]
7
__version__ = "1.6.0dev"
8
__maintainer__ = "Jesse Stombaugh"
9
__email__ = "jesse.stombaugh@colorado.edu"
10
__status__ = "Release"
12
from os import getcwd, remove, rmdir, mkdir
13
from os.path import splitext
14
from cogent.util.unit_test import TestCase, main
15
from cogent.util.misc import flatten
16
from random import randint
17
from qiime.pycogent_backports.pplacer import Pplacer, insert_sequences_into_tree
18
from cogent.app.util import ApplicationError,get_tmp_filename
19
from cogent.parse.fasta import MinimalFastaParser
20
from cogent.core.tree import PhyloNode
21
from cogent.core.moltype import RNA,DNA
22
from StringIO import StringIO
23
from cogent.core.alignment import Alignment
25
class Genericpplacer(TestCase):
28
'''setup the files for testing pplacer'''
30
# create a list of files to cleanup
31
self._paths_to_clean_up = []
32
self._dirs_to_clean_up = []
34
# get a tmp filename to use
35
basename=splitext(get_tmp_filename())[0]
37
# create and write out RAxML stats file
38
self.stats_fname=basename+'.stats'
39
stats_out=open(self.stats_fname,'w')
40
stats_out.write(RAXML_STATS)
42
self._paths_to_clean_up.append(self.stats_fname)
44
# create and write out reference sequence file
45
self.refseq_fname=basename+'_refseqs.fasta'
46
refseq_out=open(self.refseq_fname,'w')
47
refseq_out.write(REF_SEQS)
49
self._paths_to_clean_up.append(self.refseq_fname)
51
# create and write out query sequence file
52
self.query_fname=basename+'_queryseqs.fasta'
53
query_out=open(self.query_fname,'w')
54
query_out.write(QUERY_SEQS)
56
self._paths_to_clean_up.append(self.query_fname)
58
# create and write out starting tree file
59
self.tree_fname=basename+'.tre'
60
tree_out=open(self.tree_fname,'w')
61
tree_out.write(REF_TREE)
63
self._paths_to_clean_up.append(self.tree_fname)
65
def writeTmp(self, outname):
66
"""Write data to temp file"""
67
t = open(outname, "w+")
73
"""cleans up all files initially created"""
74
# remove the tempdir and contents
75
map(remove,self._paths_to_clean_up)
76
map(rmdir,self._dirs_to_clean_up)
78
class pplacerTests(Genericpplacer):
79
"""Tests for the pplacer application controller"""
81
def test_pplacer(self):
82
"""Base command-calls"""
86
self.assertEqual(app.BaseCommand, \
87
''.join(['cd "',getcwd(),'/"; ','pplacer']))
89
app.Parameters['--help'].on()
90
self.assertEqual(app.BaseCommand, \
91
''.join(['cd "',getcwd(),'/"; ','pplacer --help']))
93
def test_change_working_dir(self):
94
"""Change working dir"""
96
working_dir='/tmp/Pplacer'
97
self._dirs_to_clean_up.append(working_dir)
99
# define working directory for output
100
app = Pplacer(WorkingDir=working_dir)
102
self.assertEqual(app.BaseCommand, \
103
''.join(['cd "','/tmp/Pplacer','/"; ','pplacer']))
106
def test_insert_sequences_into_tree(self):
107
"""Inserts sequences into Tree"""
110
# generate temp filename for output
111
params["-r"] = self.refseq_fname
112
params["-t"] = self.tree_fname
113
params["-s"] = self.stats_fname
114
params["--out-dir"] = "/tmp"
116
aln_ref_query=MinimalFastaParser(StringIO(QUERY_SEQS))
117
aln = Alignment(aln_ref_query)
118
seqs, align_map = aln.toPhylip()
119
tree = insert_sequences_into_tree(seqs, DNA, params=params,
122
# rename tips back to query names
123
for node in tree.tips():
124
if node.Name in align_map:
125
node.Name = align_map[node.Name]
127
self.assertEqual(tree.getNewick(with_distances=True), RESULT_TREE)
132
"((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];",
136
[[0, -113.210938, 0.713818, 0.064504, 0.000006],
137
[1, -114.929894, 0.127954, 0.137122, 0.000007],
138
[2, -114.932766, 0.127587, 0.000008, 0.000006],
139
[6, -117.743534, 0.007675, 0.000141, 0.027211],
140
[3, -117.743759, 0.007674, 0.020310, 0.027207],
141
[4, -117.747386, 0.007646, 0.000131, 0.027266],
142
[5, -117.747396, 0.007646, 0.000131, 0.027266]
143
], "n": ["seq0000006"]
145
{"p": [[0, -113.476305, 1.000000, 0.035395, 0.000006]], "n":
150
"pplacer -t %s -r %s -s %s --out-dir \/tmp %s"
151
}, "version": 1, "fields":
152
["edge_num", "likelihood", "like_weight_ratio", "distal_length",
156
""".replace('\n','').replace(' ','')
161
TGCATGTCAGTATAGCTTTGGTGAAACTGCGAATGGCTCATTAAATCAGT
163
TGCATGTCAGTATAACTTTGGTGAAACTGCGAATGGCTCATTAAATCAGT
169
TGCATGTCAGTATAGCTTTAGTGAAACTGCGAATGGCTCATTAAATCAGT
171
TGCATGTCAGTATAGCTTTAGTGAAACTGCGAATGGCTNNTTAAATCAGT
173
TGCATGTCAGTATAGCATTAGTGAAACTGCGAATGGCTCATTAAATCAGT
175
TCCATGTCAGTATAACTTTGGTGAAACTGCGAATGGCTCATTAAATCAGG
177
NNNNNNNNNNTATATCTTATGTGAAACTTCGAATGCCTCATTAAATCAGT
180
REF_TREE="""((seq0000014:0.08408,seq0000015:0.13713)0.609:0.00215,seq0000013:0.02032,(seq0000011:0.00014,seq0000012:0.00014)0.766:0.00015);
183
RESULT_TREE="""((((seq0000014:0.0353946,7:6.11352e-06):0.0291093,6:6.11352e-06):0.019576,seq0000015:0.13713)0.609:0.00215,seq0000013:0.02032,(seq0000011:0.00014,seq0000012:0.00014)0.766:0.00015);"""
188
This is RAxML version 7.2.6 released by Alexandros Stamatakis in February 2010.
190
With greatly appreciated code contributions by:
195
Nick Pattengale (UNM)
196
Wayne Pfeiffer (SDSC)
199
Alignment has 18 distinct alignment patterns
201
Proportion of gaps and completely undetermined characters in this alignment: 4.80%
203
RAxML rapid hill-climbing mode
205
Using 1 distinct models/data partitions with joint branch length optimization
208
Executing 1 inferences on the original alignment using 1 distinct randomized MP trees
210
All free model parameters will be estimated by RAxML
211
ML estimate of 25 per site rate categories
213
Likelihood of final tree will be evaluated and optimized under GAMMA
215
GAMMA Model parameters will be estimated up to an accuracy of 0.1000000000 Log Likelihood units
218
Alignment Patterns: 18
219
Name: No Name Provided
221
Substitution Matrix: GTR
226
RAxML was called as follows:
228
raxmlHPC -m GTRCAT -s test_raxml.phy -n results
231
Inference[0]: Time 0.072128 CAT-based likelihood -85.425107, best rearrangement setting 2
232
alpha[0]: 1.000000 rates[0] ac ag at cg ct gt: 0.000017 0.037400 0.859448 1.304301 0.000017 1.000000
235
Conducting final model optimizations on all 1 trees under GAMMA-based models ....
237
Inference[0] final GAMMA-based Likelihood: -107.575676 tree written to file /home/RAxML_result.results
240
Starting final GAMMA-based thorough Optimization on tree 0 likelihood -107.575676 ....
242
Final GAMMA-based Score of best tree -107.575676
244
Program execution info written to /home/RAxML_info.results
245
Best-scoring ML tree written to: /home/RAxML_bestTree.results
247
Overall execution time: 0.078965 secs or 0.000022 hours or 0.000001 days
250
if __name__ == '__main__':