comparison toolSelenzyme.py @ 23:635b76a9bd7a draft

planemo upload commit 6f56159bc3cd5339f88517f6822240410bc9e4dd-dirty
author pablocarb
date Fri, 05 Jul 2019 06:26:22 -0400
parents ac027c9ace4d
children
comparison
equal deleted inserted replaced
22:638dcd2d93bc 23:635b76a9bd7a
22 parser.add_argument('-server', default='http://selenzyme.synbiochem.co.uk/REST', 22 parser.add_argument('-server', default='http://selenzyme.synbiochem.co.uk/REST',
23 help='Selenzyme server.') 23 help='Selenzyme server.')
24 return parser 24 return parser
25 25
26 # Output columns, to be improved 26 # Output columns, to be improved
27 columns = ['Seq. ID', 'Score', 'Organism Source', 'Description'] 27 columns = ['smarts', 'Seq. ID', 'Score', 'Organism Source', 'Description']
28 28
29 if __name__ == "__main__": 29 if __name__ == "__main__":
30 parser = arguments() 30 parser = arguments()
31 arg = parser.parse_args() 31 arg = parser.parse_args()
32 assert os.path.exists(arg.infile) 32 assert os.path.exists(arg.infile)
33 with open(arg.infile) as handler: 33 header = True
34 with open(arg.infile) as handler, open(arg.outfile, 'w' ) as writer:
35 cw = csv.writer( writer )
34 cv = csv.DictReader(handler) 36 cv = csv.DictReader(handler)
35 row = next(cv) 37 for row in cv:
36 url = arg.server 38 url = arg.server
37 assert 'smarts' in row 39 assert 'smarts' in row
38 r = requests.post( os.path.join(url, 'Query') , json={'smarts': row['smarts']} ) 40 smarts = row['smarts']
39 res = json.loads( r.content.decode('utf-8') ) 41 r = requests.post( os.path.join(url, 'Query') , json={'smarts': smarts} )
40 assert res['data'] is not None 42 res = json.loads( r.content.decode('utf-8') )
41 val = json.loads( res['data'] ) 43 try:
42 assert 'Seq. ID' in val and len(val['Seq. ID'])>0 44 assert res['data'] is not None
43 with open(arg.outfile, 'w' ) as writer: 45 val = json.loads( res['data'] )
44 cw = csv.writer( writer ) 46 assert 'Seq. ID' in val and len(val['Seq. ID'])>0
45 cw.writerow( columns ) 47 if header:
46 for ix in sorted(val['Seq. ID'], key=lambda z: int(z)): 48 cw.writerow( columns )
47 cw.writerow( [val[j][ix] for j in columns] ) 49 header = False
50 for ix in sorted(val['Seq. ID'], key=lambda z: int(z)):
51 cw.writerow( [smarts]+[val[j][ix] for j in columns[1:]] )
52 except:
53 continue
48 54