def setUp(self):
        l = logging.getLogger()
        l.manager.loggerDict.clear()

        #add only one handler to the macsypy logger
        from macsypy.gene import _log
        macsy_log = _log.parent
        log_file = 'NUL' if platform.system() == 'Windows' else '/dev/null'
        log_handler = logging.FileHandler(log_file)
        macsy_log.addHandler(log_handler)

        self.cfg = Config(sequence_db=os.path.join(self._data_dir, "base",
                                                   "test_base.fa"),
                          db_type="gembase",
                          hmmer_exe="",
                          e_value_res=1,
                          i_evalue_sel=0.5,
                          def_dir=os.path.join(self._data_dir, 'DEF'),
                          res_search_dir=tempfile.gettempdir(),
                          res_search_suffix="",
                          profile_dir=os.path.join(self._data_dir, 'profiles'),
                          profile_suffix=".hmm",
                          res_extract_suffix="",
                          log_level=30,
                          log_file=log_file)
        self.profile_registry = ProfilesRegistry(self.cfg)
 def setUp(self):
     self.cfg = Config( sequence_db = os.path.join(self._data_dir, "base", "test_base.fa"),
                        db_type = "gembase",
                        hmmer_exe = "",
                        e_value_res = 1,
                        i_evalue_sel = 0.5,
                        def_dir = os.path.join(self._data_dir, 'DEF'),
                        res_search_dir = "/tmp",
                        res_search_suffix = "",
                        profile_dir = os.path.join(self._data_dir, 'profiles'),
                        profile_suffix = ".hmm",
                        res_extract_suffix = "",
                        log_level = 30,
                        log_file = '/dev/null'
                        )
     self.profile_registry = ProfilesRegistry(self.cfg)
Example #3
0
 def setUp(self):
     l = logging.getLogger()
     l.manager.loggerDict.clear()
     
     #add only one handler to the macsypy logger
     from macsypy.gene import _log
     macsy_log = _log.parent
     log_file = 'NUL' if platform.system() == 'Windows' else '/dev/null'
     log_handler = logging.FileHandler(log_file)
     macsy_log.addHandler(log_handler)
     
     self.cfg = Config( hmmer_exe = "hmmsearch",
                        sequence_db = os.path.join(self._data_dir, "base", "test_base.fa"),
                        db_type = "gembase",
                        e_value_res = 1,
                        i_evalue_sel = 0.5,
                        def_dir = os.path.join(self._data_dir, 'DEF'),
                        res_search_dir = tempfile.gettempdir(),
                        res_search_suffix = ".search_hmm.out",
                        profile_dir = os.path.join(self._data_dir, 'profiles'),
                        profile_suffix = ".hmm",
                        res_extract_suffix = "",
                        log_level = 30,
                        log_file = log_file
                        )
     self.profile_registry = ProfilesRegistry(self.cfg)
class Test(unittest.TestCase):
    
    _data_dir = os.path.join(os.path.dirname(__file__), "datatest")

    def setUp(self):
        l = logging.getLogger()
        l.manager.loggerDict.clear()
        self.cfg = Config( sequence_db = os.path.join(self._data_dir, "base", "test_base.fa"),
                           db_type = "gembase",
                           hmmer_exe = "",
                           e_value_res = 1,
                           i_evalue_sel = 0.5,
                           def_dir = os.path.join(self._data_dir, 'DEF'),
                           res_search_dir = tempfile.gettempdir(),
                           res_search_suffix = "",
                           profile_dir = os.path.join(self._data_dir, 'profiles'),
                           profile_suffix = ".hmm",
                           res_extract_suffix = "",
                           log_level = 30,
                           log_file = 'NUL' if platform.system() == 'Windows' else '/dev/null'
                           )
        self.profile_registry = ProfilesRegistry(self.cfg)

    def tearDown(self):
        # close loggers filehandles, so they don't block file deletion
        # in shutil.rmtree calls in Windows
        logging.shutdown()
        l = logging.getLogger()
        l.manager.loggerDict.clear()
        profile_factory._profiles = {}
        try:
            shutil.rmtree(self.cfg.working_dir)
        except:
            pass

    def test_get_profile(self):
        system_foo = System(self.cfg, "foo", 10)
        gene_name = 'sctJ_FLG'
        gene = Gene(self.cfg, gene_name, system_foo, self.profile_registry)
        profile = profile_factory.get_profile(gene, self.cfg, self.profile_registry )
        self.assertTrue( isinstance( profile, Profile ))
        self.assertEqual( profile.gene.name, gene_name )

    def test_get_uniq_object(self):
        system_foo = System(self.cfg, "foo", 10)
        gene = Gene(self.cfg, 'sctJ_FLG', system_foo, self.profile_registry)
        path = self.profile_registry.get('sctJ_FLG')
        profile1 = profile_factory.get_profile(gene, self.cfg, path )
        profile2 = profile_factory.get_profile(gene, self.cfg, path)
        self.assertEqual( profile1, profile2 )

    def test_unknow_profile(self):
        system_foo = System(self.cfg, "foo", 10)
        gene = Gene(self.cfg, 'sctJ_FLG', system_foo, self.profile_registry)
        gene.name = "foo"
        self.assertRaises(MacsypyError, profile_factory.get_profile, gene, self.cfg, self.profile_registry)
 def setUp(self):
     self.cfg = Config( hmmer_exe = "hmmsearch",
                        sequence_db = os.path.join(self._data_dir, "base", "test_base.fa"),
                        db_type = "gembase",
                        e_value_res = 1,
                        i_evalue_sel = 0.5,
                        def_dir = os.path.join(self._data_dir, 'DEF'),
                        res_search_dir = '/tmp',
                        res_search_suffix = ".search_hmm.out",
                        profile_dir = os.path.join(self._data_dir, 'profiles'),
                        profile_suffix = ".hmm",
                        res_extract_suffix = "",
                        log_level = 30,
                        log_file = '/dev/null'
                        )
     self.profile_registry = ProfilesRegistry(self.cfg)
