[aligner] Let the user decide on wheter return the global alignement matrix or not
authorSimon Chabot <simon.chabot@logilab.fr>
Wed, 14 Nov 2012 10:27:57 +0100
changeset 130 79d506091e46
parent 129 7120da9101de
child 131 ee8d9adac929
[aligner] Let the user decide on wheter return the global alignement matrix or not
aligner.py
--- a/aligner.py	Wed Nov 14 09:40:30 2012 +0100
+++ b/aligner.py	Wed Nov 14 10:27:57 2012 +0100
@@ -190,7 +190,7 @@
 
             `resultfile` (default is None). Write the matched elements in a file.
 
-    Return the distance matrix and the matched list.
+        Return the distance matrix and the matched list.
     """
     treatments = treatments or {}
 
@@ -228,13 +228,15 @@
 
 def conquer_and_divide_alignment(alignset, targetset, threshold, treatments=None,
                                  indexes=(1,1), mode='kdtree', neighbours_threshold=0.1,
-                                 n_clusters=None, kwordsgram=1, siglen=200):
+                                 n_clusters=None, kwordsgram=1, siglen=200,
+                                 get_global_mat=True):
     """ Full conquer and divide method for alignment.
     Compute neighbours and merge the different subalignments.
     XXX
     """
     global_matched = {}
-    global_mat = lil_matrix((len(alignset), len(targetset)))
+    if get_global_mat:
+        global_mat = lil_matrix((len(alignset), len(targetset)))
     for alignind, targetind in findneighbours(alignset, targetset, indexes, mode,
                                               neighbours_threshold, n_clusters, kwordsgram, siglen):
         mat, matched = subalign(alignset, targetset, alignind, targetind, threshold, treatments)
@@ -243,5 +245,8 @@
             for v, d in values:
                 subdict.add((v, d))
                 # XXX avoid issue in sparse matrix
-                global_mat[k, v] = d or 10**(-10)
-    return global_mat, global_matched
+                if get_global_mat:
+                    global_mat[k, v] = d or 10**(-10)
+    if get_global_mat:
+        return global_mat, global_matched
+    return global_matched