Beispiel #1
0
 def test_pdb_coords_hdr(self):
     hdr = Sequence.split_hdr('cath|4_3_0|4w5hA00/-1-211')
     self.assertEqual(hdr['id'], 'cath|4_3_0|4w5hA00/-1-211')
     self.assertEqual(hdr['accession'], '4w5hA00')
     self.assertEqual(hdr['id_type'], 'domain')
     self.assertEqual(hdr['segs'][0].start, "-1")
     self.assertEqual(hdr['segs'][0].stop, "211")
Beispiel #2
0
 def test_sequence_methods(self):
     seq = Sequence('id1/23-123', '---AKGHP--GPKAPGPAK--')
     self.assertEqual(seq.get_offset_at_seq_position(1),
                      3)  # seq pos '1' 'A' -> offset '3'
     self.assertEqual(seq.get_res_at_seq_position(2), 'K')
     # offset 5 'G' -> seq pos 3 'AKG'
     self.assertEqual(seq.get_seq_position_at_offset(5), 3)
     self.assertEqual(seq.get_res_at_offset(5), 'G')
Beispiel #3
0
 def test_pdb_numeric_coords_hdr(self):
     hdr = Sequence.split_hdr(
         'cath|4_3_0|4w5hA00/23-211_232-345', parse_segments_as_numbers=True)
     self.assertEqual(hdr['id'], 'cath|4_3_0|4w5hA00/23-211_232-345')
     self.assertEqual(hdr['accession'], '4w5hA00')
     self.assertEqual(hdr['id_type'], 'domain')
     self.assertEqual(hdr['segs'][0].start, 23)
     self.assertEqual(hdr['segs'][0].stop, 211)
     self.assertEqual(hdr['segs'][1].start, 232)
     self.assertEqual(hdr['segs'][1].stop, 345)
Beispiel #4
0
 def test_split_hdr(self):
     hdr = Sequence.split_hdr('domain|1cukA01/12-134_178-234')
     self.assertEqual(hdr['id'], 'domain|1cukA01/12-134_178-234')
     self.assertEqual(hdr['accession'], '1cukA01')
     self.assertEqual(hdr['id_type'], 'domain')
     self.assertIsInstance(hdr['segs'][0], SegmentBase)
     self.assertEqual(hdr['segs'][0].start, '12')
     self.assertEqual(hdr['segs'][0].stop, '134')
     self.assertIsInstance(hdr['segs'][1], SegmentBase)
     self.assertEqual(str(hdr['segs'][1]), '178-234')
     self.assertEqual(hdr['id_ver'], None)
Beispiel #5
0
 def test_create_sequence(self):
     seq = Sequence('id1/23-123', '---AKGHP--GPKAPGPAK--')
     self.assertEqual(seq.uid, 'id1/23-123')
     self.assertEqual(seq.accession, 'id1')
     self.assertEqual(len(seq.segs), 1)
     self.assertEqual(seq.segs[0].start, '23')
     self.assertEqual(seq.segs[0].stop, '123')
     self.assertEqual(seq.seq, '---AKGHP--GPKAPGPAK--')
     self.assertEqual(seq.get_res_at_offset(0), '-')
     self.assertEqual(seq.get_res_at_offset(3), 'A')
     seq.insert_gap_at_offset(5)
     self.assertEqual(seq.seq, '---AK-GHP--GPKAPGPAK--')
     seq.insert_gap_at_offset(-3, gap_char='.')
     self.assertEqual(seq.seq, '---AK-GHP--GPKAPGPA.K--')
Beispiel #6
0
    def test_sequence_errors(self):
        seq = Sequence('seq1', '-TTTTL-LASAM')
        self.assertEqual(seq.get_res_at_offset(0), '-')
        self.assertEqual(seq.get_res_at_offset(1), 'T')
        self.assertEqual(seq.get_res_at_offset(11), 'M')
        self.assertEqual(seq.get_res_at_offset(-3), 'S')

        with self.assertRaises(SeqIOError):
            seq.get_res_at_offset(12)

        with self.assertRaises(SeqIOError):
            seq.get_res_at_seq_position(11)

        self.assertEqual(seq.get_seq_position_at_offset(2), 2)
        with self.assertRaises(GapError):
            seq.get_seq_position_at_offset(6)
Beispiel #7
0
    def test_apply_segments(self):
        seq1str = 'AKGHP GPKAP GPAKK APHPP PAIIH PAPIL HADSA P'.replace(
            ' ', '')
        seq1 = Sequence('testid', seq1str)
        self.assertEqual(seq1.uid, 'testid')
        self.assertEqual(len(seq1.seq), len(seq1str))

        seq2 = seq1.apply_segments([Segment(3, 5)])
        self.assertEqual(seq1.uid, 'testid')
        self.assertEqual(len(seq1.seq), len(seq1str))
        self.assertEqual(seq2.uid, 'testid/3-5')
        self.assertEqual(seq2.seq, 'GHP')

        seq3 = seq1.apply_segments([Segment(3, 10), Segment(15, 25)])

        seq3str = ''.join(['GHPGPKAP', 'KAPHPPPAIIH'])
        self.assertEqual(seq3.uid, 'testid/3-10_15-25')
        self.assertEqual(len(seq3.seq), 8 + 11)
        self.assertEqual(seq3.seq, seq3str)
Beispiel #8
0
 def test_pdb_numeric_coords_hdr_fails(self):
     with self.assertRaises(ValueError):
         hdr = Sequence.split_hdr(
             'cath|4_3_0|4w5hA00/-1-211', parse_segments_as_numbers=True)
Beispiel #9
0
 def test_sequence_lower_case(self):
     seq = Sequence('id1/23-123', '---AKGHP--GPKAPGPAK--')
     seq.lower_case_at_offset(6)
     self.assertEqual(seq.seq, '---AKGhP--GPKAPGPAK--')