Пример #1
0
    def test_name(self):
        self.assertEqual(self.sgc.name, 'Standard')
        self.assertEqual(GeneticCode('M' * 64, '-' * 64).name, '')
        self.assertEqual(GeneticCode('M' * 64, '-' * 64, 'foo').name, 'foo')

        with self.assertRaises(AttributeError):
            self.sgc.name = 'foo'
Пример #2
0
    def test_eq(self):
        amino_acids = 'AMPM' * 16
        starts = '--M-' * 16

        equal_gcs = [
            GeneticCode(amino_acids, starts),
            # name should be ignored
            GeneticCode(amino_acids, starts, 'foo'),
            # metadata/positional metadata should be ignored if Sequence
            # subclass is provided
            GeneticCode(
                Protein(amino_acids, metadata={'foo': 'bar'}),
                Protein(starts, positional_metadata={'foo': range(64)}))
        ]

        # every gc should be equal to itself
        for gc in equal_gcs:
            self.assertTrue(gc == gc)
            self.assertFalse(gc != gc)

        # every pair of gcs should be equal. use permutations instead of
        # combinations to test that comparing gc1 to gc2 and gc2 to gc1 are
        # both equal
        for gc1, gc2 in itertools.permutations(equal_gcs, 2):
            self.assertTrue(gc1 == gc2)
            self.assertFalse(gc1 != gc2)
Пример #3
0
    def test_translate_varied_genetic_codes(self):
        # spot check using a few NCBI and custom genetic codes to translate
        seq = RNA('AAUGAUGUGACUAUCAGAAGG')

        # table_id=2
        exp = Protein('NDVTI**')
        obs = GeneticCode.from_ncbi(2).translate(seq)
        self.assertEqual(obs, exp)

        exp = Protein('MTI')
        obs = GeneticCode.from_ncbi(2).translate(seq,
                                                 start='require',
                                                 stop='require')
        self.assertEqual(obs, exp)

        # table_id=22
        exp = Protein('NDVTIRR')
        obs = GeneticCode.from_ncbi(22).translate(seq)
        self.assertEqual(obs, exp)

        with six.assertRaisesRegex(self, ValueError,
                                   'reading_frame=1.*start=\'require\''):
            GeneticCode.from_ncbi(22).translate(seq,
                                                start='require',
                                                stop='require')

        # custom, no start codons
        gc = GeneticCode('MWN*' * 16, '-' * 64)
        exp = Protein('MM*MWN*')
        obs = gc.translate(seq)
        self.assertEqual(obs, exp)

        with six.assertRaisesRegex(self, ValueError,
                                   'reading_frame=1.*start=\'require\''):
            gc.translate(seq, start='require', stop='require')
Пример #4
0
 def test_from_ncbi_valid_table_ids(self):
     # spot check a few tables
     self.assertEqual(GeneticCode.from_ncbi().name, 'Standard')
     self.assertEqual(
         GeneticCode.from_ncbi(2).name, 'Vertebrate Mitochondrial')
     self.assertEqual(
         GeneticCode.from_ncbi(12).name, 'Alternative Yeast Nuclear')
     self.assertEqual(
         GeneticCode.from_ncbi(25).name,
         'Candidate Division SR1 and Gracilibacteria')
Пример #5
0
 def test_from_ncbi_valid_table_ids(self):
     # spot check a few tables
     self.assertEqual(GeneticCode.from_ncbi().name,
                      'Standard')
     self.assertEqual(GeneticCode.from_ncbi(2).name,
                      'Vertebrate Mitochondrial')
     self.assertEqual(GeneticCode.from_ncbi(12).name,
                      'Alternative Yeast Nuclear')
     self.assertEqual(GeneticCode.from_ncbi(25).name,
                      'Candidate Division SR1 and Gracilibacteria')
Пример #6
0
    def test_translate_varied_genetic_codes(self):
        # spot check using a few NCBI and custom genetic codes to translate
        seq = RNA('AAUGAUGUGACUAUCAGAAGG')

        # table_id=2
        exp = Protein('NDVTI**')
        obs = GeneticCode.from_ncbi(2).translate(seq)
        self.assertEqual(obs, exp)

        exp = Protein('MTI')
        obs = GeneticCode.from_ncbi(2).translate(seq, start='require',
                                                 stop='require')
        self.assertEqual(obs, exp)

        # table_id=22
        exp = Protein('NDVTIRR')
        obs = GeneticCode.from_ncbi(22).translate(seq)
        self.assertEqual(obs, exp)

        with self.assertRaisesRegex(ValueError,
                                    'reading_frame=1.*start=\'require\''):
            GeneticCode.from_ncbi(22).translate(seq, start='require',
                                                stop='require')

        # custom, no start codons
        gc = GeneticCode('MWN*' * 16, '-' * 64)
        exp = Protein('MM*MWN*')
        obs = gc.translate(seq)
        self.assertEqual(obs, exp)

        with self.assertRaisesRegex(ValueError,
                                    'reading_frame=1.*start=\'require\''):
            gc.translate(seq, start='require', stop='require')
