Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/file/tip/test/test_markups.py
Дата изменения: Unknown
Дата индексирования: Tue Apr 12 11:23:56 2016
Кодировка:
allpy: b556c96c6719 test/test_markups.py

allpy

view test/test_markups.py @ 1168:b556c96c6719

blocks3d/www Makefile: never check certificates of github, they are too confusing for wget
author Daniil Alexeyevsky <dendik@kodomo.fbb.msu.ru>
date Mon, 26 May 2014 17:20:29 +0400
parents 0aa68678861c
children
line source
1 from StringIO import StringIO
2 from allpy import base
3 from allpy import protein
4 from allpy import markups
5 import protein_pdb
7 def test_index():
8 seq = protein.Sequence.from_string('SEQVENCE', name='sequence')
9 markup = seq.add_markup('index')
10 assert seq[5].index == 5
11 assert markup[seq[5]] == 5
13 def test_hardio():
14 aln = protein.Alignment().append_row_from_string("SEQVENCE", name="A")
15 markup = aln.sequences[0].add_markup('index')
16 del aln.columns[2]
18 file = StringIO()
19 aln.to_file(file, format="markup")
21 file.seek(0)
22 aln = protein.Alignment().append_file(file, format="markup")
23 assert str(aln.sequences[0]) == "SEVENCE"
24 assert aln.sequences[0][3].index == 3
26 def test_number():
27 seq = protein.Sequence.from_string('SEQVENCE', name='sequence')
28 seq.add_markup('number')
29 assert seq[5].number == 6
30 assert seq.markups["number"][seq[5]] == 6
32 try:
33 seq.add_markup('number')
34 except AssertionError:
35 pass
36 else:
37 raise AssertionError("Silently created same named alignment")
39 seq.add_markup('number', use_existing=True)
41 try:
42 other = markups.SequenceIndexMarkup
43 seq.add_markup('number', use_existing=True, markup_class=other)
44 except AssertionError:
45 pass
46 else:
47 raise AssertionError("Created same named different class alignment")
49 def test_case():
50 seq = protein.Sequence.from_string('seQVEncE', name='sequence')
51 seq.add_markup('case')
52 letters = ''.join(v[0] for v in seq.markups['case'].sorted_values())
53 assert letters == 'lluuullu'
55 fakefile = StringIO()
56 aln = protein.Alignment().append_sequence(seq)
57 aln.to_file(fakefile, format='markup')
59 fakefile.seek(0)
60 aln = protein.Alignment().append_file(fakefile, format='markup')
61 seq = aln.sequences[0]
62 letters = ''.join(v[0] for v in seq.markups['case'].sorted_values())
63 assert letters == 'lluuullu'
65 def test_manual():
66 seq = protein.Sequence.from_string('SEQVENCE', name='sequence')
67 markup = seq.add_markup(name='my_markup', markup_class=base.SequenceMarkup)
68 markup[seq[4]] = 5
69 assert seq[4].my_markup == 5
70 seq[2].my_markup = 4
71 assert markup[seq[2]] == 4
73 def test_by_name():
74 from_name = markups.by_name['sequence_markup', 'index']
75 assert from_name is markups.SequenceIndexMarkup
76 from_name = markups.by_name['alignment_markup', 'index']
77 assert from_name is markups.AlignmentIndexMarkup
79 def test_io():
80 aln = (protein.Alignment().
81 append_row_from_string('aseq-vence', name='a').
82 append_row_from_string('ase-qret--', name='b')
83 )
85 class MySequenceMarkup(base.SequenceMarkup, markups.IntMarkupMixin):
86 name = 'm1'
87 class MyAlignmentMarkup(base.AlignmentMarkup, markups.IntMarkupMixin):
88 name = 'm2'
89 markups.update(MySequenceMarkup, MyAlignmentMarkup)
91 s = aln.sequences[0]
92 c = aln.columns
93 m1 = s.add_markup('m1')
94 m1[s[5]] = 5
95 m1[s[3]] = 3
96 m2 = aln.add_markup('m2')
97 m2[c[5]] = 5
98 m2[c[6]] = 6
99 m3 = aln.add_markup('m3', markup_class=MyAlignmentMarkup)
100 m3.save = False
101 m3[c[1]] = "hello"
102 m4 = aln.add_markup('m4', markup_class=MyAlignmentMarkup)
103 m5 = s.add_markup('ss', markup_class=markups.SequenceCharMarkup)
104 s[0].ss = 'H'
105 s[5].ss = 'S'
107 file = StringIO()
108 aln.to_file(file, format='markup')
110 file.seek(0)
111 out = protein.Alignment().append_file(file, format='markup')
112 s = out.sequences[0]
113 c = out.columns
114 assert s[5].m1 == 5 and s[3].m1 == 3
115 assert out.<