Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/file/36095a51e4c0/test/usecase3.py
Дата изменения: Unknown
Дата индексирования: Mon Feb 4 05:12:06 2013
Кодировка:
allpy: 36095a51e4c0 test/usecase3.py

allpy

view test/usecase3.py @ 444:36095a51e4c0

Tested and fixed Block.process(*, False, False) In this ivokation process only copies gap patterns, not sequence names. It is equivalent to calling Block._replace_column_contents. Previously this function assumed self is Alignment and that each monomer in self.sequences is visible in columns. This is false for Blocks.
author Daniil Alexeyevsky <dendik@kodomo.fbb.msu.ru>
date Tue, 15 Feb 2011 22:45:34 +0300
parents efca47965dc3
children e7d60bf1dfd8
line source
1 from allpy import protein
2 alignment = protein.Alignment().append_file(open("aln.fasta"))
3 #conservative = [(10,20), (40,50)]
4 conservative = [(0,6),(18,37)]
6 def ranges_to_markup(ranges):
7 """Convert list of ranges to line of markup.
9 This has nothing to do with allpy.
10 """
11 markup = ["-"] * len(alignment.columns)
12 for begin, end in ranges:
13 for i in range(begin, end+1):
14 markup[i] = "+"
15 return "".join(markup)
17 def markup_to_blocks(markup):
18 """Convert markup line to a bunch of blocks, one for each sequential run."""
19 current = None
20 blocks = {}
21 for mark, column in zip(markup, alignment.columns):
22 if mark != current:
23 block = protein.Block.from_alignment(alignment, columns=[])
24 blocks[mark] = blocks.get(mark, []) + [block]
25 current = mark
26 blocks[mark][-1].columns.append(column)
27 return blocks
29 def main():
30 markup = ranges_to_markup(conservative)
31 blocks = markup_to_blocks(markup)
32 for block in blocks["-"]:
33 block.flush("left")
34 alignment.to_file(open("output.fasta", "w"))
36 main()