class Test(unittest.TestCase):
    
    _data_dir = os.path.join(os.path.dirname(__file__), "datatest")

    def setUp(self):
        self.cfg = Config( sequence_db = os.path.join(self._data_dir, "base", "test_base.fa"),
                           db_type = "gembase",
                           hmmer_exe = "",
                           e_value_res = 1,
                           i_evalue_sel = 0.5,
                           def_dir = os.path.join(self._data_dir, 'DEF'),
                           res_search_dir = "/tmp",
                           res_search_suffix = "",
                           profile_dir = os.path.join(self._data_dir, 'profiles'),
                           profile_suffix = ".hmm",
                           res_extract_suffix = "",
                           log_level = 30,
                           log_file = '/dev/null'
                           )
        self.profile_registry = ProfilesRegistry(self.cfg)

    def tearDown(self):
        profile_factory._profiles = {}
        shutil.rmtree(self.cfg.working_dir)

    def test_get_profile(self):
        system_foo = System(self.cfg, "foo", 10)
        gene_name = 'sctJ_FLG'
        gene = Gene(self.cfg, gene_name, system_foo, self.profile_registry)
        profile = profile_factory.get_profile(gene, self.cfg, self.profile_registry )
        self.assertTrue( isinstance( profile, Profile ))
        self.assertEqual( profile.gene.name, gene_name )

    def test_get_uniq_object(self):
        system_foo = System(self.cfg, "foo", 10)
        gene = Gene(self.cfg, 'sctJ_FLG', system_foo, self.profile_registry)
        path = self.profile_registry.get('sctJ_FLG')
        profile1 = profile_factory.get_profile(gene, self.cfg, path )
        profile2 = profile_factory.get_profile(gene, self.cfg, path)
        self.assertEqual( profile1, profile2 )

    def test_unknow_profile(self):
        system_foo = System(self.cfg, "foo", 10)
        gene = Gene(self.cfg, 'sctJ_FLG', system_foo, self.profile_registry)
        gene.name = "foo"
        self.assertRaises(MacsypyError, profile_factory.get_profile, gene, self.cfg, self.profile_registry)
Example #7
0
 def setUp(self):
     l = logging.getLogger()
     l.manager.loggerDict.clear()
     self.cfg = Config( hmmer_exe = "hmmsearch",
                        sequence_db = os.path.join(self._data_dir, "base", "test_base.fa"),
                        db_type = "gembase",
                        e_value_res = 1,
                        i_evalue_sel = 0.5,
                        def_dir = os.path.join(self._data_dir, 'DEF'),
                        res_search_dir = tempfile.gettempdir(),
                        res_search_suffix = ".search_hmm.out",
                        profile_dir = os.path.join(self._data_dir, 'profiles'),
                        profile_suffix = ".hmm",
                        res_extract_suffix = "",
                        log_level = 30,
                        log_file = 'NUL' if platform.system() == 'Windows' else '/dev/null'
                        )
     self.profile_registry = ProfilesRegistry(self.cfg)
