allpy
view allpy/base.py @ 289:d7ad71def6c8
Experimenting with styles of docstrings in allpy.base.Alignment (to be recognized by Sphinx)
author | Daniil Alexeyevsky <me.dendik@gmail.com> |
---|---|
date | Thu, 16 Dec 2010 01:25:54 +0300 |
parents | 9c68d8eab8f5 |
children | 751048390c45 |
line source
14 """Class of monomer types.
16 Each MonomerType object represents a known monomer type, e.g. Valine,
17 and is referenced to by each instance of monomer in a given sequence.
19 - `name`: full name of monomer type
20 - `code1`: one-letter code
21 - `code3`: three-letter code
22 - `is_modified`: either of True or False
24 class atributes:
26 - `by_code1`: a mapping from one-letter code to MonomerType object
27 - `by_code3`: a mapping from three-letter code to MonomerType object
28 - `by_name`: a mapping from monomer name to MonomerType object
29 - `instance_type`: class of Monomer objects to use when creating new
30 objects; this must be redefined in descendent classes
32 All of the class attributes MUST be redefined when subclassing.
33 """
49 # We duplicate distinguished long names into MonomerType itself,
50 # so that we can use MonomerType.from_code3 to create the relevant
51 # type of monomer.
55 @classmethod
57 """Create all relevant instances of MonomerType.
59 `type_letter` is either of:
61 - 'p' for protein
62 - 'd' for DNA
63 - 'r' for RNA
65 `codes` is a table of monomer codes
66 """
71 @classmethod
73 """Return monomer type by one-letter code."""
76 @classmethod
78 """Return monomer type by three-letter code."""
81 @classmethod
83 """Return monomer type by name."""
87 """Create a new monomer of given type."""
96 """Monomer object.
98 attributes:
100 - `type`: type of monomer (a MonomerType object)
102 class attributes:
104 - `monomer_type`: either MonomerType or one of it's subclasses, it is used
105 when creating new monomers. It SHOULD be redefined when subclassing
106 Monomer.
107 """
113 @classmethod
117 @classmethod
121 @classmethod
131 """Sequence of Monomers.
133 This behaves like list of monomer objects. In addition to standard list
134 behaviour, Sequence has the following attributes:
136 * name -- str with the name of the sequence
137 * description -- str with description of the sequence
138 * source -- str denoting source of the sequence
140 Any of them may be empty (i.e. hold empty string)
142 Class attributes:
144 * monomer_type -- type of monomers in sequence, must be redefined when
145 subclassing
146 """
166 """Returns sequence in one-letter code."""
169 @classmethod
171 """Create sequences from string of one-letter codes."""
176 @classmethod
178 """Read sequence from FASTA file.
180 File must contain exactly one sequence.
181 """
188 """Alignment. Behaves like a list of Columns."""
191 """Type of sequences in alignment. SHOULD be redefined when subclassing."""
194 """Ordered list of sequences in alignment. Read, but DO NOT FIDDLE!"""
197 """Initialize empty alignment."""
202 """Add row from a line of one-letter codes and gaps."""
211 @classmethod
213 """Create new alignment from FASTA file."""
220 """Return width, ie length of each sequence with gaps."""
224 """ The number of sequences in alignment (it's thickness). """
228 """ Calculate the identity of alignment positions for colouring.
230 For every (row, column) in alignment the percentage of the exactly
231 same residue in the same column in the alignment is calculated.
232 The data structure is just like the Alignment.body, but istead of
233 monomers it contains float percentages.
234 """
235 # Oh, God, that's awful! Absolutely not understandable.
236 # First, calculate percentages of amino acids in every column
252 # Second, map these percentages onto the alignment
266 @staticmethod
268 """ Constructs new alignment from sequences
270 Add None's to right end to make equal lengthes of alignment sequences
271 """
281 """ Saves alignment to given file
283 Splits long lines to substrings of length=long_line
284 To prevent this, set long_line=None
285 """
289 """ Simple align ths alignment using sequences (muscle)
291 uses old Monomers and Sequences objects
292 """
317 """ returns list of columns of alignment
319 sequence or sequences:
320 * if sequence is given, then column is (original_monomer, monomer)
321 * if sequences is given, then column is (original_monomer, {sequence: monomer})
322 * if both of them are given, it is an error
324 original (Sequence type):
325 * if given, this filters only columns represented by original sequence
326 """
342 """ Returns string representing secondary structure """
348 """ Block of alignment
350 Mandatory data:
352 * self.alignment -- alignment object, which the block belongs to
353 * self.sequences - set of sequence objects that contain monomers
354 and/or gaps, that constitute the block
355 * self.positions -- list of positions of the alignment.body that
356 are included in the block; position[i+1] is always to the right from position[i]
358 Don't change self.sequences -- it may be a link to other block.sequences
360 How to create a new block:
362 >>> import alignment
363 >>> import block
364 >>> proj = alignment.Alignment(open("test.fasta"))
365 >>> block1 = block.Block(proj)
366 """
369 """ Builds new block from alignment
371 if sequences==None, all sequences are used
372 if positions==None, all positions are used
373 """
383 """ Saves alignment to given file in fasta-format
385 No changes in the names, descriptions or order of the sequences
386 are made.
387 """
398 """ Returns length-sorted list of blocks, representing GCs
400 * max_delta -- threshold of distance spreading
401 * timeout -- Bron-Kerbosh timeout (then fast O(n ln n) algorithm)
402 * minsize -- min size of each core
403 * ac_new_atoms -- min part or new atoms in new alternative core
404 current GC is compared with each of already selected GCs if
405 difference is less then ac_new_atoms, current GC is skipped
406 difference = part of new atoms in current core
407 * ac_count -- max number of cores (including main core)
408 -1 means infinity
410 If more than one pdb chain for some sequence provided, consider all of them
411 cost is calculated as 1 / (delta + 1)
413 delta in [0, +inf) => cost in (0, 1]
414 """
442 break
446 break
450 """ Returns string consisting of gap chars and chars x at self.positions
452 Length of returning string = length of alignment
453 """
460 """ Save xstring and name in fasta format """
464 """ Iterates monomers of this sequence from this block """
469 """ Iterates Ca-atom of monomers of this sequence from this block """
473 """ Iterates pairs (sequence, chain) """
480 """ Superimpose all pdb_chains in this block """
489 # Apply rotation/translation to the moving atoms
493 """ Save all sequences
495 Returns {(sequence, chain): CHAIN}
496 CHAIN is chain letter in new file
497 """
503 # TODO: read from tmp_file.name
504 # change CHAIN
505 # add to out_file
509 # vim: set ts=4 sts=4 sw=4 et: