Beispiel #1
0
    def test_hmmscan_task_multithreaded(self):
        with TemporaryDirectory() as td:
            with Move(td):
                with TestData('20aa-alitest.fa', td) as prot, \
                     TestData('20aa.hmm', td) as hmm, \
                     TemporaryFile(td) as out_single,\
                     TemporaryFile(td) as out_multi:

                    for n_threads in (2, 3, 4, 5):
                        db_task = tasks.get_hmmpress_task(
                            hmm, self.hmmpress_cfg)
                        aln_task_single = tasks.get_hmmscan_task(
                            prot, out_single, hmm, 1.0, 1, self.hmmscan_cfg)
                        aln_task_multi = tasks.get_hmmscan_task(
                            prot, out_multi, hmm, 1.0, n_threads,
                            self.hmmscan_cfg)
                        run_tasks([db_task, aln_task_single], ['run'])
                        run_task(aln_task_multi)
                        print(os.listdir(td), file=sys.stderr)

                        print(open(out_single).read())
                        alns_single = pd.concat(hmmscan_to_df_iter(out_single))
                        alns_multi = pd.concat(hmmscan_to_df_iter(out_multi))

                        self.assertTrue(all(alns_single['domain_i_evalue'].sort_values() == \
                                            alns_multi['domain_i_evalue'].sort_values()))
Beispiel #2
0
    def test_cmscan_task_multithreaded(self):
        with TemporaryDirectory() as td:
            with Move(td):
                with TestData('rnaseP-bsu.fa', td) as transcript, \
                     TestData('rnaseP-eubact.c.cm', td) as cm, \
                     TemporaryFile(td) as out_single,\
                     TemporaryFile(td) as out_multi:

                    for n_threads in (2, 3, 4, 5):

                        db_task = tasks.get_cmpress_task(cm, self.cmpress_cfg)
                        aln_task_single = tasks.get_cmscan_task(
                            transcript, out_single, cm, 1.0, 1,
                            self.cmscan_cfg)
                        aln_task_multi = tasks.get_cmscan_task(
                            transcript, out_multi, cm, 1.0, n_threads,
                            self.cmscan_cfg)
                        run_tasks([db_task, aln_task_single], ['run'])
                        run_task(aln_task_multi)

                        alns_single = pd.concat(cmscan_to_df_iter(out_single))
                        alns_multi = pd.concat(cmscan_to_df_iter(out_multi))

                        self.assertTrue(all(alns_single['e_value'].sort_values() == \
                                            alns_multi['e_value'].sort_values()))
Beispiel #3
0
    def test_lastal_task_nucl_x_prot(self):
        with TemporaryDirectory() as td:
            with Move(td):
                with TestData('test-protein.fa', td) as prot, \
                     TestData('test-transcript.fa', td) as tr, \
                     TemporaryFile(td) as out:

                    print(os.listdir(td), file=sys.stderr)
                    db_task = tasks.get_lastdb_task(prot, prot,
                                                    self.lastdb_cfg)
                    aln_task = tasks.get_lastal_task(tr,
                                                     prot,
                                                     out,
                                                     self.lastal_cfg,
                                                     translate=True,
                                                     cutoff=None)
                    run_tasks([db_task, aln_task], ['run'])

                    aln = ''.join(open(out).readlines())
                    print(aln, file=sys.stderr)

                    self.assertIn('SPAC212_RecQ_type_DNA_helicase_PROTEIN',
                                  aln)
                    self.assertIn('SPAC212_RecQ_type_DNA_helicase_TRANSCRIPT',
                                  aln)
                    self.assertIn('lambda',
                                  aln,
                                  msg='lambda missing, wrong LAST version?')
Beispiel #4
0
    def test_save(self):
        '''Test that FigureManager saves a plot.
        '''
        with TemporaryDirectory() as td:
            with TemporaryFile(td) as filename:
                with FigureManager(filename=filename + '.pdf') as (fig, ax):
                    ax.plot(range(10), range(10))

                self.assertTrue(os.path.isfile(filename + '.pdf'))
def update_serialized_option_value(shell, option_table, option_name, expr):
    """
    직렬화 된 값 안에서 문자열은 문자열의 길이를 기억하게 되어 있다. 문자열 치환이 직렬화된 값 안에서 일어났다면 문자열의 길이도 변경해야 한다.

    :param shell:
    :param option_table:
    :param option_name:
    :param expr:
    :return:
    """
    def repl(match):
        return 's:%d:\"%s\";' % (len(match.group(2)), match.group(2))

    query = '"SELECT option_value AS \'\' FROM %s WHERE option_name=\'%s\'"' % (
        option_table, option_name)
    cmd = shell.cmd_mysql(mysql_options='-s -r -e {}'.format(query))
    m = local(cmd, capture=True)

    expr = 's:(\d+):"(%s)";' % expr
    replaced = escape_string(re.sub(expr, repl, m.stdout)).decode('utf-8')

    f = TemporaryFile()
    query = 'UPDATE %s SET option_value=\'%s\' WHERE option_name=\'%s\';' % (
        option_table, replaced, option_name)
    f.write(query)
    f.close()

    local(shell.cmd_mysql() + ' < ' + f.name)
