Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/raw-rev/4f896db3531d
Дата изменения: Unknown
Дата индексирования: Tue Oct 2 08:18:17 2012
Кодировка:

# HG changeset patch
# User Daniil Alexeyevsky
# Date 1310738491 -14400
# Node ID 4f896db3531dcdf726ebb7f4da39fa54f018c9e6
# Parent 41f7241c2aeb1d5c70b5a4977b4fa282eff29ce8
allpy.fileio. markup filetype now allows either - or _ to be used in headers interchangeably [closes #89]

diff -r 41f7241c2aeb -r 4f896db3531d allpy/fileio.py
--- a/allpy/fileio.py Fri Jul 15 17:13:01 2011 +0400
+++ b/allpy/fileio.py Fri Jul 15 18:01:31 2011 +0400
@@ -102,7 +102,8 @@
record type. Header is a sequence of lines, each in format `key: value`.
Content, if present, is separated from header with an empty line.

- Type names and header key names are case-insensitive.
+ Type names and header key names are case-insensitive and '-' and '_' in
+ them are equivalent.

Known record types now are:

@@ -112,14 +113,14 @@

Example::

- sequence_markup
- sequence_name: cyb5_mouse
- sequence_description:
+ sequence-markup
+ sequence-name: cyb5_mouse
+ sequence-description:
name: pdb_residue_number
type: SequencePDBResidueNumberMarkup
markup: -,12,121,122,123,124,13,14,15,-,-,16

- alignment_markup
+ alignment-markup
name: geometrical_core
type: AlignmentGeometricalCoreMarkup
markup: -,-,-,-,+,+,+,-,-,-,+,+,-,-,-,-
@@ -161,9 +162,10 @@
def write_record(self, record):
"""Write record to file. Add new line before every but first record."""
self.write_empty_line()
- self.file.write('%s\n' % record['type'])
+ self.file.write('%s\n' % self.normalize('write', record['type']))
del record['type']
for key, value in record.items():
+ key = self.normalize('write', key)
self.file.write('%s: %s\n' % (key, value))

def write_empty_line(self):
@@ -207,14 +209,14 @@

def read_record(self, alignment, type):
"""Read record headers and record payload."""
- type = type.strip().lower()
+ type = self.normalize('read', type)
record = {'type': type}
for line in self.file:
if line.strip() == "":
self.read_payload(alignment, record, type)
return record
key, value = line.split(':', 1)
- key = key.strip().lower()
+ key = self.normalize('read', key)
value = value.strip()
record[key] = value
return record
@@ -225,6 +227,13 @@
io = File(self.file, record.get('format', 'fasta'), gaps=self.gaps)
io.read_alignment(alignment)

+ @staticmethod
+ def normalize(for_what, string):
+ if for_what == 'read':
+ return string.strip().replace('-', '_').lower()
+ if for_what == 'write':
+ return string.strip().replace('_', '-').capitalize()
+
class EmbossFile(AlignmentFile):
"""Parser & writer for file formats supported by EMBOSS."""

diff -r 41f7241c2aeb -r 4f896db3531d allpy/markups.py
--- a/allpy/markups.py Fri Jul 15 17:13:01 2011 +0400
+++ b/allpy/markups.py Fri Jul 15 18:01:31 2011 +0400
@@ -26,7 +26,7 @@

@classmethod
def from_record(cls, container, record, name=None):
- assert record['io-class'] == 'IntMarkup'
+ assert record['io_class'] == 'IntMarkup'
result = container.add_markup(name, markup_class=cls)
separator = record.get('separator', ',')
values = record['markup'].split(separator)
@@ -42,7 +42,7 @@
return ""
return str(value)
values = [fmt(self.get(key)) for key in self.sorted_keys()]
- return {'markup': ','.join(values), 'io-class': 'IntMarkup'}
+ return {'markup': ','.join(values), 'io_class': 'IntMarkup'}

class SequenceNumberMarkup(base.SequenceMarkup):

@@ -89,7 +89,7 @@

@classmethod
def from_record(cls, container, record, name=None):
- assert record['io-class'] == 'SequenceCaseMarkup'
+ assert record['io_class'] == 'SequenceCaseMarkup'
result = container.add_markup(name, markup_class=cls)
markup = record['markup']
assert markup[0] == markup[-1] == "'"
@@ -111,7 +111,7 @@
markup += monomer.code1.upper()
elif case == 'lower':
markup += monomer.code1.lower()
- return {'markup': "'%s'" % markup, 'io-class': 'SequenceCaseMarkup'}
+ return {'markup': "'%s'" % markup, 'io_class': 'SequenceCaseMarkup'}

class SequencePdbResiMarkup(base.SequenceMarkup, IntMarkupMixin):
name = 'pdb_resi'