view test/usecase2.py @ 350:0411fa851bba
Fixed references to base interface according to previous changes (closes #12)
author |
Daniil Alexeyevsky <me.dendik@gmail.com> |
date |
Fri, 21 Jan 2011 15:00:23 +0300 |
parents |
cc9f4972ea46 |
children |
bed32775625a |
line source
1 # Fragments are in pair_repeat.fasta
6 def my_column_mark(column, threshold):
7 """Helper to mark column (given as dict) by identity."""
9 for sequence, monomer in column:
11 count[code] = count.get(code, 0) + 1
13 if count[code] > threshold:
17 def my_pair_mark(column):
18 """Helper to mark column of 2 sequences (given as list) by identity."""
19 if column[0] is None or column[1] is None:
21 if column[0].code1 == column[0].code1:
25 def find_runs(markup):
26 """Fund long positive runs.
28 This obscure and probably broken function has nothing to do with allpy,
29 so it's presence in the example is unnecessary.
34 for i in range(len(markup)):
41 if markup[i-width] == "+":
44 plus_positions.append(position)
45 if len(plus_positions)==0:
46 raise Exception("No blocks in alignment")
49 start = plus_positions[0]-width + 1
50 stop = plus_positions[0]
51 for p in plus_positions[1:]:
55 blocks.append((start,stop))
61 alignment = dna.Alignment.from_file(open("pair_repeat.fasta"))
62 if len(alignment.sequences) != 2:
63 raise Exception("Input must have exactly 2 sequences!")
64 alignment.realign("needle", gap_open = 0)
66 for column in alignment.columns_as_lists():
67 markup.append(my_pair_mark(column))
68 markup = alignment.map_columns(my_pair_mark)
69 print find_runs(markup)
74 print "An error has occured:", e