[API] Write results according to csv format
authorSimon Chabot <simon.chabot@logilab.fr>
Mon, 29 Oct 2012 15:19:09 +0100
changeset 61 72614ee36ea2
parent 60 8b2e1146fccd
child 62 c05fe3386919
[API] Write results according to csv format
alignment.py
--- a/alignment.py	Mon Oct 29 15:07:22 2012 +0100
+++ b/alignment.py	Mon Oct 29 15:19:09 2012 +0100
@@ -104,10 +104,15 @@
         return
 
     with open(resultfile, 'w') as fobj:
-        for cible in matched:
-            fobj.write('%s, %s\n' % (ralignset[cible][0],
-                                   ', '.join((str(rtargetset[target][0])
-                                              for target, _ in matched[cible]))))
+        fobj.write('aligned;targetted;distance\n')
+        for aligned in matched:
+            for target, dist in matched[aligned]:
+                fobj.write('%s;%s;%s\n' %
+                    (ralignset[aligned][0],
+                     rtargetset[target][0],
+                     dist
+                    ))
+
 if __name__ == '__main__':
     alignquery = 'Any P, BP ORDERBY(RANDOM()) LIMIT 100 WHERE P is Person, ' \
                  'P birthplace BP, NOT BP is NULL'