def test_changing_working_dir(self): """Clustalw BaseCommand should change according to WorkingDir""" c = Clustalw(WorkingDir='/tmp/clustaltest') self.assertEqual(c.BaseCommand,\ ''.join(['cd "','/tmp/clustaltest','/"; ','clustalw -align'])) c = Clustalw(WorkingDir='/tmp/clustaltest/') self.assertEqual(c.BaseCommand,\ ''.join(['cd "','/tmp/clustaltest/','/"; ','clustalw -align'])) c = Clustalw() c.WorkingDir = '/tmp/clustaltest2/' self.assertEqual(c.BaseCommand,\ ''.join(['cd "','/tmp/clustaltest2/','/"; ','clustalw -align'])) #removing the dirs is proof that they were created at the same time #if the dirs are not there, an OSError will be raised rmdir('/tmp/clustaltest') rmdir('/tmp/clustaltest2')
def test_tree_outputtree(self): """Clustalw tree should work correctly with outputtree""" c = Clustalw(params={'-tree':None,'-outputtree':'dist',\ '-infile':'/tmp/ct/align1'},WorkingDir='/tmp/ct/') c.Parameters['-align'].off() res = c() self.assertEqual(res['Tree'].name, '/tmp/ct/align1.ph') self.assertEqual(res['TreeInfo'].name, '/tmp/ct/align1.dst') res.cleanUp()
def test_stdout_input_as_string(self): """Clustalw input_as_string shoud function as expected""" c = Clustalw(WorkingDir='/tmp/ct') res = c('/tmp/ct/seq1.txt') self.assertEqual(cw_vers.sub("", res['StdOut'].read()), cw_vers.sub("", self.stdout1)) self.assertEqual(res['StdErr'].read(), '') self.assertEqual(cw_vers.sub("", res['Align'].read()), cw_vers.sub("", self.aln1)) self.assertEqual(res['Dendro'].read(), self.dnd1) res.cleanUp()
def test_profile_newtree(self): """Clustalw profile should work correctly with new/usetree""" c = Clustalw(params={'-profile':None,'-profile1':'/tmp/ct/seq1.txt',\ '-profile2':'/tmp/ct/seq2.txt','-newtree1':'lala'},\ WorkingDir='/tmp/ct') c.Parameters['-align'].off() res = c() self.assertEqual(res['Align'], None) self.assertEqual(res['Dendro1'].name, '/tmp/ct/lala') self.assertEqual(res['Dendro2'].name, '/tmp/ct/seq2.dnd') res.cleanUp()
def test_sequences_newtree(self): """Clustalw sequences should work correctly with new/usetree""" c = Clustalw(params={'-sequences':None,'-newtree':'lala',\ '-profile1':'/tmp/ct/align1','-profile2':'/tmp/ct/seq2.txt'},\ WorkingDir='/tmp/ct') c.Parameters['-align'].off() res = c() self.assertEqual(res['Align'], None) self.assertEqual(res['Dendro'].name, '/tmp/ct/lala') res.cleanUp() #is this a bug in clustal. It's creating an empty file 'seq2.aln' #but doesn't report it in the stdout remove('/tmp/ct/seq2.aln')
def test_base_command(self): """Clustalw BaseCommand should return the correct BaseCommand""" c = Clustalw() self.assertEqual(c.BaseCommand,\ ''.join(['cd "',getcwd(),'/"; ','clustalw -align'])) c.Parameters['-infile'].on('seq.txt') self.assertEqual(c.BaseCommand,\ ''.join(['cd "',getcwd(),'/"; ',\ 'clustalw -infile="seq.txt" -align'])) c.Parameters['-align'].off() self.assertEqual(c.BaseCommand,\ ''.join(['cd "',getcwd(),'/"; ','clustalw -infile="seq.txt"'])) c.Parameters['-nopgap'].on() c.Parameters['-infile'].off() self.assertEqual(c.BaseCommand,\ ''.join(['cd "',getcwd(),'/"; ','clustalw -nopgap']))
def test_changing_working_dir(self): """Clustalw BaseCommand should change according to WorkingDir""" c = Clustalw(WorkingDir='/tmp/clustaltest') self.assertEqual(c.BaseCommand,\ ''.join(['cd "','/tmp/clustaltest','/"; ','clustalw -align'])) c = Clustalw(WorkingDir='/tmp/clustaltest/') self.assertEqual(c.BaseCommand,\ ''.join(['cd "','/tmp/clustaltest/','/"; ','clustalw -align'])) c = Clustalw() c.WorkingDir = '/tmp/clustaltest2/' self.assertEqual(c.BaseCommand,\ ''.join(['cd "','/tmp/clustaltest2/','/"; ','clustalw -align'])) #removing the dirs is proof that they were created at the same time #if the dirs are not there, an OSError will be raised rmdir('/tmp/clustaltest') rmdir('/tmp/clustaltest2')
def test_stdout_input_as_multiline_string(self): """Clustalw input_as_multiline_string should function as expected""" c = Clustalw(InputHandler='_input_as_multiline_string',\ WorkingDir='/tmp/ct') res = c(self.multiline1) name = c.Parameters['-infile'].Value out = self.stdout1.split('\n') out[16] =\ 'Guide tree file created: ['+name.rsplit(".")[0]+'.dnd]' out[23] =\ 'CLUSTAL-Alignment file created ['+name.rsplit(".")[0]+'.aln]' self.assertEqual(cw_vers.sub("", res['StdOut'].read()), cw_vers.sub("", '\n'.join(out))) self.assertEqual(res['StdErr'].read(), '') self.assertEqual(cw_vers.sub("", res['Align'].read()), cw_vers.sub("", self.aln1)) self.assertEqual(res['Dendro'].read(), self.dnd1) res.cleanUp()
def test_alignment_trees(self): """Clustalw alignment should work correctly with new/usetree""" c = Clustalw(params={'-quicktree':True,'-type':'DNA','-gapopen':10},\ WorkingDir='/tmp/ct') res = c('/tmp/ct/seq1.txt') self.assertEqual(res['Align'].name, '/tmp/ct/seq1.aln') self.assertEqual(res['Dendro'].name, '/tmp/ct/seq1.dnd') res.cleanUp() c.Parameters['-usetree'].on('/tmp/ct/tree1') c.Parameters['-output'].on('PHYLIP') res = c('/tmp/ct/seq1.txt') self.assertEqual(res['Align'].name, '/tmp/ct/seq1.phy') self.assertEqual(res['Dendro'].name, '/tmp/ct/tree1') res.cleanUp() c.Parameters['-newtree'].on('newtree') c.Parameters['-outfile'].on('outfile') res = c('/tmp/ct/seq1.txt') self.assertEqual(res['Align'].name, c.WorkingDir + 'outfile') self.assertEqual(res['Dendro'].name, c.WorkingDir + 'newtree') res.cleanUp()
def test_stdout_input_as_lines_local(self): """Clustalw input_as_lines should function as expected""" c = Clustalw(InputHandler='_input_as_lines', WorkingDir=self.temp_dir_space) res = c(self.lines1) #get info on input file name and change output accordingly name = c.Parameters['-infile'].Value out = self.stdout1.split('\n') out[16] =\ 'Guide tree file created: ['+name.rsplit(".")[0]+'.dnd]' out[23] =\ 'CLUSTAL-Alignment file created ['+name.rsplit(".")[0]+'.aln]' self.assertEqual(cw_vers.sub("", res['StdOut'].read()), cw_vers.sub("", '\n'.join(out))) self.assertEqual(res['StdErr'].read(), '') self.assertEqual(cw_vers.sub("", res['Align'].read()), cw_vers.sub("", self.aln1)) self.assertEqual(res['Dendro'].read(), self.dnd1) res.cleanUp()