view allpy/markups.py @ 781:6f615b0a2359
allpy.base: when filling by_code3 tables, unmodified classes take precedence
author |
Daniil Alexeyevsky <dendik@kodomo.fbb.msu.ru> |
date |
Tue, 12 Jul 2011 23:52:54 +0400 |
parents |
21cfc7897a8f |
children |
497de2152849 |
line source
3 class IntMarkupMixin(base.Markup):
6 def from_record(cls, container, record, name=None):
7 assert record['io-class'] == 'IntMarkup'
8 result = cls(container, name=name)
9 separator = record.get('separator', ',')
10 values = record['markup'].split(separator)
11 assert len(values) == len(result.sorted_keys())
12 for key, value in zip(result.sorted_keys(), values):
14 result[key] = int(value)
22 values = [fmt(self.get(key)) for key in self.sorted_keys()]
23 return {'markup': ','.join(values), 'io-class': 'IntMarkup'}
25 class SequenceNumberMarkup(base.SequenceMarkup):
30 for number, monomer in enumerate(self.sequence, 1):
31 monomer.number = number
33 class SequenceIndexMarkup(base.SequenceMarkup):
38 for index, monomer in enumerate(self.sequence):
41 class AlignmentNumberMarkup(base.AlignmentMarkup):
46 for number, column in enumerate(self.alignment.columns, 1):
49 class AlignmentIndexMarkup(base.AlignmentMarkup):
54 for index, column in enumerate(self.alignment.columns):
57 class SequenceCaseMarkup(base.SequenceMarkup):
62 for monomer in self.sequence:
63 if monomer.input_code1.isupper():
64 monomer.case = 'upper'
65 elif monomer.input_code1.islower():
66 monomer.case = 'lower'
69 def from_record(cls, container, record, name=None):
70 assert record['io-class'] == 'SequenceCaseMarkup'
71 result = cls(container, name=name)
72 markup = record['markup']
73 assert markup[0] == markup[-1] == "'"
75 assert len(markup) == len(result.sequence)
76 for monomer, mark in zip(result.sequence, markup):
77 assert monomer.code1 == mark.upper()
79 monomer.case = 'upper'
81 monomer.case = 'lower'
86 for monomer in self.sequence:
87 case = self.get(monomer)
89 markup += monomer.code1.upper()
91 markup += monomer.code1.lower()
92 return {'markup': "'%s'" % markup, 'io-class': 'SequenceCaseMarkup'}
94 # vim: set ts=4 sts=4 sw=4 et: