Esempio n. 1
0
 def test_add_hit(self):
     self.th.add_hit('a', 'b', 0.1, 20)
     self.th.add_hit('a', 'c', 0.1, 10)
     self.th.add_hit('x', 'y', 0.1, 20)
     self.th.add_hit('x', 'z', 0.0, 20)
     expected = {('a', Hit('a', 'b', 0.1, 20)),
                 ('x', Hit('x', 'z', 0.0, 20))}
     self.assertSetEqual(expected, set(self.th.iter_hits()))
Esempio n. 2
0
 def test_add_hit(self):
     self.th.add_hit('a', 'b', 0.1, 10)
     self.th.add_hit('a', 'b', 0.1, 20)
     self.th.add_hit('a', 'c', 0.1, 10)
     self.th.add_hit('x', 'y', 0.1, 10)
     self.th.add_hit('x', 'y', 0.2, 10)
     self.assertEqual(Hit('a', 'b', 0.1, 20), self.th.get_top_hit('a'))
     self.assertEqual(Hit('x', 'y', 0.1, 10), self.th.get_top_hit('x'))
Esempio n. 3
0
 def test_ordering(self):
     expected = [
         Hit('a', 'a', 0.05, 50),
         Hit('a', 'b', 0.99, 50),
         Hit('a', 'x', 0.01, 10),
         Hit('a', 'y', 0.01, 10)
     ]
     test = [expected[2], expected[1], expected[0], expected[3]]
     self.assertListEqual(expected, sorted(test, reverse=True))
Esempio n. 4
0
 def test_read(self):
     with open(self.path, 'w') as fh:
         fh.write('Gene Id Top hits (Family id,e-value,bitscore)\n')
         fh.write('a\tc,0.1,20;b,0.1,10\n')
         fh.write('x\ty,0.1,10\n')
     self.th.read()
     self.assertEqual(Hit('a', 'c', 0.1, 20), self.th.get_hmm_hit('a', 'c'))
     self.assertEqual(Hit('a', 'b', 0.1, 10), self.th.get_hmm_hit('a', 'b'))
     self.assertEqual(Hit('x', 'y', 0.1, 10), self.th.get_hmm_hit('x', 'y'))
Esempio n. 5
0
 def test___hash__(self):
     self.assertEqual(hash(Hit('a', 'b', 0.1, 10)),
                      hash(Hit('a', 'b', 0.1, 10)))
     self.assertNotEqual(hash(Hit('a', 'b', 0.1, 10)),
                         hash(Hit('a', 'b', 0.1, 20)))
     self.assertNotEqual(hash(Hit('a', 'b', 0.1, 10)),
                         hash(Hit('a', 'b', 0.2, 10)))
     self.assertNotEqual(hash(Hit('a', 'b', 0.1, 10)),
                         hash(Hit('a', 'c', 0.1, 10)))
     self.assertNotEqual(hash(Hit('a', 'b', 0.1, 10)),
                         hash(Hit('c', 'b', 0.1, 10)))
Esempio n. 6
0
    def test__merge_hit_files(self):
        pfam_th = TopHitPfamFile(os.path.join(self.dir_tmp), 'genome_1')
        pfam_th.add_hit('gene_a', 'PFAM_1', 0.05, 100)
        pfam_th.add_hit('gene_b', 'PFAM_2', 0.05, 200)
        pfam_th.add_hit('gene_c', 'PFAM_2', 0.05, 100)

        tigr_th = TopHitTigrFile(os.path.join(self.dir_tmp), 'genome_1')
        tigr_th.add_hit('gene_x', 'TIGR_1', 0.05, 100)

        expected = {'TIGR_1': [Hit('gene_x', 'TIGR_1', 0.05, 100)],
                    'PFAM_1': [Hit('gene_a', 'PFAM_1', 0.05, 100)],
                    'PFAM_2': [Hit('gene_b', 'PFAM_2', 0.05, 200),
                               Hit('gene_c', 'PFAM_2', 0.05, 100)]}
        self.assertDictEqual(expected, CopyNumberFile._merge_hit_files(pfam_th, tigr_th))
Esempio n. 7
0
 def test___lt__(self):
     self.assertLess(Hit('gene_id', 'hmm_id', 1e-100, 10),
                     Hit('gene_id', 'hmm_id', 1e-100, 20))
     self.assertLess(Hit('gene_id', 'hmm_id', 1e-100, 10),
                     Hit('gene_id', 'hmm_id', 1e-200, 10))
     self.assertLess(Hit('gene_id', 'z', 1e-100, 10),
                     Hit('gene_id', 'a', 1e-100, 10))
     self.assertLess(Hit('z', 'hmm_id', 1e-100, 10),
                     Hit('a', 'hmm_id', 1e-100, 10))
