예제 #1
0
    def test_model_len(self):
        cf = config.Config(self.args)
        with self.assertRaises(RuntimeError) as ctx:
            with self.catch_log():
                cf.model_len
        self.assertEqual(str(ctx.exception), "'model_attc' is not define.")

        self.args.attc_model = 'foo'
        cf = config.Config(self.args)
        with self.assertRaises(IOError) as ctx:
            with self.catch_log():
                cf.model_len
        self.assertEqual(
            str(ctx.exception),
            "Path to model_attc '{}' does not exists".format(
                cf.model_attc_path))

        model_path = os.path.join(os.path.dirname(__file__), 'data',
                                  'Replicons', 'acba.007.p01.13.fst')
        self.args.attc_model = model_path
        cf = config.Config(self.args)
        with self.assertRaises(RuntimeError) as ctx:
            with self.catch_log():
                cf.model_len
        self.assertEqual(
            str(ctx.exception),
            "CLEN not found in '{}', maybe it's not infernal model file".
            format(model_path))

        self.args.attc_model = 'attc_4.cm'
        cf = config.Config(self.args)
        cf._prefix_data = os.path.join(os.path.dirname(__file__), 'data')
        self.assertEqual(cf.model_len, 47)
        # test the model_len cache
        self.assertEqual(cf.model_len, 47)
예제 #2
0
    def test_model_attc_name(self):
        cf = config.Config(self.args)
        with self.assertRaises(RuntimeError) as ctx:
            cf.model_attc_name
        self.assertEqual(str(ctx.exception), "'model_attc' is not define.")

        self.args.attc_model = 'bar'
        cf = config.Config(self.args)
        cf._prefix_data = 'foo'
        self.assertEqual(cf.model_attc_name, 'bar')
        self.args.attc_model = 'bar/baz'
        self.assertEqual(cf.model_attc_name, 'baz')
예제 #3
0
 def test_default_topology(self):
     self.args.circular = True
     self.args.linear = False
     cf = config.Config(self.args)
     self.assertEqual(cf.default_topology, 'circ')
     self.args.circular = False
     self.args.linear = True
     cf = config.Config(self.args)
     self.assertEqual(cf.default_topology, 'lin')
     self.args.circular = False
     self.args.linear = False
     cf = config.Config(self.args)
     self.assertIsNone(cf.default_topology)
     self.args = argparse.Namespace()
     cf = config.Config(self.args)
     self.assertIsNone(cf.default_topology)
예제 #4
0
 def test_log_level(self):
     for v, q, l in [(0, 0, 20), (0, 2, 40), (0, 5, 50), (1, 0, 10),
                     (3, 0, 10), (2, 2, 20)]:
         self.args.verbose = v
         self.args.quiet = q
         cf = config.Config(self.args)
         self.assertEqual(cf.log_level, l)
예제 #5
0
 def test_getattr(self):
     self.args.replicon = 'foo'
     self.args.bar = 'baz'
     cf = config.Config(self.args)
     self.assertEqual(cf.input_seq_path, os.path.abspath('foo'))
     self.assertEqual(cf.bar, 'baz')
     with self.assertRaises(AttributeError) as ctx:
         self.assertEqual(cf.foobar, 'foobar')
     self.assertEqual(str(ctx.exception),
                      "config object has no attribute 'foobar'")
예제 #6
0
 def test_result_dir(self):
     replicon = '../foo.fasta'
     outdir = 'outdir'
     self.args.replicon = replicon
     self.args.outdir = outdir
     cf = config.Config(self.args)
     exp_result_dir = os.path.abspath(
         os.path.join(
             outdir, "Results_Integron_Finder_" +
             os.path.splitext(os.path.split(replicon)[1])[0]))
     self.assertEqual(cf.result_dir, exp_result_dir)
예제 #7
0
 def test_tmp_dir(self):
     replicon_id = 'foo'
     replicon_path = '../{}.fasta'.format(replicon_id)
     outdir = 'outdir'
     self.args.replicon = replicon_path
     self.args.outdir = outdir
     cf = config.Config(self.args)
     exp_result_tmp_dir = os.path.abspath(
         os.path.join(outdir,
                      "Results_Integron_Finder_{}".format(replicon_id),
                      "tmp_{}".format(replicon_id)))
     self.assertEqual(cf.tmp_dir(replicon_id), exp_result_tmp_dir)
예제 #8
0
 def test_resultdir_not_writable(self):
     replicon_filename = 'acba.007.p01.13'
     args = argparse.Namespace()
     args.replicon = self.find_data(os.path.join('Replicons', '{}.fst'.format(replicon_filename)))
     args.outdir = self.out_dir
     cf = config.Config(args)
     os.mkdir(cf.result_dir, mode=0o500)
     command = "integron_finder --outdir {out_dir} {replicon}".format(out_dir=self.out_dir,
                                                                      replicon=self.find_data(
                                                                          os.path.join('Replicons',
                                                                                       '{}.fst'.format(replicon_filename))
                                                                      )
                                                                      )
     with self.assertRaises(PermissionError) as ctx:
         with self.catch_io(out=True):
             # in case the error is not raised
             # anyway do not want to mess up the test output
             # I cannot catch log because loggers are reinitialized in main
             # I need to catch stdout as log are write on
             main(command.split()[1:])
     err_msg = "result dir '{}' already exists and is not writable".format(self.out_dir)
     self.assertEqual(err_msg, str(ctx.exception))
예제 #9
0
 def test_input_dir(self):
     self.args.replicon = '../foo.fasta'
     cf = config.Config(self.args)
     self.assertEqual(cf.input_dir,
                      os.path.split(os.path.abspath('../foo'))[0])
예제 #10
0
 def test_replicon_path(self):
     self.args.replicon = '../foo'
     cf = config.Config(self.args)
     self.assertEqual(cf.input_seq_path, os.path.abspath('../foo'))
예제 #11
0
 def test_func_annot_path(self):
     cf = config.Config(self.args)
     cf._prefix_data = 'foo'
     self.assertEqual(cf.func_annot_path,
                      os.path.join('foo', 'Functional_annotation'))
예제 #12
0
 def test_model_phage_int(self):
     cf = config.Config(self.args)
     cf._prefix_data = 'foo'
     self.assertEqual(cf.model_phage_int,
                      os.path.join('foo', 'Models', 'phage-int.hmm'))
예제 #13
0
 def test_model_integrase(self):
     cf = config.Config(self.args)
     cf._prefix_data = 'foo'
     self.assertEqual(
         cf.model_integrase,
         os.path.join('foo', 'Models', 'integron_integrase.hmm'))
예제 #14
0
 def test_model_dir(self):
     cf = config.Config(self.args)
     cf._prefix_data = 'foo'
     self.assertEqual(cf.model_dir, os.path.join('foo', 'Models'))