Пример #7
0
 def test_init_varied_equivalent_input(self):
     for args in (('M' * 64, '-' * 64), (Protein('M' * 64),
                                         Protein('-' * 64)),
                  (Sequence('M' * 64), Sequence('-' * 64))):
         gc = GeneticCode(*args)
         self.assertEqual(gc.name, '')
         self.assertEqual(gc._amino_acids, Protein('M' * 64))
         self.assertEqual(gc._starts, Protein('-' * 64))
         npt.assert_array_equal(gc._m_character_codon,
                                np.asarray([0, 0, 0], dtype=np.uint8))
         self.assertEqual(len(gc._start_codons), 0)
Пример #8
0
 def test_translate_six_frames_genetic_code_object(self):
     gc = GeneticCode('M' * 64, '-' * 64)
     for seq in RNA('AAAUUG'), DNA('AAATTG'):
         obs = list(seq.translate_six_frames(gc))
         self.assertEqual(obs, [
             Protein('MM'),
             Protein('M'),
             Protein('M'),
             Protein('MM'),
             Protein('M'),
             Protein('M')
         ])
Пример #9
0
    def test_init_invalid_input(self):
        # `amino_acids` invalid protein
        with six.assertRaisesRegex(self, ValueError, 'Invalid character.*J'):
            GeneticCode('J' * 64, '-' * 64)

        # wrong number of amino acids
        with six.assertRaisesRegex(self, ValueError, 'amino_acids.*64.*42'):
            GeneticCode('M' * 42, '-' * 64)

        # `amino_acids` missing M
        with six.assertRaisesRegex(self, ValueError,
                                   'amino_acids.*M.*character'):
            GeneticCode('A' * 64, '-' * 64)

        # `starts` invalid protein
        with six.assertRaisesRegex(self, ValueError, 'Invalid character.*J'):
            GeneticCode('M' * 64, 'J' * 64)

        # wrong number of starts
        with six.assertRaisesRegex(self, ValueError, 'starts.*64.*42'):
            GeneticCode('M' * 64, '-' * 42)

        # invalid characters in `starts`
        with six.assertRaisesRegex(self, ValueError,
                                   'starts.*M and - characters'):
            GeneticCode('M' * 64, '-M' * 30 + '*AQR')
Пример #10
0
    def test_str(self):
        # predefined
        exp = (
            '  AAs  = FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAA'
            'DDEEGGGG\n'
            'Starts = ---M---------------M---------------M--------------------'
            '--------\n'
            'Base1  = UUUUUUUUUUUUUUUUCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGG'
            'GGGGGGGG\n'
            'Base2  = UUUUCCCCAAAAGGGGUUUUCCCCAAAAGGGGUUUUCCCCAAAAGGGGUUUUCCCC'
            'AAAAGGGG\n'
            'Base3  = UCAGUCAGUCAGUCAGUCAGUCAGUCAGUCAGUCAGUCAGUCAGUCAGUCAGUCAG'
            'UCAGUCAG')
        self.assertEqual(str(self.sgc), exp)

        # custom, no name
        obs = str(GeneticCode('M' * 64, '-' * 64))
        self.assertIn('M' * 64, obs)
        self.assertIn('-' * 64, obs)
Пример #11
0
    def test_ne(self):
        class GeneticCodeSubclass(GeneticCode):
            pass

        amino_acids = 'AMPM' * 16
        starts = '--M-' * 16

        unequal_gcs = [
            GeneticCode(amino_acids, starts),
            # type must match
            GeneticCodeSubclass(amino_acids, starts),
            # completely different type
            'foo'
        ]
        # none of the NCBI genetic codes should be equal to each other
        unequal_gcs.extend(_ncbi_genetic_codes.values())

        for gc in unequal_gcs:
            self.assertTrue(gc == gc)
            self.assertFalse(gc != gc)

        for gc1, gc2 in itertools.permutations(unequal_gcs, 2):
            self.assertTrue(gc1 != gc2)
            self.assertFalse(gc1 == gc2)
Пример #12
0
 def test_from_ncbi_invalid_input(self):
     with six.assertRaisesRegex(self, ValueError, 'table_id.*7'):
         GeneticCode.from_ncbi(7)
     with six.assertRaisesRegex(self, ValueError, 'table_id.*42'):
         GeneticCode.from_ncbi(42)
Пример #13
0
 def setUp(self):
     self.sgc = GeneticCode.from_ncbi(1)
Пример #14
0
 def test_translate_genetic_code_object(self):
     gc = GeneticCode('M' * 64, '-' * 64)
     for seq in RNA('AAAUUUAUGCAU'), DNA('AAATTTATGCAT'):
         obs = seq.translate(gc)
         self.assertEqual(obs, Protein('MMMM'))
Пример #15
0
 def test_from_ncbi_invalid_input(self):
     with self.assertRaisesRegex(ValueError, 'table_id.*7'):
         GeneticCode.from_ncbi(7)
     with self.assertRaisesRegex(ValueError, 'table_id.*42'):
         GeneticCode.from_ncbi(42)
Пример #16
0
 def setUp(self):
     self.sgc = GeneticCode.from_ncbi(1)