comparison toolOptBioDes.py @ 24:8f42eba7e2eb draft

planemo upload commit 2414e76bee8adbe48fee12b14b13a743a03b9748-dirty
author pablocarb
date Fri, 05 Jul 2019 17:18:26 -0400
parents 6a1fbacdfaf5
children 0ad6fda90f41
comparison
equal deleted inserted replaced
23:635b76a9bd7a 24:8f42eba7e2eb
13 import os 13 import os
14 import json 14 import json
15 15
16 def arguments(): 16 def arguments():
17 parser = argparse.ArgumentParser(description='toolOptBioDes: Optimal SynBio Design. Pablo Carbonell, SYNBIOCHEM, 2019') 17 parser = argparse.ArgumentParser(description='toolOptBioDes: Optimal SynBio Design. Pablo Carbonell, SYNBIOCHEM, 2019')
18 parser.add_argument('infile',
19 help='Input csv file (DoE specificiations).')
20 parser.add_argument('size', 18 parser.add_argument('size',
21 help='Library size.') 19 help='Library size.')
22 parser.add_argument('outfile', 20 parser.add_argument('outfile',
23 help='Output csv design file.') 21 help='Output csv design file.')
24 parser.add_argument('diagfile', 22 parser.add_argument('diagfile',
25 help='Output csv diagnostics file.') 23 help='Output csv diagnostics file.')
24 parser.add_argument('-infile', default=None,
25 help='Input csv file (DoE specifications sheet).')
26 parser.add_argument('-partsfile', default=None,
27 help='Input csv file (Regulartory parts).')
28 parser.add_argument('-genesfile', default=None,
29 help='Input csv file (Genetic parts).')
30 parser.add_argument('-sbolOut', default=None,
31 help='Output design in SBOL format.')
26 parser.add_argument('-server', default='http://optbiodes.synbiochem.co.uk/REST', 32 parser.add_argument('-server', default='http://optbiodes.synbiochem.co.uk/REST',
27 help='OptBioDes server.') 33 help='OptBioDes server.')
28 return parser 34 return parser
29 35
30 def testApp(url): 36 def testApp(url):
47 cw = csv.writer(h) 53 cw = csv.writer(h)
48 cw.writerow( ['Size', 'Efficiency'] ) 54 cw.writerow( ['Size', 'Efficiency'] )
49 cw.writerow( [res['data']['libsize'], res['data']['J']] ) 55 cw.writerow( [res['data']['libsize'], res['data']['J']] )
50 print( 'Size:', res['data']['libsize'], 'Efficiency:', res['data']['J'] ) 56 print( 'Size:', res['data']['libsize'], 'Efficiency:', res['data']['J'] )
51 57
58 def partsUploadSbol( partsfile, genesfile, size, outfile, diagfile, sbolOut, server ):
59 files = {
60 'parts': open(partsfile, 'rb' ),
61 'genes': open(genesfile, 'rb')
62 }
63 values = {'size': size}
64 r = requests.post( os.path.join(url, 'Parts' ), files=files, data=values )
65 res = json.loads( r.content.decode('utf-8') )
66 M = res['data']['M']
67 with open(outfile, 'w') as h:
68 cw = csv.writer(h)
69 cw.writerow( res['data']['names'] )
70 for row in M:
71 cw.writerow( row )
72 with open(diagfile, 'w') as h:
73 cw = csv.writer(h)
74 cw.writerow( ['Size', 'Efficiency'] )
75 cw.writerow( [res['data']['libsize'], res['data']['J']] )
76 open(sbolOut, 'w').write(res['data']['sbol'])
77 print( 'Size:', res['data']['libsize'], 'Efficiency:', res['data']['J'] )
52 78
53 79
54 if __name__ == "__main__": 80 if __name__ == "__main__":
55 parser = arguments() 81 parser = arguments()
56 arg = parser.parse_args() 82 arg = parser.parse_args()
57 assert os.path.exists(arg.infile) 83 assert os.path.exists(arg.infile)
58 sheetUpload( arg.infile, arg.size, arg.outfile, arg.diagfile, arg.server ) 84 if arg.sbolOut is None:
85 sheetUpload( arg.infile, arg.size, arg.outfile, arg.diagfile, arg.server )
86 else:
87 partsUploadSbol( arg.partsfile, arg.genesfile, arg.size, arg.outfile, arg.diagfile, arg.sbolOut, arg.server )