annotate toolOptBioDes.py @ 4:6dbb43bdf2f4 draft

planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
author pablocarb
date Thu, 02 May 2019 07:46:26 -0400
parents f3771c0a2327
children 93eb36300900
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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',
856bd14e6e96 planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff changeset
19 help='Input xlsx 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.')
856bd14e6e96 planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff changeset
26 parser.add_argument('-server', default='http://doe.synbiochem.co.uk/REST',
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' ) }
4
6dbb43bdf2f4 planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents: 3
diff changeset
37 values = {'size': int(size)}
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 )
856bd14e6e96 planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff changeset
46 print( 'Size:', res['data']['libsize'], 'Efficiency:', res['data']['J'] )
856bd14e6e96 planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff changeset
47
856bd14e6e96 planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff changeset
48
856bd14e6e96 planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff changeset
49
856bd14e6e96 planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff changeset
50 if __name__ == "__main__":
856bd14e6e96 planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff changeset
51 parser = arguments()
856bd14e6e96 planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff changeset
52 arg = parser.parse_args()
856bd14e6e96 planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents:
diff changeset
53 assert os.path.exists(arg.infile)
3
f3771c0a2327 planemo upload commit 6a252d04f4b2f79606ab6679b6a91f957e33da7b-dirty
pablocarb
parents: 2
diff changeset
54 sheetUpload( arg.infile, arg.outfile, arg.diagfile, arg.server )