annotate cpt_gbk_compare/gbk_compare.py @ 0:cae700761678 draft

Uploaded
author cpt
date Fri, 01 Jul 2022 13:47:46 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cae700761678 Uploaded
cpt
parents:
diff changeset
1 #!/usr/bin/env python3
cae700761678 Uploaded
cpt
parents:
diff changeset
2 """
cae700761678 Uploaded
cpt
parents:
diff changeset
3 Copyright 2019 Ryan Wick (rrwick@gmail.com)
cae700761678 Uploaded
cpt
parents:
diff changeset
4 https://github.com/rrwick/Compare-annotations/
cae700761678 Uploaded
cpt
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify it under the terms of the GNU
cae700761678 Uploaded
cpt
parents:
diff changeset
6 General Public License as published by the Free Software Foundation, either version 3 of the
cae700761678 Uploaded
cpt
parents:
diff changeset
7 License, or (at your option) any later version.
cae700761678 Uploaded
cpt
parents:
diff changeset
8 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
cae700761678 Uploaded
cpt
parents:
diff changeset
9 even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
cae700761678 Uploaded
cpt
parents:
diff changeset
10 General Public License for more details.
cae700761678 Uploaded
cpt
parents:
diff changeset
11 You should have received a copy of the GNU General Public License along with this program. If not,
cae700761678 Uploaded
cpt
parents:
diff changeset
12 see <https://www.gnu.org/licenses/>.
cae700761678 Uploaded
cpt
parents:
diff changeset
13 """
cae700761678 Uploaded
cpt
parents:
diff changeset
14
cae700761678 Uploaded
cpt
parents:
diff changeset
15 import argparse
cae700761678 Uploaded
cpt
parents:
diff changeset
16 from Bio import SeqIO
cae700761678 Uploaded
cpt
parents:
diff changeset
17 from Bio import pairwise2
cae700761678 Uploaded
cpt
parents:
diff changeset
18 from Bio.pairwise2 import format_alignment
cae700761678 Uploaded
cpt
parents:
diff changeset
19 import itertools
cae700761678 Uploaded
cpt
parents:
diff changeset
20 import sys
cae700761678 Uploaded
cpt
parents:
diff changeset
21
cae700761678 Uploaded
cpt
parents:
diff changeset
22
cae700761678 Uploaded
cpt
parents:
diff changeset
23 def addArr(arrA, arrB):
cae700761678 Uploaded
cpt
parents:
diff changeset
24 res = []
cae700761678 Uploaded
cpt
parents:
diff changeset
25 for x in range(0, min(len(arrA), len(arrB))):
cae700761678 Uploaded
cpt
parents:
diff changeset
26 res.append(arrA[x] + arrB[x])
cae700761678 Uploaded
cpt
parents:
diff changeset
27 return res
cae700761678 Uploaded
cpt
parents:
diff changeset
28
cae700761678 Uploaded
cpt
parents:
diff changeset
29 def get_arguments():
cae700761678 Uploaded
cpt
parents:
diff changeset
30 parser = argparse.ArgumentParser(description='Compare GenBank annotations',
cae700761678 Uploaded
cpt
parents:
diff changeset
31 formatter_class=argparse.ArgumentDefaultsHelpFormatter)
cae700761678 Uploaded
cpt
parents:
diff changeset
32
cae700761678 Uploaded
cpt
parents:
diff changeset
33 parser.add_argument('annotation_1', type=str,
cae700761678 Uploaded
cpt
parents:
diff changeset
34 help='First annotated genome in Genbank format')
cae700761678 Uploaded
cpt
parents:
diff changeset
35 parser.add_argument('annotation_2', type=str,
cae700761678 Uploaded
cpt
parents:
diff changeset
36 help='Second annotated genome in Genbank format')
cae700761678 Uploaded
cpt
parents:
diff changeset
37
cae700761678 Uploaded
cpt
parents:
diff changeset
38
cae700761678 Uploaded
cpt
parents:
diff changeset
39 parser.add_argument('--match_identity_threshold', type=float, default=0.7,
cae700761678 Uploaded
cpt
parents:
diff changeset
40 help='Two genes must have at least this identity to be considerd the same (0.0 to 1.0)')
cae700761678 Uploaded
cpt
parents:
diff changeset
41 parser.add_argument('--allowed_skipped_genes', type=int, default=10,
cae700761678 Uploaded
cpt
parents:
diff changeset
42 help='This many missing genes are allowed when aligning the annotations')
cae700761678 Uploaded
cpt
parents:
diff changeset
43 parser.add_argument("--addNotes", action="store_true", help="Add Note fields")
cae700761678 Uploaded
cpt
parents:
diff changeset
44
cae700761678 Uploaded
cpt
parents:
diff changeset
45 parser.add_argument(
cae700761678 Uploaded
cpt
parents:
diff changeset
46 "-sumOut", type=argparse.FileType("w"), help="Summary out file"
cae700761678 Uploaded
cpt
parents:
diff changeset
47 )
cae700761678 Uploaded
cpt
parents:
diff changeset
48 args = parser.parse_args()
cae700761678 Uploaded
cpt
parents:
diff changeset
49 return args
cae700761678 Uploaded
cpt
parents:
diff changeset
50
cae700761678 Uploaded
cpt
parents:
diff changeset
51
cae700761678 Uploaded
cpt
parents:
diff changeset
52 def main():
cae700761678 Uploaded
cpt
parents:
diff changeset
53 args = get_arguments()
cae700761678 Uploaded
cpt
parents:
diff changeset
54
cae700761678 Uploaded
cpt
parents:
diff changeset
55 # Load in the CDS features from the two assemblies.
cae700761678 Uploaded
cpt
parents:
diff changeset
56 old = SeqIO.parse(args.annotation_1, 'genbank')
cae700761678 Uploaded
cpt
parents:
diff changeset
57 new = SeqIO.parse(args.annotation_2, 'genbank')
cae700761678 Uploaded
cpt
parents:
diff changeset
58 old_record = next(old)
cae700761678 Uploaded
cpt
parents:
diff changeset
59 new_record = next(new)
cae700761678 Uploaded
cpt
parents:
diff changeset
60 old_features, new_features = [], []
cae700761678 Uploaded
cpt
parents:
diff changeset
61 for f in old_record.features:
cae700761678 Uploaded
cpt
parents:
diff changeset
62 if f.type == 'CDS':
cae700761678 Uploaded
cpt
parents:
diff changeset
63 old_features.append(f)
cae700761678 Uploaded
cpt
parents:
diff changeset
64 for f in new_record.features:
cae700761678 Uploaded
cpt
parents:
diff changeset
65 if f.type == 'CDS':
cae700761678 Uploaded
cpt
parents:
diff changeset
66 new_features.append(f)
cae700761678 Uploaded
cpt
parents:
diff changeset
67
cae700761678 Uploaded
cpt
parents:
diff changeset
68 args.sumOut.write('Features in First Genbank\'s assembly:\t' + str(len(old_features)) + "\n")
cae700761678 Uploaded
cpt
parents:
diff changeset
69 args.sumOut.write('Features in Second Genbank\'s assembly:\t' + str(len(new_features)) + "\n\n")
cae700761678 Uploaded
cpt
parents:
diff changeset
70
cae700761678 Uploaded
cpt
parents:
diff changeset
71 # Align the features to each other.
cae700761678 Uploaded
cpt
parents:
diff changeset
72 offsets = sorted(list(itertools.product(range(args.allowed_skipped_genes + 1),
cae700761678 Uploaded
cpt
parents:
diff changeset
73 range(args.allowed_skipped_genes + 1))),
cae700761678 Uploaded
cpt
parents:
diff changeset
74 key=lambda x: x[0]+x[1])
cae700761678 Uploaded
cpt
parents:
diff changeset
75 old_i, new_i = 0, 0
cae700761678 Uploaded
cpt
parents:
diff changeset
76 exactRec = 0
cae700761678 Uploaded
cpt
parents:
diff changeset
77 inexactRec = [0, 0 ,0]
cae700761678 Uploaded
cpt
parents:
diff changeset
78 hypoRec = [0, 0, 0]
cae700761678 Uploaded
cpt
parents:
diff changeset
79 newCount = 0
cae700761678 Uploaded
cpt
parents:
diff changeset
80 oldCount = 0
cae700761678 Uploaded
cpt
parents:
diff changeset
81 if args.addNotes:
cae700761678 Uploaded
cpt
parents:
diff changeset
82 print("First Record CDS Product\tSimilarity\tSecond Record CDS Product\tPercent Identity\tLength Difference\tFirst Gbk's CDS Location\tSecond Gbk's CDS Location\tHypothetical Status\tFirst Record's Notes\tSecond Record's Notes\n")
cae700761678 Uploaded
cpt
parents:
diff changeset
83 else:
cae700761678 Uploaded
cpt
parents:
diff changeset
84 print("First Record CDS Product\tSimilarity\tSecond Record CDS Product\tPercent Identity\tLength Difference\tFirst Gbk's CDS Location\tSecond Gbk's CDS Location\tHypothetical Status\n")
cae700761678 Uploaded
cpt
parents:
diff changeset
85 while True:
cae700761678 Uploaded
cpt
parents:
diff changeset
86 if old_i >= len(old_features) and new_i >= len(new_features):
cae700761678 Uploaded
cpt
parents:
diff changeset
87 break
cae700761678 Uploaded
cpt
parents:
diff changeset
88
cae700761678 Uploaded
cpt
parents:
diff changeset
89 for old_offset, new_offset in offsets:
cae700761678 Uploaded
cpt
parents:
diff changeset
90 try:
cae700761678 Uploaded
cpt
parents:
diff changeset
91 old_feature = old_features[old_i + old_offset]
cae700761678 Uploaded
cpt
parents:
diff changeset
92 except IndexError:
cae700761678 Uploaded
cpt
parents:
diff changeset
93 old_feature = None
cae700761678 Uploaded
cpt
parents:
diff changeset
94 try:
cae700761678 Uploaded
cpt
parents:
diff changeset
95 new_feature = new_features[new_i + new_offset]
cae700761678 Uploaded
cpt
parents:
diff changeset
96 except IndexError:
cae700761678 Uploaded
cpt
parents:
diff changeset
97 new_feature = None
cae700761678 Uploaded
cpt
parents:
diff changeset
98 try:
cae700761678 Uploaded
cpt
parents:
diff changeset
99 match, identity, length_diff = compare_features(old_feature, new_feature, old_record, new_record, args.match_identity_threshold)
cae700761678 Uploaded
cpt
parents:
diff changeset
100 except TypeError:
cae700761678 Uploaded
cpt
parents:
diff changeset
101 break
cae700761678 Uploaded
cpt
parents:
diff changeset
102 if match:
cae700761678 Uploaded
cpt
parents:
diff changeset
103 for j in range(old_offset):
cae700761678 Uploaded
cpt
parents:
diff changeset
104 print_in_old_not_new(old_features[old_i + j])
cae700761678 Uploaded
cpt
parents:
diff changeset
105 oldCount += 1
cae700761678 Uploaded
cpt
parents:
diff changeset
106 for j in range(new_offset):
cae700761678 Uploaded
cpt
parents:
diff changeset
107 print_in_new_not_old(new_features[new_i + j])
cae700761678 Uploaded
cpt
parents:
diff changeset
108 newCount += 1
cae700761678 Uploaded
cpt
parents:
diff changeset
109 if identity == 1.0:
cae700761678 Uploaded
cpt
parents:
diff changeset
110 exactRec += 1
cae700761678 Uploaded
cpt
parents:
diff changeset
111 res1, res2 = print_match(old_features[old_i + old_offset], new_features[new_i + new_offset], identity, length_diff, args.addNotes)
cae700761678 Uploaded
cpt
parents:
diff changeset
112 inexactRec = addArr(inexactRec, res1)
cae700761678 Uploaded
cpt
parents:
diff changeset
113 hypoRec = addArr(hypoRec, res2)
cae700761678 Uploaded
cpt
parents:
diff changeset
114 old_i += old_offset
cae700761678 Uploaded
cpt
parents:
diff changeset
115 new_i += new_offset
cae700761678 Uploaded
cpt
parents:
diff changeset
116 break
cae700761678 Uploaded
cpt
parents:
diff changeset
117 else:
cae700761678 Uploaded
cpt
parents:
diff changeset
118 sys.stderr.write("Exceeded allowed number of skipped genes (" + str(args.allowed_skipped_genes) + "), unable to maintain alignment and continue comparison.\n")
cae700761678 Uploaded
cpt
parents:
diff changeset
119 exit(2)
cae700761678 Uploaded
cpt
parents:
diff changeset
120
cae700761678 Uploaded
cpt
parents:
diff changeset
121 if old_feature is None and new_feature is None:
cae700761678 Uploaded
cpt
parents:
diff changeset
122 break
cae700761678 Uploaded
cpt
parents:
diff changeset
123
cae700761678 Uploaded
cpt
parents:
diff changeset
124 old_i += 1
cae700761678 Uploaded
cpt
parents:
diff changeset
125 new_i += 1
cae700761678 Uploaded
cpt
parents:
diff changeset
126
cae700761678 Uploaded
cpt
parents:
diff changeset
127 args.sumOut.write('Exact Match:\t' + str(exactRec) + "\n\n")
cae700761678 Uploaded
cpt
parents:
diff changeset
128
cae700761678 Uploaded
cpt
parents:
diff changeset
129 args.sumOut.write('Inexact Match:\t' + str(inexactRec[0] + inexactRec[1] + inexactRec[2]) + "\n")
cae700761678 Uploaded
cpt
parents:
diff changeset
130 args.sumOut.write(' Same length:\t' + str(inexactRec[0]) + "\n")
cae700761678 Uploaded
cpt
parents:
diff changeset
131 args.sumOut.write(' Second Gbk Seq longer:\t' + str(inexactRec[2]) + "\n")
cae700761678 Uploaded
cpt
parents:
diff changeset
132 args.sumOut.write(' First Gbk Seq longer:\t' + str(inexactRec[1]) + "\n\n")
cae700761678 Uploaded
cpt
parents:
diff changeset
133
cae700761678 Uploaded
cpt
parents:
diff changeset
134 args.sumOut.write('In Second Gbk but not in first:\t' + str(newCount) + "\n")
cae700761678 Uploaded
cpt
parents:
diff changeset
135 args.sumOut.write('In First Gbk but not in second:\t' + str(oldCount) + "\n\n")
cae700761678 Uploaded
cpt
parents:
diff changeset
136
cae700761678 Uploaded
cpt
parents:
diff changeset
137 args.sumOut.write('Hypothetical Annotation Change:\t' + str(hypoRec[1] + hypoRec[2]) + "\n")
cae700761678 Uploaded
cpt
parents:
diff changeset
138 args.sumOut.write('Hypothetical:\t' + str(hypoRec[0] + hypoRec[2]) + "\n")
cae700761678 Uploaded
cpt
parents:
diff changeset
139
cae700761678 Uploaded
cpt
parents:
diff changeset
140
cae700761678 Uploaded
cpt
parents:
diff changeset
141 def print_match(f1, f2, identity, length_diff, outNotes):
cae700761678 Uploaded
cpt
parents:
diff changeset
142 #print('', flush=True)
cae700761678 Uploaded
cpt
parents:
diff changeset
143 line = f1.qualifiers['product'][0] + "\t"
cae700761678 Uploaded
cpt
parents:
diff changeset
144 matchArr = [0, 0, 0]
cae700761678 Uploaded
cpt
parents:
diff changeset
145 hypoArr = [0, 0, 0]
cae700761678 Uploaded
cpt
parents:
diff changeset
146 if identity == 1.0:
cae700761678 Uploaded
cpt
parents:
diff changeset
147 # print('Exact match')
cae700761678 Uploaded
cpt
parents:
diff changeset
148 line += 'Exact match\t' + f2.qualifiers['product'][0] + "\t100.0\tSame Length\t"
cae700761678 Uploaded
cpt
parents:
diff changeset
149 else:
cae700761678 Uploaded
cpt
parents:
diff changeset
150 # print('Inexact match (' + '%.2f' % (identity * 100.0) + '% ID, ', end='')
cae700761678 Uploaded
cpt
parents:
diff changeset
151 line += 'Inexact match\t' + f2.qualifiers['product'][0] + "\t%.2f\t" % (identity * 100.0)
cae700761678 Uploaded
cpt
parents:
diff changeset
152 if length_diff == 0:
cae700761678 Uploaded
cpt
parents:
diff changeset
153 # print('same length)')
cae700761678 Uploaded
cpt
parents:
diff changeset
154 line +="Same Length\t"
cae700761678 Uploaded
cpt
parents:
diff changeset
155 matchArr[0] += 1
cae700761678 Uploaded
cpt
parents:
diff changeset
156 elif length_diff > 0:
cae700761678 Uploaded
cpt
parents:
diff changeset
157 # print('old seq longer)')
cae700761678 Uploaded
cpt
parents:
diff changeset
158 line +="First Gbk Seq Longer\t"
cae700761678 Uploaded
cpt
parents:
diff changeset
159 matchArr[1] += 1
cae700761678 Uploaded
cpt
parents:
diff changeset
160 elif length_diff < 0:
cae700761678 Uploaded
cpt
parents:
diff changeset
161 # print('new seq longer)')
cae700761678 Uploaded
cpt
parents:
diff changeset
162 line +="Second Gbk Seq Longer\t"
cae700761678 Uploaded
cpt
parents:
diff changeset
163 matchArr[2] += 1
cae700761678 Uploaded
cpt
parents:
diff changeset
164 # print(' old: ', end='')
cae700761678 Uploaded
cpt
parents:
diff changeset
165 # print_feature_one_line(f1)
cae700761678 Uploaded
cpt
parents:
diff changeset
166 line += print_feature_one_line(f1) + "\t"
cae700761678 Uploaded
cpt
parents:
diff changeset
167 # print(' new: ', end='')
cae700761678 Uploaded
cpt
parents:
diff changeset
168 # print_feature_one_line(f2)
cae700761678 Uploaded
cpt
parents:
diff changeset
169 line += print_feature_one_line(f2) + "\t"
cae700761678 Uploaded
cpt
parents:
diff changeset
170 p1 = f1.qualifiers['product'][0].lower()
cae700761678 Uploaded
cpt
parents:
diff changeset
171 p2 = f2.qualifiers['product'][0].lower()
cae700761678 Uploaded
cpt
parents:
diff changeset
172 if 'hypothetical' in p1 and 'hypothetical' in p2:
cae700761678 Uploaded
cpt
parents:
diff changeset
173 # print(' still hypothetical')
cae700761678 Uploaded
cpt
parents:
diff changeset
174 line += "Hypothetical\t"
cae700761678 Uploaded
cpt
parents:
diff changeset
175 hypoArr[0] += 1
cae700761678 Uploaded
cpt
parents:
diff changeset
176 elif 'hypothetical' in p1 and 'hypothetical' not in p2:
cae700761678 Uploaded
cpt
parents:
diff changeset
177 # print(' no longer hypothetical')
cae700761678 Uploaded
cpt
parents:
diff changeset
178 line += "No Longer Hypothetical\t"
cae700761678 Uploaded
cpt
parents:
diff changeset
179 hypoArr[1] += 1
cae700761678 Uploaded
cpt
parents:
diff changeset
180 elif 'hypothetical' not in p1 and 'hypothetical' in p2:
cae700761678 Uploaded
cpt
parents:
diff changeset
181 # print(' became hypothetical')
cae700761678 Uploaded
cpt
parents:
diff changeset
182 line += "Became Hypothetical\t"
cae700761678 Uploaded
cpt
parents:
diff changeset
183 hypoArr[2] += 1
cae700761678 Uploaded
cpt
parents:
diff changeset
184 else:
cae700761678 Uploaded
cpt
parents:
diff changeset
185 line += "'Hypothetical' not in second nor first Gbk's product tag"
cae700761678 Uploaded
cpt
parents:
diff changeset
186
cae700761678 Uploaded
cpt
parents:
diff changeset
187 if outNotes:
cae700761678 Uploaded
cpt
parents:
diff changeset
188 line += "\t"
cae700761678 Uploaded
cpt
parents:
diff changeset
189 if "note" in f1.qualifiers.keys():
cae700761678 Uploaded
cpt
parents:
diff changeset
190 for x in f1.qualifiers["note"]:
cae700761678 Uploaded
cpt
parents:
diff changeset
191 line += x
cae700761678 Uploaded
cpt
parents:
diff changeset
192 line += "\t"
cae700761678 Uploaded
cpt
parents:
diff changeset
193 else:
cae700761678 Uploaded
cpt
parents:
diff changeset
194 line += "N/A\t"
cae700761678 Uploaded
cpt
parents:
diff changeset
195 if "note" in f2.qualifiers.keys():
cae700761678 Uploaded
cpt
parents:
diff changeset
196 for x in f2.qualifiers["note"]:
cae700761678 Uploaded
cpt
parents:
diff changeset
197 line += x
cae700761678 Uploaded
cpt
parents:
diff changeset
198 else:
cae700761678 Uploaded
cpt
parents:
diff changeset
199 line += "N/A"
cae700761678 Uploaded
cpt
parents:
diff changeset
200
cae700761678 Uploaded
cpt
parents:
diff changeset
201 print(line)
cae700761678 Uploaded
cpt
parents:
diff changeset
202 return matchArr, hypoArr
cae700761678 Uploaded
cpt
parents:
diff changeset
203
cae700761678 Uploaded
cpt
parents:
diff changeset
204 def print_in_old_not_new(f): # rename file outputs
cae700761678 Uploaded
cpt
parents:
diff changeset
205 line = f.qualifiers['product'][0] + "\tIn First Gbk but not Second\tN/A\t0.00\t" + str(f.location.end - f.location.start) + "\t" + print_feature_one_line(f) + "\tN/A\tN/A"
cae700761678 Uploaded
cpt
parents:
diff changeset
206 # print('')
cae700761678 Uploaded
cpt
parents:
diff changeset
207 # print('In old but not in new:')
cae700761678 Uploaded
cpt
parents:
diff changeset
208 # print(' ', end='')
cae700761678 Uploaded
cpt
parents:
diff changeset
209 # print_feature_one_line(f)
cae700761678 Uploaded
cpt
parents:
diff changeset
210 print(line)
cae700761678 Uploaded
cpt
parents:
diff changeset
211
cae700761678 Uploaded
cpt
parents:
diff changeset
212
cae700761678 Uploaded
cpt
parents:
diff changeset
213 def print_in_new_not_old(f): # rename file outputs
cae700761678 Uploaded
cpt
parents:
diff changeset
214 line = "N/A\tIn Second Gbk but not First\t" + f.qualifiers['product'][0] + "\t0.00\t" + str(f.location.end - f.location.start) + "\tN/A\t" + print_feature_one_line(f) + "\tN/A"
cae700761678 Uploaded
cpt
parents:
diff changeset
215 #print('')
cae700761678 Uploaded
cpt
parents:
diff changeset
216 #print('In new but not in old:')
cae700761678 Uploaded
cpt
parents:
diff changeset
217 #print(' ', end='')
cae700761678 Uploaded
cpt
parents:
diff changeset
218 #print_feature_one_line(f)
cae700761678 Uploaded
cpt
parents:
diff changeset
219 print(line)
cae700761678 Uploaded
cpt
parents:
diff changeset
220
cae700761678 Uploaded
cpt
parents:
diff changeset
221
cae700761678 Uploaded
cpt
parents:
diff changeset
222 def print_feature_one_line(f):
cae700761678 Uploaded
cpt
parents:
diff changeset
223 #f_str = f.qualifiers['product'][0]
cae700761678 Uploaded
cpt
parents:
diff changeset
224 f_str = ""
cae700761678 Uploaded
cpt
parents:
diff changeset
225 strand = '+' if f.location.strand == 1 else '-'
cae700761678 Uploaded
cpt
parents:
diff changeset
226 f_str += '(' + str(f.location.start) + '-' + str(f.location.end) + ' ' + strand + ', '
cae700761678 Uploaded
cpt
parents:
diff changeset
227 f_str += str(f.location.end - f.location.start) + ' bp)'
cae700761678 Uploaded
cpt
parents:
diff changeset
228 return(f_str)
cae700761678 Uploaded
cpt
parents:
diff changeset
229
cae700761678 Uploaded
cpt
parents:
diff changeset
230
cae700761678 Uploaded
cpt
parents:
diff changeset
231 def compare_features(f1, f2, r1, r2, match_identity_threshold):
cae700761678 Uploaded
cpt
parents:
diff changeset
232 if f1 is None or f2 is None:
cae700761678 Uploaded
cpt
parents:
diff changeset
233 return False
cae700761678 Uploaded
cpt
parents:
diff changeset
234
cae700761678 Uploaded
cpt
parents:
diff changeset
235 s1 = f1.extract(r1).seq
cae700761678 Uploaded
cpt
parents:
diff changeset
236 s2 = f2.extract(r2).seq
cae700761678 Uploaded
cpt
parents:
diff changeset
237 score = pairwise2.align.globalms(s1, s2, 1, 0, 0, 0, score_only=True)
cae700761678 Uploaded
cpt
parents:
diff changeset
238 identity = score / max(len(s1), len(s2))
cae700761678 Uploaded
cpt
parents:
diff changeset
239 match = identity >= match_identity_threshold
cae700761678 Uploaded
cpt
parents:
diff changeset
240 length_diff = len(s1) - len(s2)
cae700761678 Uploaded
cpt
parents:
diff changeset
241 return match, identity, length_diff
cae700761678 Uploaded
cpt
parents:
diff changeset
242
cae700761678 Uploaded
cpt
parents:
diff changeset
243
cae700761678 Uploaded
cpt
parents:
diff changeset
244 if __name__ == '__main__':
cae700761678 Uploaded
cpt
parents:
diff changeset
245 main()