def test_changing_working_dir(self): """RNAsubopt: BaseCommand should be ok after changing the working dir """ temp_dir = tempfile.mkdtemp() #changing in initialization r = RNAsubopt(WorkingDir=temp_dir) self.assertEqual(r.BaseCommand,\ 'cd "%s/"; RNAsubopt -e 1 -d2 -T 37'%(temp_dir)) #changing afterwards r = RNAsubopt() r.WorkingDir = temp_dir self.assertEqual(r.BaseCommand,\ 'cd "%s/"; RNAsubopt -e 1 -d2 -T 37'%(temp_dir)) rmdir(temp_dir)
def test_base_command(self): """RNAsubopt: BaseCommand should be ok for different parameter settings """ r = RNAsubopt() obs = r.BaseCommand.split() exp = [ 'cd', '"%s/";' % getcwd(), 'RNAsubopt', '-e', '1', '-d2', '-T', '37' ] self.assertEqualItems(obs, exp) r.Parameters['-nsp'].on('GA') obs = r.BaseCommand.split() exp = ['cd','"%s/";' % getcwd(),'RNAsubopt','-e','1','-d2','-nsp','GA',\ '-T','37'] self.assertEqualItems(obs, exp) r.Parameters['Temp'].on(15) obs = r.BaseCommand.split() exp = ['cd','"%s/";' % getcwd(),'RNAsubopt','-e','1','-d2','-nsp','GA',\ '-T','15'] self.assertEqualItems(obs, exp) r.Parameters['-d'].off() obs = r.BaseCommand.split() exp = ['cd','"%s/";' % getcwd(),'RNAsubopt','-e','1','-nsp','GA','-T',\ '15'] self.assertEqualItems(obs, exp)
def predict_ss(self, method="RNAfold"): """it creats /tmp/ss.fa and runs various methods for ss prediction""" # make tmp file f = open('/tmp/ss.fa', 'w') f.write('>test\n') f.write(self.seq) f.close() # run prediction if method == "RNAsubopt": r = RNAsubopt(WorkingDir="/tmp") res = r([self.seq]) return str(res['StdOut'].read()).strip() if method == "ipknot": self.ss_log = commands.getoutput('ipknot /tmp/ss.fa') return '\n'.join(self.ss_log.split('\n')[2:]) if method == "contextfold": cmd = "cd /home/magnus/work/opt/ContextFold_1_00 && java -cp bin contextFold.app.Predict in:" + self.seq self.ss_log = commands.getoutput(cmd) return '\n'.join(self.ss_log.split('\n')[1:]) if method == "centroid_fold": self.ss_log = commands.getoutput('centroid_fold /tmp/ss.fa') return '\n'.join(self.ss_log.split('\n')[2:]) if method == 'RNAfold': r = RNAfold(WorkingDir="/tmp") res = r([self.seq]) self.ss_log = res['StdOut'].read() return self.ss_log.strip().split('\n')[-1].split()[0]
def test_get_result_paths(self): """RNAsubopt: _get_result_paths() should create the right dict entries """ r = RNAsubopt() seq = ['AUAGCUAGCUAUGCGCUAGCGGAUUAGCUAGCUAGCGA',\ 'ucgaucgaucagcuagcuauuauauaua'] res = r(seq) self.assertEqualItems(res.keys(),\ ['StdOut','StdErr','ExitStatus']) self.failUnless(res['StdOut'] is not None) self.failUnless(res['StdErr'] is None) self.assertEqual(res['ExitStatus'], 0) res.cleanUp() r = RNAsubopt({'-s':None,'-lodos':None,'-d':3,'-logML':None,\ '-noLP':None,'-4':None,'-noGU':None,'-noCloseGU':None}) res = r(seq) self.assertEqualItems(res.keys(),\ ['StdOut','StdErr','ExitStatus']) self.failUnless(res['StdOut'] is not None) self.failUnless(res['StdErr'] is None) #self.assertEqual(res['ExitStatus'],0) #platform-dependent? res.cleanUp()
def test_stdout_input_as_path_space(self): """RNAsubopt: StdOut with input_as_path and space in filename""" mixed_seq2 = [ '>namedseq2', 'AUAGCUAGCUAUGCGCUAGC', 'ACGGCUAUAGCUAGCGA', 'gcuagcuauuauauaua' ] r = RNAsubopt(InputHandler='_input_as_path') f = open('/tmp/rna test file', 'w') f.write('\n'.join(mixed_seq2)) f.close() exp = '\n'.join([ '> namedseq2 [100]', 'AUAGCUAGCUAUGCGCUAGC -830 100', '...((((((.....)))))) -8.30', 'ACGGCUAUAGCUAGCGA -320 100', '...(((......))).. -2.30', '...((((....)))).. -3.20', 'GCUAGCUAUUAUAUAUA 0 100', '................. 0.00' ]) + '\n' res = r('/tmp/rna test file') obs = res['StdOut'].read() self.assertEqual(obs, exp) res.cleanUp() remove('/tmp/rna test file')
def test_stdout(self): """RNAsubopt: StdOut should be as expected""" r = RNAsubopt() seq = ['AUAGCUAGCUAUGCGCUAGCGGAUUAGCUAGCUAGCGA',\ 'ucgaucgaucagcuagcuauuauauaua'] exp = '\n'.join( ['AUAGCUAGCUAUGCGCUAGCGGAUUAGCUAGCUAGCGA -1720 100', '.(((((((((.(((....)))....))))))))).... -16.20', '.(((((((((((.((....)).)).))))))))).... -17.20', '.((((((((((..((....))...)))))))))).... -16.60', '.((((((((((.((....))....)))))))))).... -16.40', '.(((((((((((((....)))...)))))))))).... -16.90', '.(((((((((((.((....)).).)))))))))).... -17.20', 'UCGAUCGAUCAGCUAGCUAUUAUAUAUA 0 100', '......(((.((....)))))....... 0.70', '..........((....)).......... 0.60', '..((....)).................. 0.90', '............................ 0.00']) + '\n' res = r(seq) obs = res['StdOut'].read() self.assertEqual(obs,exp) res.cleanUp()