def run(self):
        'It runs the analysis.'
        inputs, output_dirs = self._get_inputs_and_prepare_outputs()
        db_dir = output_dirs['db_dir']
        result_dir = output_dirs['result']
        blast_settings = self._project_settings['blast']

        go_settings = self._project_settings['Annotation']['go_annotation']

        go_database = go_settings['blast_database']
        create_dat = go_settings['create_dat_file']
        java_memory = go_settings['java_memory']
        prop_fpath = go_settings['b2g_properties_file']
        if not prop_fpath:
            msg = 'Blast2go properties file path not given in backbone.conf'
            raise ValueError(msg)

        blast2go_path = go_settings['blast2go_path']
        if not blast2go_path:
            msg = 'Path to blast2go binary not given in backbone.conf'
            raise ValueError(msg)

        blast2go = {}
        for input_ in inputs['input']:
            input_fpath = input_.last_version
            annot_fpath = join(result_dir, input_.basename + '.b2g.annot')
            if not exists(annot_fpath):
                go_blast_settings = blast_settings[go_database]
                blast = self._get_b2g_blast(input_fpath, go_blast_settings)
                if create_dat:
                    dat_fpath = join(result_dir, input_.basename + '.b2g.dat')
                else:
                    dat_fpath = None

                java_conf = {'java_memory': java_memory}
                b2gpipe_runner(blast, annot_fpath=annot_fpath,
                               b2gpipe_bin=blast2go_path, prop_fpath=prop_fpath,
                               dat_fpath=dat_fpath, java_conf=java_conf,
                               )
                blast.close()

            blast2go[input_fpath] = annot_fpath

        # prepare pipeline
        pipeline = [annotate_gos]
        configuration = {}

        for input_ in  inputs['input']:
            input_fpath = input_.last_version
            step_config = {'annot_fpath': blast2go[input_fpath]}
            configuration[input_.basename] = {'annotate_gos': step_config}

        result = self._run_annotation(pipeline=pipeline,
                                      configuration=configuration,
                                      inputs=inputs, output_dir=db_dir)

        return result
Exemple #2
0
    def test_go_annotator():
        'It test the go annotator'
        blast = open(os.path.join(TEST_DATA_DIR, 'blastResult.xml'))
        prop_fpath = os.path.join(TEST_DATA_DIR, 'b2gPipe.properties')
        b2gpipe_bin = os.path.join(guess_jar_dir('blast2go.jar'),
                                   'blast2go.jar')
        fhand, annot_fpath = tempfile.mkstemp()
        os.close(fhand)
        if not b2gpipe_bin:
            print "Do not run b2gppe tests, blast2go jar file not found "
            return
        b2gpipe_runner(blast, annot_fpath, b2gpipe_bin, prop_fpath=prop_fpath)
        blast2go = annot_fpath
        go_annotator = create_go_annotator(blast2go)
        seq = SeqWithQuality(name='seq1', seq=Seq('aaaa'))

        go_annotator(seq)
        assert 'GO:0009853' in seq.annotations['GOs']

        os.remove(annot_fpath)
    def test_run_b2g4pipe():
        'It test the runner of b2g4pipe'

        blast = open(os.path.join(TEST_DATA_DIR, 'blast2.xml'))
        fhand, annot_fpath = tempfile.mkstemp()
        os.close(fhand)
        fhand, dat_fpath = tempfile.mkstemp()
        os.close(fhand)
        prop_fpath = os.path.join(TEST_DATA_DIR, 'b2gPipe.properties')
        b2gpipe_bin = os.path.join(guess_jar_dir('blast2go.jar'),
                                   'blast2go.jar')
        if not b2gpipe_bin:
            print "Do not run b2gppe tests, blast2go jar file not found "
            return
        b2gpipe_runner(blast, annot_fpath, b2gpipe_bin, prop_fpath, dat_fpath)

        assert os.path.exists(annot_fpath)
        assert os.path.exists(dat_fpath)
        os.remove(annot_fpath)
        os.remove(dat_fpath)