Example #8
0
    def setUp(self):
        self.cfg = Config(hmmer_exe="hmmsearch",
                          sequence_db=os.path.join(self._data_dir, "base",
                                                   "test_base.fa"),
                          db_type="gembase",
                          e_value_res=1,
                          i_evalue_sel=0.5,
                          def_dir=os.path.join(self._data_dir, 'DEF'),
                          res_search_dir='/tmp',
                          res_search_suffix=".search_hmm.out",
                          profile_dir=os.path.join(self._data_dir, 'profiles'),
                          profile_suffix=".hmm",
                          res_extract_suffix="",
                          log_level=30,
                          log_file='/dev/null')
        shutil.copy(self.cfg.sequence_db, self.cfg.working_dir)
        self.cfg.options['sequence_db'] = os.path.join(
            self.cfg.working_dir, os.path.basename(self.cfg.sequence_db))
        self.profile_registry = ProfilesRegistry(self.cfg)

        idx = Indexes(self.cfg)
        idx._build_my_indexes()
Example #9
0
class Test(unittest.TestCase):

    _data_dir = os.path.join(os.path.dirname(__file__), "datatest")

    def setUp(self):
        l = logging.getLogger()
        l.manager.loggerDict.clear()
        self.cfg = Config( hmmer_exe = "hmmsearch",
                           sequence_db = os.path.join(self._data_dir, "base", "test_base.fa"),
                           db_type = "gembase",
                           e_value_res = 1,
                           i_evalue_sel = 0.5,
                           def_dir = os.path.join(self._data_dir, 'DEF'),
                           res_search_dir = tempfile.gettempdir(),
                           res_search_suffix = ".search_hmm.out",
                           profile_dir = os.path.join(self._data_dir, 'profiles'),
                           profile_suffix = ".hmm",
                           res_extract_suffix = "",
                           log_level = 30,
                           log_file = 'NUL' if platform.system() == 'Windows' else '/dev/null'
                           )
        self.profile_registry = ProfilesRegistry(self.cfg)


    def tearDown(self):
        # close loggers filehandles, so they don't block file deletion
        # in shutil.rmtree calls in Windows
        logging.shutdown
        l = logging.getLogger()
        l.manager.loggerDict.clear()
        try:
            shutil.rmtree(self.cfg.working_dir)
        except:
            pass


    def test_len(self):
        system = System(self.cfg, "T2SS", 10)
        gene = Gene(self.cfg, "abc", system, self.profile_registry)
        path = self.profile_registry.get("abc")
        profile = Profile(gene, self.cfg, path)
        self.assertEqual(len(profile), 501)


    def test_str(self):
        system = System(self.cfg, "T2SS", 10)
        gene = Gene(self.cfg, "abc", system, self.profile_registry)
        path = self.profile_registry.get("abc")
        profile = Profile(gene, self.cfg, path)
        s = "%s : %s" % (gene.name, path)
        self.assertEqual(str(profile), s)

    @unittest.skipIf( not which('hmmsearch'), 'hmmsearch not found in PATH')
    def test_execute(self):
        system = System(self.cfg, "T2SS", 10)
        gene = Gene(self.cfg, "abc", system, self.profile_registry)
        path = self.profile_registry.get("abc")
        profile = Profile(gene, self.cfg, path)
        report = profile.execute()
        hmmer_raw_out = profile.hmm_raw_output
        with open(hmmer_raw_out, 'r') as hmmer_raw_out_file:
            first_l = hmmer_raw_out_file.readline()
            #a hmmsearch output file has been produced
            self.assertTrue(first_l.startswith("# hmmsearch :: search profile(s) against a sequence database"))
            for i in range(5):
                #skip 4 lines
                l  =  hmmer_raw_out_file.readline()
            #a hmmsearch used the abc profile line should become with: "# query HMM file:"
            path = os.path.join(self.cfg.profile_dir, gene.name + self.cfg.profile_suffix)
            self.assertTrue(l.find(path) != -1)

    def test_execute_unknown_binary(self):
        self.cfg.options['hmmer_exe'] = "Nimportnaoik"
        system = System(self.cfg, "T2SS", 10)
        gene = Gene(self.cfg, "abc", system, self.profile_registry)
        path = self.profile_registry.get("abc")
        profile = Profile(gene, self.cfg, path)
        self.assertRaises(RuntimeError, profile.execute)
