allpy
view allpy/fileio.py @ 900:7ebba94eece2
MarkupIOMixin: added attribute quotes to allow quotation around markup serialized string; fixed implementation of SequenceCaseMarkup based on that; [closes #125]
author | Daniil Alexeyevsky <dendik@kodomo.fbb.msu.ru> |
---|---|
date | Tue, 11 Oct 2011 17:21:44 +0400 |
parents | 6cc007e68af6 |
children |
line source
11 pass
14 """This ugly helper is to avoid bad untimely import loops."""
19 """Automatical file IO."""
34 """Some helpers."""
43 """Append alignment to the file."""
47 )
50 """Read alignment from the file."""
57 """Fasta parser & writer."""
60 """Append one sequence to file."""
73 """Write sequences to file.
75 Sequences are given as list of tuples (string, name, description).
76 """
81 """Read parts beginning with > in FASTA file.
83 This is a drop-in replacement for self.file.read().split("\n>")
84 It is required for markup format, which combines parts read with
85 different parsers. Python prohibits combining iterators and file.read
86 methods on the same file.
87 """
107 """Parser & writer for our own marked alignment file format.
109 Marked alignment file consists of a list of records, separated with one or
110 more empty lines. Each record consists of type name, header and optional
111 contents. Type name is a line, containing just one word, describing the
112 record type. Header is a sequence of lines, each in format `key: value`.
113 Content, if present, is separated from header with an empty line.
115 Type names and header key names are case-insensitive and '-' and '_' in
116 them are equivalent.
118 Known record types now are:
120 - `alignment` -- this must be the last record in file for now
121 - `sequence_markup`
122 - `alignment_markup`
124 Example::
126 sequence-markup
127 sequence-name: cyb5_mouse
128 sequence-description:
129 name: pdb_residue_number
130 type: SequencePDBResidueNumberMarkup
131 markup: -,12,121,122,123,124,13,14,15,-,-,16
133 alignment-markup
134 name: geometrical_core
135 type: AlignmentGeometricalCoreMarkup
136 markup: -,-,-,-,+,+,+,-,-,-,+,+,-,-,-,-
138 alignment
139 format: fasta
141 > cyb5_mouse
142 seqvencemouse
143 """
146 """Helper attribute for write_empty_line."""
149 """Write alignment to file."""
155 }
163 """Write a dictionary of markups as series of records."""
166 continue
175 """Write record to file. Add new line before every but first record."""
184 """Add empty line every time except the first call."""
189 """Read alignment from file."""
195 """Found sequence markup record in file. Do something about it."""
203 return
207 """Found alignment markup record in file. Do something about it."""
212 """Found alignment record. It has been handled in read_payload."""
213 pass
216 """Read records and return them as a list of dicts."""
219 continue
223 """Read record headers and record payload."""
237 """Read record payload, if necessary."""
242 @staticmethod
250 """Parser & writer for file formats supporte by Bio python."""
252 @staticmethod
254 """Tell what formats this method supports."""
258 )
261 """Write sequences to file."""
267 )
269 ])
273 """Read sequences from file."""
278 """Parser & writer for file formats supported by EMBOSS."""
281 """Write sequences to file."""
284 )
291 """EMBOSS does not permit : in file names. Fix sequences for that."""
296 """Read sequences from file."""
299 )
305 # vim: set et ts=4 sts=4 sw=4: