Mercurial > repos > pablocarb > synbiodesign
comparison toolSelenzyme.py @ 0:ac027c9ace4d draft
planemo upload commit 9e24fae395aeaca30c5bcdef80a21b7decb04042-dirty
author | pablocarb |
---|---|
date | Mon, 29 Apr 2019 09:49:36 -0400 |
parents | |
children | 635b76a9bd7a |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:ac027c9ace4d |
---|---|
1 #!/usr/bin/env python3 | |
2 # -*- coding: utf-8 -*- | |
3 """ | |
4 Created on Mar 19 | |
5 | |
6 @author: Pablo Carbonell | |
7 @description: Query Selenzme: Enzyme sequence selection. | |
8 | |
9 """ | |
10 import requests | |
11 import argparse | |
12 import csv | |
13 import os | |
14 import json | |
15 | |
16 def arguments(): | |
17 parser = argparse.ArgumentParser(description='toolSelenzyme: Enzyme sequence selection. Pablo Carbonell, SYNBIOCHEM, 2019') | |
18 parser.add_argument('infile', | |
19 help='Input csv file.') | |
20 parser.add_argument('outfile', | |
21 help='Input csv file.') | |
22 parser.add_argument('-server', default='http://selenzyme.synbiochem.co.uk/REST', | |
23 help='Selenzyme server.') | |
24 return parser | |
25 | |
26 # Output columns, to be improved | |
27 columns = ['Seq. ID', 'Score', 'Organism Source', 'Description'] | |
28 | |
29 if __name__ == "__main__": | |
30 parser = arguments() | |
31 arg = parser.parse_args() | |
32 assert os.path.exists(arg.infile) | |
33 with open(arg.infile) as handler: | |
34 cv = csv.DictReader(handler) | |
35 row = next(cv) | |
36 url = arg.server | |
37 assert 'smarts' in row | |
38 r = requests.post( os.path.join(url, 'Query') , json={'smarts': row['smarts']} ) | |
39 res = json.loads( r.content.decode('utf-8') ) | |
40 assert res['data'] is not None | |
41 val = json.loads( res['data'] ) | |
42 assert 'Seq. ID' in val and len(val['Seq. ID'])>0 | |
43 with open(arg.outfile, 'w' ) as writer: | |
44 cw = csv.writer( writer ) | |
45 cw.writerow( columns ) | |
46 for ix in sorted(val['Seq. ID'], key=lambda z: int(z)): | |
47 cw.writerow( [val[j][ix] for j in columns] ) | |
48 |