class Test(unittest.TestCase):

    _data_dir = os.path.join(os.path.dirname(__file__), "datatest")

    def setUp(self):
        l = logging.getLogger()
        l.manager.loggerDict.clear()

        #add only one handler to the macsypy logger
        from macsypy.gene import _log
        macsy_log = _log.parent
        log_file = 'NUL' if platform.system() == 'Windows' else '/dev/null'
        log_handler = logging.FileHandler(log_file)
        macsy_log.addHandler(log_handler)

        self.cfg = Config(sequence_db=os.path.join(self._data_dir, "base",
                                                   "test_base.fa"),
                          db_type="gembase",
                          hmmer_exe="",
                          e_value_res=1,
                          i_evalue_sel=0.5,
                          def_dir=os.path.join(self._data_dir, 'DEF'),
                          res_search_dir=tempfile.gettempdir(),
                          res_search_suffix="",
                          profile_dir=os.path.join(self._data_dir, 'profiles'),
                          profile_suffix=".hmm",
                          res_extract_suffix="",
                          log_level=30,
                          log_file=log_file)
        self.profile_registry = ProfilesRegistry(self.cfg)

    def tearDown(self):
        # close loggers filehandles, so they don't block file deletion
        # in shutil.rmtree calls in Windows
        logging.shutdown()
        l = logging.getLogger()
        l.manager.loggerDict.clear()
        profile_factory._profiles = {}
        try:
            shutil.rmtree(self.cfg.working_dir)
        except:
            pass

    def test_get_profile(self):
        system_foo = System(self.cfg, "foo", 10)
        gene_name = 'sctJ_FLG'
        gene = Gene(self.cfg, gene_name, system_foo, self.profile_registry)
        profile = profile_factory.get_profile(gene, self.cfg,
                                              self.profile_registry)
        self.assertTrue(isinstance(profile, Profile))
        self.assertEqual(profile.gene.name, gene_name)

    def test_get_uniq_object(self):
        system_foo = System(self.cfg, "foo", 10)
        gene = Gene(self.cfg, 'sctJ_FLG', system_foo, self.profile_registry)
        path = self.profile_registry.get('sctJ_FLG')
        profile1 = profile_factory.get_profile(gene, self.cfg, path)
        profile2 = profile_factory.get_profile(gene, self.cfg, path)
        self.assertEqual(profile1, profile2)

    def test_unknow_profile(self):
        system_foo = System(self.cfg, "foo", 10)
        gene = Gene(self.cfg, 'sctJ_FLG', system_foo, self.profile_registry)
        gene.name = "foo"
        self.assertRaises(MacsypyError, profile_factory.get_profile, gene,
                          self.cfg, self.profile_registry)
Example #11
0
class Test(unittest.TestCase):

    _data_dir = os.path.join(os.path.dirname(__file__), "datatest")

    def setUp(self):
        l = logging.getLogger()
        l.manager.loggerDict.clear()

        #add only one handler to the macsypy logger
        from macsypy.gene import _log
        macsy_log = _log.parent
        log_file = 'NUL' if platform.system() == 'Windows' else '/dev/null'
        log_handler = logging.FileHandler(log_file)
        macsy_log.addHandler(log_handler)

        self.cfg = Config(hmmer_exe="hmmsearch",
                          sequence_db=os.path.join(self._data_dir, "base",
                                                   "test_base.fa"),
                          db_type="gembase",
                          e_value_res=1,
                          i_evalue_sel=0.5,
                          def_dir=os.path.join(self._data_dir, 'DEF'),
                          res_search_dir=tempfile.gettempdir(),
                          res_search_suffix=".search_hmm.out",
                          profile_dir=os.path.join(self._data_dir, 'profiles'),
                          profile_suffix=".hmm",
                          res_extract_suffix="",
                          log_level=30,
                          log_file=log_file)
        self.profile_registry = ProfilesRegistry(self.cfg)

    def tearDown(self):
        # close loggers filehandles, so they don't block file deletion
        # in shutil.rmtree calls in Windows
        logging.shutdown
        l = logging.getLogger()
        l.manager.loggerDict.clear()
        try:
            shutil.rmtree(self.cfg.working_dir)
        except:
            pass

    def test_len(self):
        system = System(self.cfg, "T2SS", 10)
        gene = Gene(self.cfg, "abc", system, self.profile_registry)
        path = self.profile_registry.get("abc")
        profile = Profile(gene, self.cfg, path)
        self.assertEqual(len(profile), 501)

    def test_str(self):
        system = System(self.cfg, "T2SS", 10)
        gene = Gene(self.cfg, "abc", system, self.profile_registry)
        path = self.profile_registry.get("abc")
        profile = Profile(gene, self.cfg, path)
        s = "{0} : {1}".format(gene.name, path)
        self.assertEqual(str(profile), s)

    @unittest.skipIf(not which('hmmsearch'), 'hmmsearch not found in PATH')
    def test_execute(self):
        system = System(self.cfg, "T2SS", 10)
        gene = Gene(self.cfg, "abc", system, self.profile_registry)
        path = self.profile_registry.get("abc")
        profile = Profile(gene, self.cfg, path)
        report = profile.execute()
        hmmer_raw_out = profile.hmm_raw_output
        with open(hmmer_raw_out, 'r') as hmmer_raw_out_file:
            first_l = hmmer_raw_out_file.readline()
            #a hmmsearch output file has been produced
            self.assertTrue(
                first_l.startswith(
                    "# hmmsearch :: search profile(s) against a sequence database"
                ))
            for i in range(5):
                #skip 4 lines
                l = hmmer_raw_out_file.readline()
            #a hmmsearch used the abc profile line should become with: "# query HMM file:"
            path = os.path.join(self.cfg.profile_dir,
                                gene.name + self.cfg.profile_suffix)
            self.assertTrue(l.find(path) != -1)

    def test_execute_unknown_binary(self):
        self.cfg.options['hmmer_exe'] = "Nimportnaoik"
        system = System(self.cfg, "T2SS", 10)
        gene = Gene(self.cfg, "abc", system, self.profile_registry)
        path = self.profile_registry.get("abc")
        profile = Profile(gene, self.cfg, path)
        self.assertRaises(RuntimeError, profile.execute)
