Mercurial > repos > pablocarb > synbiodesign
annotate toolOptBioDes.py @ 16:fe78fd6b315a draft
planemo upload commit 87db86a34f2d92eb2c9756bf9ee53ae2970554d5
author | pablocarb |
---|---|
date | Tue, 11 Jun 2019 11:42:40 -0400 |
parents | 6a1fbacdfaf5 |
children | 8f42eba7e2eb |
rev | line source |
---|---|
2
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
3 """ |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
4 Created on Mar 19 |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
5 |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
6 @author: Pablo Carbonell |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
7 @description: Query OptBioDes: optimal synbio design. |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
8 |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
9 """ |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
10 import requests |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
11 import argparse |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
12 import csv |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
13 import os |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
14 import json |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
15 |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
16 def arguments(): |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
17 parser = argparse.ArgumentParser(description='toolOptBioDes: Optimal SynBio Design. Pablo Carbonell, SYNBIOCHEM, 2019') |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
18 parser.add_argument('infile', |
8
6572347b3e1a
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
6
diff
changeset
|
19 help='Input csv file (DoE specificiations).') |
4
6dbb43bdf2f4
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
3
diff
changeset
|
20 parser.add_argument('size', |
6dbb43bdf2f4
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
3
diff
changeset
|
21 help='Library size.') |
2
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
22 parser.add_argument('outfile', |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
23 help='Output csv design file.') |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
24 parser.add_argument('diagfile', |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
25 help='Output csv diagnostics file.') |
10
6a1fbacdfaf5
planemo upload commit b97a4df6e4e3a6f3d14f18f3f30c47eb5657a362
pablocarb
parents:
9
diff
changeset
|
26 parser.add_argument('-server', default='http://optbiodes.synbiochem.co.uk/REST', |
2
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
27 help='OptBioDes server.') |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
28 return parser |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
29 |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
30 def testApp(url): |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
31 r = requests.get( url ) |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
32 res = json.loads( r.content.decode('utf-8') ) |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
33 print( res ) |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
34 |
4
6dbb43bdf2f4
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
3
diff
changeset
|
35 def sheetUpload(doefile, size, outfile, diagfile, url): |
2
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
36 files = { 'file': open(doefile, 'rb' ) } |
8
6572347b3e1a
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
6
diff
changeset
|
37 values = {'size': int(size), 'format': 'csv'} |
2
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
38 r = requests.post( os.path.join(url, 'Query' ), files=files, data=values ) |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
39 res = json.loads( r.content.decode('utf-8') ) |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
40 M = res['data']['M'] |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
41 with open(outfile, 'w') as h: |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
42 cw = csv.writer(h) |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
43 cw.writerow( res['data']['names'] ) |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
44 for row in M: |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
45 cw.writerow( row ) |
9
f9aef3df1fc8
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
8
diff
changeset
|
46 with open(diagfile, 'w') as h: |
8
6572347b3e1a
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
6
diff
changeset
|
47 cw = csv.writer(h) |
6572347b3e1a
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
6
diff
changeset
|
48 cw.writerow( ['Size', 'Efficiency'] ) |
6572347b3e1a
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
6
diff
changeset
|
49 cw.writerow( [res['data']['libsize'], res['data']['J']] ) |
2
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
50 print( 'Size:', res['data']['libsize'], 'Efficiency:', res['data']['J'] ) |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
51 |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
52 |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
53 |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
54 if __name__ == "__main__": |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
55 parser = arguments() |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
56 arg = parser.parse_args() |
856bd14e6e96
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff
changeset
|
57 assert os.path.exists(arg.infile) |
6
93eb36300900
planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
4
diff
changeset
|
58 sheetUpload( arg.infile, arg.size, arg.outfile, arg.diagfile, arg.server ) |