allpy
changeset 835:bbe1b872e424
convert_homology: mapping of column numbers was totally wrong; fixed
author | Daniil Alexeyevsky <dendik@kodomo.fbb.msu.ru> |
---|---|
date | Mon, 18 Jul 2011 19:53:06 +0400 |
parents | 0dc6d90af0cf |
children | 7de42d758354 |
files | utils/convert_homology.py |
diffstat | 1 files changed, 18 insertions(+), 15 deletions(-) [+] |
line diff
1.1 --- a/utils/convert_homology.py Mon Jul 18 19:26:21 2011 +0400 1.2 +++ b/utils/convert_homology.py Mon Jul 18 19:53:06 2011 +0400 1.3 @@ -23,6 +23,22 @@ 1.4 seq2_number = str(column[seq2].number) 1.5 mon_map[seq1.name, seq1_number] = seq2_number 1.6 1.7 +def col2_num(seq1_name, mon1_num, col1_num): 1.8 + key = seq1_name, str(mon1_num) 1.9 + if key not in mon_map: 1.10 + return 1.11 + seq2_name = seq1_name + "_2" 1.12 + mon2_num = int(mon_map[key]) 1.13 + for seq2 in aln2.sequences: 1.14 + if seq2.name != seq2_name: 1.15 + continue 1.16 + mon2 = seq2[mon2_num - 1] 1.17 + for col2 in aln2.columns: 1.18 + if seq2 in col2 and col2[seq2] is mon2: 1.19 + return aln2_num[col2] 1.20 + return 1.21 + raise AssertionError, "seq2_name %s not found" % seq2_name 1.22 + 1.23 col_map = {} 1.24 aln1_num = aln1.add_markup('number') 1.25 aln2_num = aln2.add_markup('number') 1.26 @@ -33,22 +49,9 @@ 1.27 continue 1.28 if seq1 not in col1: 1.29 continue 1.30 - key = seq1.name, str(col1[seq1].number) 1.31 - if key not in mon_map: 1.32 - continue 1.33 - num2 = None 1.34 - try: 1.35 - for seq2 in aln2.sequences: 1.36 - if seq2.name.startswith(seq1.name): 1.37 - mon2 = seq2[col1[seq1].number] 1.38 - for col2 in aln2.columns: 1.39 - if col2[seq2] is mon2: 1.40 - num2 = str(aln2_num[col2]) 1.41 - raise Exception 1.42 - except Exception: 1.43 - pass 1.44 + num2 = col2_num(seq1.name, col1[seq1].number, aln1_num[col1]) 1.45 if num2 is not None: 1.46 - col_map[num1] = num2 1.47 + col_map[num1] = str(num2) 1.48 1.49 print sorted(col_map.items(), key=lambda (a,b): int(a)) 1.50