[aligner] Make the alignall() function
authorSimon Chabot <simon.chabot@logilab.fr>
Wed, 14 Nov 2012 10:50:31 +0100
changeset 131 ee8d9adac929
parent 130 79d506091e46
child 132 7b1e5eccfcdf
[aligner] Make the alignall() function
aligner.py
--- a/aligner.py	Wed Nov 14 10:27:57 2012 +0100
+++ b/aligner.py	Wed Nov 14 10:50:31 2012 +0100
@@ -250,3 +250,22 @@
     if get_global_mat:
         return global_mat, global_matched
     return global_matched
+
+def alignall(alignset, targetset, threshold, treatments=None,
+             indexes=(1,1), mode='kdtree', neighbours_threshold=0.1,
+             n_clusters=None, kwordsgram=1, siglen=200, uniq=False):
+
+    matched = conquer_and_divide_alignment(alignset, targetset,
+                                           threshold, treatments, indexes, mode,
+                                           neighbours_threshold,
+                                           n_clusters, kwordsgram,
+                                           siglen, get_global_mat=False)
+
+    if not uniq:
+        for alignid in matched:
+            for targetid, dist in matched[alignid]:
+                yield alignset[alignid][0], targetset[targetid][0]
+    else:
+        for alignid in matched:
+            bestid, dist = sorted(matched[alignid], key=lambda x:x[1])[0]
+            yield alignset[alignid][0], targetset[bestid][0]