diff toolSelenzyme.py @ 23:635b76a9bd7a draft

planemo upload commit 6f56159bc3cd5339f88517f6822240410bc9e4dd-dirty
author pablocarb
date Fri, 05 Jul 2019 06:26:22 -0400
parents ac027c9ace4d
children
line wrap: on
line diff
--- a/toolSelenzyme.py	Fri Jun 14 12:14:23 2019 -0400
+++ b/toolSelenzyme.py	Fri Jul 05 06:26:22 2019 -0400
@@ -24,25 +24,31 @@
     return parser
 
 # Output columns, to be improved
-columns = ['Seq. ID', 'Score', 'Organism Source', 'Description']
+columns = ['smarts', 'Seq. ID', 'Score', 'Organism Source', 'Description']
 
 if __name__ == "__main__":
     parser = arguments()
     arg = parser.parse_args()
     assert os.path.exists(arg.infile)
-    with open(arg.infile) as handler:
+    header = True
+    with open(arg.infile) as handler, open(arg.outfile, 'w' ) as writer:
+        cw = csv.writer( writer )
         cv = csv.DictReader(handler)
-        row = next(cv)
-        url = arg.server
-        assert 'smarts' in row
-        r = requests.post( os.path.join(url, 'Query') , json={'smarts': row['smarts']} )
-        res = json.loads( r.content.decode('utf-8') )
-        assert res['data'] is not None
-        val = json.loads( res['data'] )
-        assert 'Seq. ID' in val and len(val['Seq. ID'])>0
-        with open(arg.outfile, 'w' ) as writer:
-            cw = csv.writer( writer )
-            cw.writerow( columns )
-            for ix in sorted(val['Seq. ID'], key=lambda z: int(z)):
-                cw.writerow( [val[j][ix] for j in columns] )
+        for row in cv:
+            url = arg.server
+            assert 'smarts' in row
+            smarts = row['smarts']
+            r = requests.post( os.path.join(url, 'Query') , json={'smarts': smarts} )
+            res = json.loads( r.content.decode('utf-8') )
+            try:
+                assert res['data'] is not None
+                val = json.loads( res['data'] )
+                assert 'Seq. ID' in val and len(val['Seq. ID'])>0
+                if header:
+                    cw.writerow( columns )
+                    header = False
+                for ix in sorted(val['Seq. ID'], key=lambda z: int(z)):
+                    cw.writerow( [smarts]+[val[j][ix] for j in columns[1:]] )
+            except:
+                continue