def test_longest_palindrome_beginning(self):
        sequence = GeneticSequence('TGGATCCATTAA')
        self.assertEqual(sequence.longest_palindrome.index, 0)
        self.assertEqual(sequence.longest_palindrome.sequence.length, 8)
        self.assertEqual(sequence.longest_palindrome.sequence, 'TGGATCCA')

        sequence = GeneticSequence('AATTC')
        self.assertEqual(sequence.longest_palindrome.index, 0)
        self.assertEqual(sequence.longest_palindrome.sequence.length, 4)
        self.assertEqual(sequence.longest_palindrome.sequence, 'AATT')
    def test_longest_palindrome_end(self):
        sequence = GeneticSequence('ATTACCTAGGT')
        self.assertEqual(sequence.longest_palindrome.index, 3)
        self.assertEqual(sequence.longest_palindrome.sequence.length, 8)
        self.assertEqual(sequence.longest_palindrome.sequence, 'ACCTAGGT')

        sequence = GeneticSequence('CTTAA')
        self.assertEqual(sequence.longest_palindrome.index, 1)
        self.assertEqual(sequence.longest_palindrome.sequence.length, 4)
        self.assertEqual(sequence.longest_palindrome.sequence, 'TTAA')
    def test_longest_palindrome_middle(self):
        # Between shorter palindromes.
        sequence = GeneticSequence('TTAATGGATCCACCGG')
        self.assertEqual(sequence.longest_palindrome.index, 4)
        self.assertEqual(sequence.longest_palindrome.sequence.length, 8)
        self.assertEqual(sequence.longest_palindrome.sequence, 'TGGATCCA')

        sequence = GeneticSequence('GCAATTCG')
        self.assertEqual(sequence.longest_palindrome.index, 2)
        self.assertEqual(sequence.longest_palindrome.sequence.length, 4)
        self.assertEqual(sequence.longest_palindrome.sequence, 'AATT')
    def test_is_palindrome(self):
        self.assertTrue(GeneticSequence('ACCTAGGT').is_palindrome)
        self.assertTrue(GeneticSequence('TGGATCCA').is_palindrome)
        self.assertTrue(GeneticSequence('TTAA').is_palindrome)
        self.assertTrue(GeneticSequence('CCGG').is_palindrome)
        self.assertTrue(GeneticSequence('AT').is_palindrome)
        self.assertTrue(GeneticSequence('CG').is_palindrome)

        self.assertFalse(GeneticSequence('TTACCTAGGT').is_palindrome)
        self.assertFalse(GeneticSequence('CTTAA').is_palindrome)
        self.assertFalse(GeneticSequence('ATTA').is_palindrome)
Exemplo n.º 5
0
def print_longest_palindrome(sequence_string):
    try:
        sequence = GeneticSequence(sequence_string)
    except GeneticSequence.InvalidSequenceError as e:
        print(f'\n{e}\n')
    else:
        pal = sequence.longest_palindrome
        if pal.sequence:
            print(f'\nStarting Index: {pal.index}')
            print(f'Length: {pal.sequence.length}')
            print(f'Palindrome: "{pal.sequence}"\n')
        else:
            print('\nNo palindrome found\n')
 def test_longest_palindrome_self(self):
     sequence = GeneticSequence('TTAA')
     self.assertEqual(sequence.longest_palindrome.index, 0)
     self.assertIs(sequence.longest_palindrome.sequence, sequence)
 def test_longest_palindrome_none(self):
     sequence = GeneticSequence('ACTG')
     self.assertIsNone(sequence.longest_palindrome.sequence)
     self.assertIsNone(sequence.longest_palindrome.index)
 def test_complement(self):
     self.assertEqual(GeneticSequence('ATCG').complement, 'TAGC')
 def test_case_insensitive(self):
     self.assertEqual(GeneticSequence('atcg'), 'ATCG')
     self.assertEqual(GeneticSequence('gCtA'), 'GCTA')