Beispiel #6
0
    def test_lastal_task_multithreaded(self):
        with TemporaryDirectory() as td:
            with Move(td):
                with TestData('test-protein.fa', td) as prot, \
                     TestData('pom.50.fa', td) as tr, \
                     TemporaryFile(td) as out_single,\
                     TemporaryFile(td) as out_multi:

                    for n_threads in (3, 4, 5):
                        print(os.listdir(td), file=sys.stderr)

                        db_task = tasks.get_lastdb_task(
                            prot, prot, self.lastdb_cfg)
                        aln_task_single = tasks.get_lastal_task(
                            tr,
                            prot,
                            out_single,
                            self.lastal_cfg,
                            translate=True,
                            cutoff=None)

                        aln_task_multi = tasks.get_lastal_task(
                            tr,
                            prot,
                            out_multi,
                            self.lastal_cfg,
                            translate=True,
                            cutoff=None,
                            n_threads=n_threads)
                        run_tasks([db_task, aln_task_single, aln_task_multi],
                                  ['run'])

                        alns_single = MafParser(out_single).read()
                        alns_multi = MafParser(out_multi).read()

                        self.assertTrue(all(alns_single['E'].sort_values() == \
                                        alns_multi['E'].sort_values()))
Beispiel #7
0
    def test_exception(self):
        '''Test that FigureManager handles internal exceptions properly.
        '''
        with TemporaryDirectory() as td:
            with TemporaryFile(td) as filename:

                # now we test the manager
                try:
                    rregexp = self.assertRaisesRegex
                except AttributeError:
                    rregexp = self.assertRaisesRegexp
                with rregexp(RuntimeError, 'TEST'):
                    with FigureManager(filename=filename) as (fig, ax):
                        raise RuntimeError('TEST')
                self.assertFalse(os.path.isfile(filename),
                                 msg='Should not have saved a file.')
Beispiel #8
0
    def test_hmmscan_task(self):
        with TemporaryDirectory() as td:
            with Move(td):
                with TestData('test-protein.fa', td) as prot, \
                     TestData('test-profile.hmm', td) as hmm, \
                     TemporaryFile(td) as out:

                    db_task = tasks.get_hmmpress_task(hmm, self.hmmpress_cfg)
                    aln_task = tasks.get_hmmscan_task(prot, out, hmm, 1.0, 1,
                                                      self.hmmscan_cfg)
                    run_tasks([db_task, aln_task], ['run'])
                    print(os.listdir(td), file=sys.stderr)
                    aln = open(out).read()
                    print(aln)

                    self.assertEquals(aln.count('accession'), 2)
                    self.assertIn('i-Evalue', aln)
Beispiel #9
0
    def test_lastal_task_uptodate(self):
        with TemporaryDirectory() as td:
            with Move(td):
                with TestData('test-protein.fa', td) as prot, \
                     TemporaryFile(td) as out:
                        
                    print(os.listdir(td), file=sys.stderr)
                    db_task = tasks.get_lastdb_task(prot, prot, self.lastdb_cfg)
                    aln_task = tasks.get_lastal_task(prot, prot, out, False,
                                                     None, 1, self.lastal_cfg)
                    # Run it once
                    run_tasks([db_task, aln_task], ['run'])

                    # Now run again and check the status
                    run_tasks([aln_task], ['run'])
                    status = check_status(aln_task)
                    self.assertEquals(status.status, 'up-to-date')
Beispiel #10
0
    def test_cmscan_task(self):
        with TemporaryDirectory() as td:
            with Move(td):
                with TestData('test-transcript.fa', td) as transcript, \
                     TestData('test-covariance-model.cm', td) as cm, \
                     TemporaryFile(td) as out:
                        
                    db_task = tasks.get_cmpress_task(cm, self.cmpress_cfg)
                    aln_task = tasks.get_cmscan_task(transcript, out, cm, 1.0, 1,
                                                      self.cmscan_cfg)
                    run_tasks([db_task, aln_task], ['run'])
                    print(os.listdir(td), file=sys.stderr)
                    aln = ''.join(open(out).readlines())
                    print(aln, file=sys.stderr)

                    # TODO: better correctness check
                    self.assertEquals(aln.count('accession'), 2)
                    self.assertIn('E-value', aln)
Beispiel #11
0
def update_url(shell, replacement_items, old_string, new_string):
    """
    데이터베이스 안의 내용을 치환.
    """
    if old_string == new_string:
        return

    f = TemporaryFile()
    for item in replacement_items:
        query = "UPDATE `%s` SET `%s` = REPLACE(`%s`, \'%s\', \'%s\');\n" % (
            item['table'], item['field'], item['field'], old_string,
            new_string)
        f.write(query)
    f.close()

    local(shell.cmd_mysql() + ' < ' + f.name)
Beispiel #12
0
    def test_lastal_task_prot_x_prot(self):
        with TemporaryDirectory() as td:
            with Move(td):
                with TestData('test-protein.fa', td) as prot, \
                     TemporaryFile(td) as out:
                        
                    print(os.listdir(td), file=sys.stderr)
                    db_task = tasks.get_lastdb_task(prot, prot, self.lastdb_cfg)
                    aln_task = tasks.get_lastal_task(prot, prot, out, False,
                                                     None, 1, self.lastal_cfg)
                    run_tasks([db_task, aln_task], ['run'])

                    aln = ''.join(open(out).readlines())
                    print(aln, file=sys.stderr)

                    self.assertEquals(
                            aln.count('SPAC212_RecQ_type_DNA_helicase_PROTEIN'),
                            2)
                    self.assertIn('EG2=0', aln)
                    self.assertIn('E=0', aln)
                    self.assertIn('lambda', aln, 
                                  msg='lambda missing, wrong LAST version?')