Exemplo n.º 1
0
 def test_goto_assignment1(self):
     """
     test_goto_assignment1 fullfils A1.
     It first tests the output.
     Then it writes the output to the file 'results/assignment1/2_2.txt'.
     """
     tests = [
         (read_fasta_file('data/test1_1.fasta'),
          read_fasta_file('data/test1_2.fasta'), -3, -1, None, (
              10,
              -10,
              'AATCCGCTAGAAACCCTTAG',
              '_ATC______TTACCTTCAT',
              ' ***      ||***|*|*|',
          ), 'results/assignment1_1.txt'),
         (
             read_fasta_file('data/test2_1.fasta'),
             read_fasta_file('data/test2_2.fasta'),
             -3,
             -1,
             None,
             (
                 1,
                 2,
                 'ATTCACTAGATTACCTTCACT',
                 '________GATTACCTTCACT',
                 '        *************',
             ),
             'results/assignment1_2.txt',
         ),
     ]
     g = gotoh.Gotoh()
     gotoh_funcs = [gotoh.gotoh, g.run]
     for func in gotoh_funcs:
         for t in tests:
             score, alignments = func(t[0], t[1], t[2], t[3])
             should = t[5]
             self.assertEqual(should[0], len(alignments))
             self.assertEqual(should[1], score)
             self.assertEqual(should[2], ''.join(alignments[0][0]))
             self.assertEqual(should[3], ''.join(alignments[0][1]))
             self.assertEqual(should[4], ''.join(alignments[0][2]))
     f = None
     for t in tests:
         score, alignments = gotoh.gotoh(t[0], t[1], t[2], t[3])
         # open(t[6], "w").close()
         f = open(t[6], "w")
         score, alignments = gotoh.gotoh(t[0], t[1], t[2], t[3], t[4])
         f.write('Score ' + str(score) + ' and ' + str(len(alignments)) +
                 ' optimal alignments. \n')
         for a in alignments:
             f.write(''.join(a[0]) + '\n')
             f.write(''.join(a[2]) + '\n')
             f.write(''.join(a[1]) + '\n\n')
         f.write('\n\n\n')
         f.close()
Exemplo n.º 2
0
    def test_empty(self):
        """Checks if everything is fine with empty sequences."""
        gt = gotoh.Gotoh()
        result = gt.run("../T_INPUT/empty_test.fasta",
                        "../T_INPUT/empty_test.fasta", "../T_INPUT/6eva.txt",
                        -4, -1, True)
        (id_seq1, seq1, id_seq2, seq2, score, alignments) = result

        assert id_seq1 == ""
        assert id_seq2 == ""
        assert seq1 == ""
        assert seq2 == ""
        assert score == 0
        assert alignments == []  # order of elements can be random!
Exemplo n.º 3
0
    def test_one_empty(self):
        """Checks if everything is fine with one empty sequence."""
        gt = gotoh.Gotoh()
        result = gt.run("../T_INPUT/empty_test.fasta",
                        "../T_INPUT/5test_seq2.fasta", "../T_INPUT/6eva.txt",
                        -4, -1, True)
        (id_seq1, seq1, id_seq2, seq2, score, alignments) = result

        assert id_seq1 == ""
        assert id_seq2 == "Seq2"
        assert seq1 == ""
        assert seq2 == "TCCGA"
        assert score == -9
        assert alignments == [["-----",
                               "TCCGA"]]  # order of elements is random!
Exemplo n.º 4
0
    def test_6(self):
        """Test if run function can be called."""
        gt = gotoh.Gotoh()
        result = gt.run("../T_INPUT/6test_seq1.fasta",
                        "../T_INPUT/6test_seq2.fasta", "../T_INPUT/6eva.txt",
                        -4, -1, True)
        (id_seq1, seq1, id_seq2, seq2, score, alignments) = result

        assert id_seq1 == "Seq1"
        assert id_seq2 == "Seq2"
        assert seq1 == "CC"
        assert seq2 == "ACCT"
        assert score == -7
        assert alignments == [['--CC', 'ACCT'],
                              ['CC--',
                               'ACCT']]  # order of elements can be random!
Exemplo n.º 5
0
    def test_4(self):
        """Test if run function can be called."""
        gt = gotoh.Gotoh()
        result = gt.run("../T_INPUT/4test_seq1.fasta",
                        "../T_INPUT/4test_seq2.fasta", "../T_INPUT/4eva.txt",
                        -3, -1, True)
        (id_seq1, seq1, id_seq2, seq2, score, alignments) = result

        assert id_seq1 == "Seq1"
        assert id_seq2 == "Seq2"
        assert seq1 == "TGGA"
        assert seq2 == "GG"
        assert score == -6
        assert alignments == [['TGGA', '--GG'],
                              ['TGGA',
                               'GG--']]  # order of elements can be random!
Exemplo n.º 6
0
 def test_gotoh_edgecases(self):
     """
     test_gotoh_edgecases tests 3 edge cases.
     1. Only wrongs.
     2. First two gap with (*,0)
     3. First two gap with (0,*)
     """
     tests = [
         ([' ', 'A', 'T'], [' ', 'T', 'A'], -3, -1, None, (
             1,
             -2,
             'AT',
             'TA',
             '||',
         )),
         ([' ', 'A', 'T', 'T', 'A'], [' ', 'T', 'A'], -3, -1, None, (
             1,
             -3,
             'ATTA',
             '__TA',
             '  **',
         )),
         ([' ', 'T', 'A'], [' ', 'A', 'T', 'T', 'A'], -3, -1, None, (
             1,
             -3,
             '__TA',
             'ATTA',
             '  **',
         )),
     ]
     for t in tests:
         score, alignments = gotoh.gotoh(t[0], t[1], t[2], t[3])
         should = t[5]
         self.assertEqual(should[0], len(alignments))
         self.assertEqual(should[1], score)
         self.assertEqual(should[2], ''.join(alignments[0][0]))
         self.assertEqual(should[3], ''.join(alignments[0][1]))
         self.assertEqual(should[4], ''.join(alignments[0][2]))
     g = gotoh.Gotoh()
     for t in tests:
         score, alignments = g.run(t[0], t[1], t[2], t[3])
         should = t[5]
         self.assertEqual(should[0], len(alignments))
         self.assertEqual(should[1], score)
         self.assertEqual(should[2], ''.join(alignments[0][0]))
         self.assertEqual(should[3], ''.join(alignments[0][1]))
         self.assertEqual(should[4], ''.join(alignments[0][2]))
Exemplo n.º 7
0
    def test_5(self):
        """Test if run function can be called."""
        gt = gotoh.Gotoh()
        result = gt.run("../T_INPUT/5test_seq1.fasta",
                        "../T_INPUT/5test_seq2.fasta", "../T_INPUT/5eva.txt",
                        -4, -1, True)
        (id_seq1, seq1, id_seq2, seq2, score, alignments) = result

        assert id_seq1 == "Seq1"
        assert id_seq2 == "Seq2"
        assert seq1 == "TACGCAGA"
        assert seq2 == "TCCGA"
        assert score == -3
        assert alignments == [['TACGCAGA',
                               'T---CCGA'], ['TACGCAGA', 'TCC---GA'],
                              ['TACGCAGA',
                               'TCCG---A']]  # order of elements can be random!
Exemplo n.º 8
0
 def test_instance(self):
     """Check inheritance."""
     assert issubclass(gotoh.Gotoh, GotohBase)
     assert isinstance(gotoh.Gotoh(), GotohBase)