Example #1
0
    def test_get_gene(self):
        system = System(self.cfg, "foo", 10)
        gene_name = 'sctJ_FLG'
        gene = Gene(self.cfg, gene_name, system, self.profile_registry)
        for meth in (system.add_forbidden_gene, system.add_accessory_gene, system.add_mandatory_gene):
            system._mandatory_genes = []
            system._accessory_genes = []
            system._forbidden_genes = []
            meth(gene)
            self.assertEqual(gene, system.get_gene(gene_name))

        self.assertRaises(KeyError, system.get_gene, 'bar')

        homolog_name = 'sctJ'
        gene_homolog = Gene(self.cfg, homolog_name, system, self.profile_registry)
        homolog = Homolog(gene_homolog, gene)
        gene.add_homolog(homolog)
        for meth in (system.add_forbidden_gene, system.add_accessory_gene, system.add_mandatory_gene):
            system._mandatory_genes = []
            system._accessory_genes = []
            system._forbidden_genes = []
            meth(gene)
            self.assertEqual(homolog, system.get_gene(homolog_name))

        analog_name = 'sctC'
        gene_analog = Gene(self.cfg, analog_name, system, self.profile_registry)
        analog = Analog(gene_analog, gene)
        gene.add_analog(analog)
        for meth in (system.add_forbidden_gene, system.add_accessory_gene, system.add_mandatory_gene):
            system._mandatory_genes = []
            system._accessory_genes = []
            system._forbidden_genes = []
            meth(gene)
            self.assertEqual(analog, system.get_gene(analog_name))
 def test_add_homolog(self):
     system_foo = System(self.cfg, "foo", 10)
     system_bar = System(self.cfg, "bar", 10)
     gene = Gene(self.cfg, 'sctJ_FLG', system_foo, self.profile_registry)
     gene_ref = Gene(self.cfg, 'sctJ', system_bar, self.profile_registry)
     homolog = Homolog(self.cfg, gene, gene_ref)
     gene.add_homolog( homolog )
     self.assertEqual(len( gene.homologs), 1)
     self.assertEqual(gene.homologs[0], homolog)
    def test_str(self):
        """
        """
        system_foo = System(self.cfg, "foo", 10)
        gene = Gene(self.cfg, 'sctJ_FLG', system_foo, self.profile_registry)
        system_bar = System(self.cfg, "bar", 20)
        gene_homolog = Gene(self.cfg, 'sctJ', system_bar, self.profile_registry)
        homolog = Homolog( gene_homolog, gene, self.cfg)
        gene.add_homolog( homolog )
        s = """name : sctJ_FLG
inter_gene_max_space: 10
    homologs: sctJ"""
        self.assertEqual( str(gene) , s )
Example #4
0
    def test_str(self):
        system = System(self.cfg, "T2SS", 10)
        gene_name = "gspD"
        gene = Gene(self.cfg, "gspD", system, self.profile_registry)
        hit_prop = {
            'id': "PSAE001c01_006940",
            'hit_seq_len': 803,
            'replicon_name': "PSAE001c01",
            'position': 694,
            'i_eval': float(1.2e-234),
            'score': float(779.2),
            'gene_name': gene.name,
            'system_name': system.name,
            'profil_coverage': float(1.0),
            'sequence_coverage': float(638.000000),
            'begin': 104,
            'end': 741
        }

        hit = Hit(gene, system, hit_prop['id'], hit_prop['hit_seq_len'],
                  hit_prop['replicon_name'], hit_prop['position'],
                  hit_prop['i_eval'], hit_prop['score'],
                  hit_prop['profil_coverage'], hit_prop['sequence_coverage'],
                  hit_prop['begin'], hit_prop['end'])
        s = "%(id)s\t%(replicon_name)s\t%(position)d\t%(hit_seq_len)d\t%(gene_name)s\t%(system_name)s\t%(i_eval)s\t%(score)s\t%(profil_coverage)f\t%(sequence_coverage)f\t%(begin)d\t%(end)d\n" % hit_prop
        self.assertEqual(s, str(hit))
Example #5
0
 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)
Example #6
0
 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 #7
0
    def test_get_gene_ref(self):
        system = System(self.cfg, "foo", 10)
        gene_name = 'sctJ_FLG'
        gene_ref = Gene(self.cfg, gene_name, system, self.profile_registry)
        homolog_name = 'sctJ'
        gene_homolg = Gene(self.cfg, homolog_name, system, self.profile_registry)
        homolog = Homolog(gene_homolg, gene_ref)
        gene_ref.add_homolog(homolog)

        for meth in (system.add_forbidden_gene, system.add_accessory_gene, system.add_mandatory_gene):
            system._mandatory_genes = []
            system._accessory_genes = []
            system._forbidden_genes = []
            meth(gene_ref)
            self.assertEqual(gene_ref, system.get_gene_ref(homolog))
        self.assertIsNone(system.get_gene_ref(gene_ref))
        gene_ukn = Gene(self.cfg, 'abc', system, self.profile_registry)
        self.assertRaises(KeyError, system.get_gene_ref, gene_ukn)
 def test_get_homologs(self):
     system_foo = System(self.cfg, "foo", 10)
     system_bar = System(self.cfg, "bar", 10)
     gene = Gene(self.cfg, 'sctN', system_foo, self.profile_registry)
     sctJ_FLG = Gene(self.cfg, 'sctJ_FLG', system_foo, self.profile_registry)
     sctJ = Gene(self.cfg, 'sctJ', system_bar, self.profile_registry)
     homolog_1 = Homolog(sctJ_FLG, gene)
     gene.add_homolog(homolog_1)
     homolog_2 = Homolog(sctJ, gene)
     gene.add_homolog(homolog_2)
     self.assertEqual(gene.get_homologs(), [homolog_1, homolog_2] )
 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_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)