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.
11 markup = ["-"] * len(alignment.columns)
12 for begin, end in ranges:
13 for i in range(begin, end+1):
15 return "".join(markup)
17 def markup_to_blocks(markup):
18 """Convert markup line to a bunch of blocks, one for each sequential run."""
21 for mark, column in zip(markup, alignment.columns):
23 block = protein.Block.from_alignment(alignment, columns=[])
24 blocks[mark] = blocks.get(mark, []) + [block]
26 blocks[mark][-1].columns.append(column)
30 markup = ranges_to_markup(conservative)
31 blocks = markup_to_blocks(markup)
32 for block in blocks["-"]:
34 alignment.to_file(open("output.fasta", "w"))