Example #12
0
class Test(unittest.TestCase):

    _data_dir = os.path.join(os.path.dirname(__file__), "datatest")

    def setUp(self):
        self.cfg = Config(hmmer_exe="hmmsearch",
                          sequence_db=os.path.join(self._data_dir, "base",
                                                   "test_base.fa"),
                          db_type="gembase",
                          e_value_res=1,
                          i_evalue_sel=0.5,
                          def_dir=os.path.join(self._data_dir, 'DEF'),
                          res_search_dir='/tmp',
                          res_search_suffix=".search_hmm.out",
                          profile_dir=os.path.join(self._data_dir, 'profiles'),
                          profile_suffix=".hmm",
                          res_extract_suffix="",
                          log_level=30,
                          log_file='/dev/null')
        self.profile_registry = ProfilesRegistry(self.cfg)

    def tearDown(self):
        shutil.rmtree(self.cfg.working_dir)

    def test_len(self):
        system = System(self.cfg, "T2SS", 10)
        gene = Gene(self.cfg, "abc", system, self.profile_registry)
        path = self.profile_registry.get("abc")
        profile = Profile(gene, self.cfg, path)
        self.assertEqual(len(profile), 501)

    def test_str(self):
        system = System(self.cfg, "T2SS", 10)
        gene = Gene(self.cfg, "abc", system, self.profile_registry)
        path = self.profile_registry.get("abc")
        profile = Profile(gene, self.cfg, path)
        s = "%s : %s" % (gene.name, path)
        self.assertEqual(str(profile), s)

    @unittest.skipIf(not which('hmmsearch'), 'hmmsearch not found in PATH')
    def test_execute(self):
        system = System(self.cfg, "T2SS", 10)
        gene = Gene(self.cfg, "abc", system, self.profile_registry)
        path = self.profile_registry.get("abc")
        profile = Profile(gene, self.cfg, path)
        report = profile.execute()
        hmmer_raw_out = profile.hmm_raw_output
        with open(hmmer_raw_out, 'r') as hmmer_raw_out_file:
            first_l = hmmer_raw_out_file.readline()
            #a hmmsearch output file has been produced
            self.assertTrue(
                first_l.startswith(
                    "# hmmsearch :: search profile(s) against a sequence database"
                ))
            for i in range(5):
                #skip 4 lines
                l = hmmer_raw_out_file.readline()
            #a hmmsearch used the abc profile line should become with: "# query HMM file:"
            path = os.path.join(self.cfg.profile_dir,
                                gene.name + self.cfg.profile_suffix)
            self.assertTrue(l.find(path) != -1)

    def test_execute_unknown_binary(self):
        self.cfg.options['hmmer_exe'] = "Nimportnaoik"
        system = System(self.cfg, "T2SS", 10)
        gene = Gene(self.cfg, "abc", system, self.profile_registry)
        path = self.profile_registry.get("abc")
        profile = Profile(gene, self.cfg, path)
        self.assertRaises(RuntimeError, profile.execute)