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