allpy
changeset 307:237deca17963
Converted docstrings and init of base.Block to match our plan
author | Daniil Alexeyevsky <me.dendik@gmail.com> |
---|---|
date | Thu, 16 Dec 2010 20:42:42 +0300 |
parents | 88631907f23d |
children | 4d610c277281 |
files | allpy/base.py |
diffstat | 1 files changed, 28 insertions(+), 28 deletions(-) [+] |
line diff
1.1 --- a/allpy/base.py Thu Dec 16 19:24:22 2010 +0300 1.2 +++ b/allpy/base.py Thu Dec 16 20:42:42 2010 +0300 1.3 @@ -336,43 +336,43 @@ 1.4 """ 1.5 pass 1.6 1.7 - ## Unclean code follows 1.8 +class Block(object): 1.9 + """Block of alignment. 1.10 1.11 -class Block(object): 1.12 - """ Block of alignment 1.13 - 1.14 - Mandatory data: 1.15 - 1.16 - * self.alignment -- alignment object, which the block belongs to 1.17 - * self.sequences - set of sequence objects that contain monomers 1.18 - and/or gaps, that constitute the block 1.19 - * self.positions -- list of positions of the alignment.body that 1.20 - are included in the block; position[i+1] is always to the right from position[i] 1.21 - 1.22 - Don't change self.sequences -- it may be a link to other block.sequences 1.23 - 1.24 - How to create a new block: 1.25 - 1.26 - >>> import alignment 1.27 - >>> import block 1.28 - >>> proj = alignment.Alignment(open("test.fasta")) 1.29 - >>> block1 = block.Block(proj) 1.30 + Block is intersection of a set of columns & a set of rows. Most of blocks 1.31 + look like rectangular part of alignment if you shuffle alignment rows the 1.32 + right way. 1.33 """ 1.34 1.35 - def __init__(self, alignment, sequences=None, positions=None): 1.36 - """ Builds new block from alignment 1.37 + alignment = None 1.38 + """Alignment the block belongs to.""" 1.39 1.40 - if sequences==None, all sequences are used 1.41 - if positions==None, all positions are used 1.42 + sequences = () 1.43 + """List of sequences in block.""" 1.44 + 1.45 + columns = () 1.46 + """List of columns in block.""" 1.47 + 1.48 + def __init__(self, alignment, sequences=None, columns=None): 1.49 + """Build new block from alignment. 1.50 + 1.51 + If sequences are not given, the block uses all sequences in alignment. 1.52 + 1.53 + If columns are not given, the block uses all columns in alignment. 1.54 + 1.55 + In both cases we use exactly the list used in alignment, thus, if new 1.56 + sequences or columns are added to alignment, the block tracks this too. 1.57 """ 1.58 - if sequences == None: 1.59 - sequences = set(alignment.sequences) # copy 1.60 - if positions == None: 1.61 - positions = range(len(alignment)) 1.62 + if sequences is None: 1.63 + sequences = alignment.sequences 1.64 + if colums is None: 1.65 + columns = alignment.columns 1.66 self.alignment = alignment 1.67 self.sequences = sequences 1.68 self.positions = positions 1.69 1.70 + ## Unclean code follows 1.71 + 1.72 def save_fasta(self, out_file, long_line=70, gap='-'): 1.73 """ Saves alignment to given file in fasta-format 1.74