Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/file/505ce122068b/lib/block.py
Дата изменения: Unknown
Дата индексирования: Sun Feb 3 17:59:50 2013
Кодировка:
allpy: 505ce122068b lib/block.py

allpy

view lib/block.py @ 9:505ce122068b

Generalized tcl examples in the sandbox.
author Danya Alexeyevsky <me.dendik@gmail.com>
date Thu, 10 Jun 2010 14:24:08 +0400
parents 757f2a1f8732
children 217d83a617c3
line source
1 #!usr/bin/python
3 import sys
5 import project
6 import sequence
7 import monomer
9 class Block(object):
10 """
11 Mandatory data:
12 * self.project -- project object, which the block belongs to
13 * self.sequences - set of sequence objects that contain monomers
14 and/or gaps, that constitute the block
15 * self.positions -- list of positions of the project.alignment that
16 are included in the block
18 How to create a new block:
19 >>> import project
20 >>> import block
21 >>> proj = project.Project(open("test.fasta"))
22 >>> block1 = block.Block(proj, proj.sequences, range(len(proj.alignment[proj.sequences[0]])))
24 """
26 def __init__(self,project,sequences,positions):
27 self.project=project
28 self.sequences=sequences
29 self.positions=positions
31 def to_fasta(self,file):
32 """writes the block as an alignment in fasta-format into the file.
34 No changes in the names, descriptions or order of the sequences
35 are made.
37 """
38 for sequence in self.sequences:
39 file.write(">%s %s\n"%(sequence.name,sequence.description))
40 string_index=0
41 for position in self.positions:
42 if string_index>=60:
43 file.write("\n")
44 string_index=0
45 if self.project.alignment[sequence][position]==None:
46 file.write("-")
47 string_index+=1
48 else:
49 file.write(self.project.alignment[sequence][position].code)
50 string_index+=1
51 file.write("\n")