Mercurial > repos > pablocarb > synbiodesign
diff 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 |
line wrap: on
line diff
--- a/toolOptBioDes.py Fri Jul 05 06:26:22 2019 -0400 +++ b/toolOptBioDes.py Fri Jul 05 17:18:26 2019 -0400 @@ -15,14 +15,20 @@ def arguments(): parser = argparse.ArgumentParser(description='toolOptBioDes: Optimal SynBio Design. Pablo Carbonell, SYNBIOCHEM, 2019') - parser.add_argument('infile', - help='Input csv file (DoE specificiations).') parser.add_argument('size', help='Library size.') parser.add_argument('outfile', help='Output csv design file.') parser.add_argument('diagfile', help='Output csv diagnostics file.') + parser.add_argument('-infile', default=None, + help='Input csv file (DoE specifications sheet).') + parser.add_argument('-partsfile', default=None, + help='Input csv file (Regulartory parts).') + parser.add_argument('-genesfile', default=None, + help='Input csv file (Genetic parts).') + parser.add_argument('-sbolOut', default=None, + help='Output design in SBOL format.') parser.add_argument('-server', default='http://optbiodes.synbiochem.co.uk/REST', help='OptBioDes server.') return parser @@ -49,10 +55,33 @@ cw.writerow( [res['data']['libsize'], res['data']['J']] ) print( 'Size:', res['data']['libsize'], 'Efficiency:', res['data']['J'] ) +def partsUploadSbol( partsfile, genesfile, size, outfile, diagfile, sbolOut, server ): + files = { + 'parts': open(partsfile, 'rb' ), + 'genes': open(genesfile, 'rb') + } + values = {'size': size} + r = requests.post( os.path.join(url, 'Parts' ), files=files, data=values ) + res = json.loads( r.content.decode('utf-8') ) + M = res['data']['M'] + with open(outfile, 'w') as h: + cw = csv.writer(h) + cw.writerow( res['data']['names'] ) + for row in M: + cw.writerow( row ) + with open(diagfile, 'w') as h: + cw = csv.writer(h) + cw.writerow( ['Size', 'Efficiency'] ) + cw.writerow( [res['data']['libsize'], res['data']['J']] ) + open(sbolOut, 'w').write(res['data']['sbol']) + print( 'Size:', res['data']['libsize'], 'Efficiency:', res['data']['J'] ) if __name__ == "__main__": parser = arguments() arg = parser.parse_args() assert os.path.exists(arg.infile) - sheetUpload( arg.infile, arg.size, arg.outfile, arg.diagfile, arg.server ) + if arg.sbolOut is None: + sheetUpload( arg.infile, arg.size, arg.outfile, arg.diagfile, arg.server ) + else: + partsUploadSbol( arg.partsfile, arg.genesfile, arg.size, arg.outfile, arg.diagfile, arg.sbolOut, arg.server )