Esempio n. 8
0
 def test___eq___not_equal(self):
     self.assertNotEqual(Hit('gene_id', 'hmm_id', 0.01, 100),
                         Hit('gene+id', 'hmm_id', 0.01, 100))
     self.assertNotEqual(Hit('gene_id', 'hmm_id', 0.01, 100),
                         Hit('gene_id', 'hmm+id', 0.01, 100))
     self.assertNotEqual(Hit('gene_id', 'hmm_id', 1e-100, 100),
                         Hit('gene_id', 'hmm_id', 1e-101, 100))
     self.assertNotEqual(Hit('gene_id', 'hmm_id', 0.01, 1e-100),
                         Hit('gene_id', 'hmm_id', 0.01, 1e-101))
Esempio n. 9
0
    def test_get_single_copy_hits(self):
        g1_expected = {
            'PFAM_1': {
                'hit': Hit('gene_a', 'PFAM_1', 0.05, 100),
                'seq': 'VVVVVV'
            },
            'TIGR_1': {
                'hit': Hit('gene_x', 'TIGR_1', 0.05, 100),
                'seq': 'AAAAAA'
            },
            'PFAM_2': {
                'hit': Hit('gene_b', 'PFAM_2', 0.05, 200),
                'seq': 'AAVVPP'
            }
        }
        g2_expected = {
            'PFAM_2': {
                'hit': Hit('gene_a', 'PFAM_2', 0.05, 100),
                'seq': 'VVVVVV'
            },
            'TIGR_1': {
                'hit': Hit('gene_x', 'TIGR_1', 0.05, 200),
                'seq': 'AAAVVV'
            },
            'TIGR_2': {
                'hit': Hit('gene_y', 'TIGR_2', 0.01, 100),
                'seq': 'VVVAAA'
            }
        }

        self.assertDictEqual(g1_expected,
                             self.cn.get_single_copy_hits('genome_1'))
        self.assertDictEqual(g2_expected,
                             self.cn.get_single_copy_hits('genome_2'))
Esempio n. 10
0
    def test_add_genome(self):
        genome_1_truth = {
            'unq': {
                'PFAM_1': {
                    'hit': Hit('gene_a', 'PFAM_1', 0.05, 100),
                    'seq': 'VVVVVV'
                },
                'TIGR_1': {
                    'hit': Hit('gene_x', 'TIGR_1', 0.05, 100),
                    'seq': 'AAAAAA'
                }
            },
            'muq': {
                'PFAM_2': {
                    'hit': Hit('gene_b', 'PFAM_2', 0.05, 200),
                    'seq': 'AAVVPP'
                }
            },
            'mul': {},
            'mis': {
                'PFAM_3': None,
                'TIGR_2': None
            }
        }
        genome_2_truth = {
            'unq': {
                'PFAM_2': {
                    'hit': Hit('gene_a', 'PFAM_2', 0.05, 100),
                    'seq': 'VVVVVV'
                }
            },
            'muq': {
                'TIGR_1': {
                    'hit': Hit('gene_x', 'TIGR_1', 0.05, 200),
                    'seq': 'AAAVVV'
                },
                'TIGR_2': {
                    'hit': Hit('gene_y', 'TIGR_2', 0.01, 100),
                    'seq': 'VVVAAA'
                }
            },
            'mul': {
                'PFAM_1': None,
                'PFAM_3': None
            },
            'mis': {}
        }

        self.assertDictEqual(genome_1_truth, self.cn.genomes['genome_1'])
        self.assertDictEqual(genome_2_truth, self.cn.genomes['genome_2'])
Esempio n. 11
0
 def test_hmm_str(self):
     hit = Hit('gene_id', 'hmm_id', 0.05, 100)
     self.assertEqual('hmm_id,0.05,100', hit.hmm_str())
Esempio n. 12
0
 def test___eq___equal(self):
     self.assertEqual(Hit('gene_id', 'hmm_id', 1e-100, 1e-100),
                      Hit('gene_id', 'hmm_id', 1e-100, 1e-100))
Esempio n. 13
0
 def test___repr__(self):
     hit = Hit('a', 'b', 0.05, 100)
     self.assertEqual(f'a b (0.05/100)', repr(hit))
Esempio n. 14
0
 def test___init__(self):
     hit = Hit('gene_id', 'hmm_id', 0.05, 100)
     self.assertEqual('gene_id', hit.gene_id)
     self.assertEqual('hmm_id', hit.hmm_id)
     self.assertAlmostEqual(0.05, hit.e_val, 2)
     self.assertAlmostEqual(100, hit.bit_score, 0)
Esempio n. 15
0
 def test_get_hmm_hit(self):
     self.th.add_hit('a', 'b', 0.1, 10)
     self.th.add_hit('a', 'c', 0.1, 20)
     self.assertEqual(Hit('a', 'b', 0.1, 10), self.th.get_hmm_hit('a', 'b'))
Esempio n. 16
0
 def test_get_top_hit(self):
     self.th.add_hit('a', 'b', 0.1, 10)
     self.th.add_hit('a', 'c', 0.1, 20)
     self.th.add_hit('a', 'd', 0.1, 5)
     self.assertEqual(Hit('a', 'c', 0.1, 20), self.th.get_top_hit('a'))
     self.assertIsNone(self.th.get_top_hit('x'))