Пример #1
0
 def test_changing_working_dir(self):
     """RNAfold: BaseCommand should be ok after changing the working dir"""
     #changing in initialization
     temp_dir = tempfile.mkdtemp()
     r = RNAfold(WorkingDir=temp_dir)
     self.assertEqual(r.BaseCommand,\
         'cd "%s/"; RNAfold -d1 -T 37 -S 1.07'%(temp_dir))
     #changing afterwards
     r = RNAfold()
     r.WorkingDir = temp_dir
     self.assertEqual(r.BaseCommand,\
         'cd "%s/"; RNAfold -d1 -T 37 -S 1.07'%(temp_dir))
     rmdir(temp_dir)
Пример #2
0
 def test_changing_working_dir(self):
     """RNAfold: BaseCommand should be ok after changing the working dir"""
     #changing in initialization
     temp_dir = tempfile.mkdtemp()
     r = RNAfold(WorkingDir=temp_dir)
     self.assertEqual(r.BaseCommand,\
         'cd "%s/"; RNAfold -d1 -T 37 -S 1.07'%(temp_dir))
     #changing afterwards
     r = RNAfold()
     r.WorkingDir = temp_dir
     self.assertEqual(r.BaseCommand,\
         'cd "%s/"; RNAfold -d1 -T 37 -S 1.07'%(temp_dir))
     rmdir(temp_dir)
Пример #3
0
    def test_base_command(self):
        """RNAfold: BaseCommand should be ok for different parameter settings"""
        r = RNAfold()
        working_dir = getcwd()

        obs = r.BaseCommand.split()
        exp = [
            'cd',
            '"%s/";' % getcwd(), 'RNAfold', '-d1', '-T', '37', '-S', '1.07'
        ]
        self.assertEqualItems(obs, exp)

        r.Parameters['-noLP'].on()
        obs = r.BaseCommand.split()
        exp = ['cd','"%s/";' % getcwd(),'RNAfold','-d1','-noLP','-T','37',\
               '-S','1.07']
        self.assertEqualItems(obs, exp)

        r.Parameters['Temp'].on(15)
        obs = r.BaseCommand.split()
        exp = ['cd','"%s/";' % getcwd(),'RNAfold','-d1','-noLP','-T','15', \
               '-S','1.07']
        self.assertEqualItems(obs, exp)

        r.Parameters['-d'].off()
        obs = r.BaseCommand.split()
        exp = [
            'cd',
            '"%s/";' % getcwd(), 'RNAfold', '-noLP', '-T', '15', '-S', '1.07'
        ]
        self.assertEqualItems(obs, exp)
Пример #4
0
    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]
Пример #5
0
    def test_get_result_paths_mixed_seq(self):
        """RNAfold: _get_result_paths() should work on partly named seq"""

        r = RNAfold()
        res = r(self.mixed_seq)
        self.assertEqualItems(res.keys(),\
            ['StdOut','StdErr','ExitStatus','SS','DP','namedseq1_ss',\
            'namedseq1_dp'])
        res.cleanUp()
Пример #6
0
 def test_stdout(self):
     """RNAfold: StdOut should be as expected"""
     r = RNAfold()
     exp = '\n'.join(['>namedseq1','AUAGCUAGCUAUGCGCUAGC',\
         '...((((((.....)))))) ( -8.30)','ACGGCUAUAGCUAGCGA',\
         '...((((....)))).. ( -3.20)','GCUAGCUAUUAUAUAUA',\
         '................. (  0.00)'])+'\n'
     res = r(self.mixed_seq)
     obs = res['StdOut'].read()
     self.assertEqual(obs, exp)
     res.cleanUp()
Пример #7
0
 def test_get_result_paths_unnamed_seq(self):
     """RNAfold: _get_result_paths() should work on unnamed seq"""
     r = RNAfold()
     res = r(self.unnamed_seq)
     self.assertEqualItems(res.keys(),\
         ['StdOut','StdErr','ExitStatus','SS','DP'])
     self.failUnless(res['DP'] is None)
     self.failUnless(res['SS'] is not None)
     self.failUnless(res['StdOut'] is not None)
     self.failUnless(res['StdErr'] is None)
     self.assertEqual(res['ExitStatus'], 0)
     res.cleanUp()
Пример #8
0
 def test_get_result_paths_working_dir(self):
     """RNAfold: _get_result_paths() should work with diff working dir"""
     r = RNAfold(WorkingDir=self.temp_dir)
     res = r(self.unnamed_seq)
     self.assertEqualItems(res.keys(),\
         ['StdOut','StdErr','ExitStatus','SS','DP'])
     self.failUnless(res['DP'] is None)
     self.failUnless(res['SS'] is not None)
     self.failUnless(isinstance(res['SS'], file))
     self.failUnless(res['StdOut'] is not None)
     self.failUnless(res['StdErr'] is None)
     self.assertEqual(res['ExitStatus'], 0)
     res.cleanUp()
Пример #9
0
    def test_get_result_paths_parameter(self):
        """RNAfold: _get_result_paths() should work with diff parameters"""

        r = RNAfold()
        r.Parameters['-p'].on()
        res = r(self.unnamed_seq)
        self.assertEqualItems(list(res.keys()),\
            ['StdOut','StdErr','ExitStatus','SS','DP'])
        self.assertTrue(res['DP'] is not None)
        self.assertTrue(res['SS'] is not None)
        self.assertTrue(res['StdOut'] is not None)
        self.assertTrue(res['StdErr'] is None)
        self.assertEqual(res['ExitStatus'],0)
        res.cleanUp()
Пример #10
0
 def test_stdout_input_as_path(self):
     """RNAfold: StdOut with input_as_path"""
     r = RNAfold(InputHandler='_input_as_path')
     f = open('/tmp/rnatestfile', 'w')
     f.write('\n'.join(self.mixed_seq2))
     f.close()
     exp = '\n'.join(['>namedseq2','AUAGCUAGCUAUGCGCUAGC',\
         '...((((((.....)))))) ( -8.30)','ACGGCUAUAGCUAGCGA',\
         '...((((....)))).. ( -3.20)','GCUAGCUAUUAUAUAUA',\
         '................. (  0.00)'])+'\n'
     res = r('/tmp/rnatestfile')
     obs = res['StdOut'].read()
     self.assertEqual(obs, exp)
     res.cleanUp()
     remove('/tmp/rnatestfile')