def rpPipeline(): with tempfile.TemporaryDirectory() as tmpdir: params = json.load(request.files['params']) rp2_file = os.path.join(tmpdir, 'rp2_file.csv') with open(rp2_file, 'wb') as fo: fo.write(request.files['rp2_file'].read()) rp2paths_compounds_file = os.path.join(tmpdir, 'rp2paths_compounds_file.csv') with open(rp2paths_compounds_file, 'wb') as fo: fo.write(request.files['rp2paths_compounds_file'].read()) rp2paths_pathways_file = os.path.join(tmpdir, 'rp2paths_pathways_file') with open(rp2paths_pathways_file, 'wb') as fo: fo.write(request.files['rp2paths_pathways_file'].read()) gem_file = os.path.join(tmpdir, 'gem_file.sbml') with open(gem_file, 'wb') as fo: fo.write(request.files['gem_file'].read()) rpcollection_file = os.path.join(tmpdir, 'rpcollection.tar.xz') rpre_status = rpReader.rp2ToCollection(rp2_file, rp2paths_compounds_file, rp2paths_pathways_file, rpcollection_file, rpcache=GLOBAL_RPCACHE) rpeq_status = rpEquilibrator.runCollection( rpcollection_file, rpcollection_file, ph=float(params['ph']), ionic_strength=float(params['ionic_strength']), temp_k=float(params['temp_k']), rpcache=GLOBAL_RPCACHE) rpfba_status = rpFBA.runCollection(rpcollection_file, gem_file, rpcollection_file, num_workers=params['num_workers'], keep_merged=params['keep_merged'], del_sp_pro=params['del_sp_pro'], del_sp_react=params['del_sp_react'], rpcache=GLOBAL_RPCACHE) if params['taxo_id'] == None: #if you cannot find the annotation then try to recover it from the GEM file rpsbml_gem = rpSBML(model_name='tmp', path=gem_file) params['taxo_id'] = rpsbml_gem.readTaxonomy() rpsel_status = rpSelenzyme.runCollection( rpcollection_file, params['taxo_id'], rpcollection_file, uniprot_aa_length=SELENZYME_UNIPROT_AA_LENGTH, data_dir=SELENZYNE_DATA_DIR, pc=SELENZYME_PC, rpcache=GLOBAL_RPCACHE) rpglo_status = rpGlobalScore.runCollection(rpcollection_file, rpcollection_file, rpcache=GLOBAL_RPCACHE) rpcollection_file.seek(0) return send_file(rpcollection_file, as_attachment=True, attachment_filename='rpcollection.tar.xz', mimetype='application/x-tar')
def rpSelenzymeService(): with tempfile.TemporaryDirectory() as tmpdir: ########### file in #################### rpcollection_file = os.path.join(tmpdir, 'rpcollection.tar.xz') try: with open(rpcollection_file, 'wb') as fo: fo.write(request.files['rpcollection_file'].read()) except KeyError as e: app.logger.error('A required file is missing: ' + str(e)) return Response('A required file is missing: ' + str(e), status=400) ########## Parameters ################### try: params = json.load(request.files['data']) except ValueError as e: app.logger.error('One or more parameters are malformed: ' + str(e)) return Response('One or more parameters are malformed: ' + str(e), status=400) except KeyError as e: app.logger.error('One or more of the parameters are missing: ' + str(e)) return Response('One or more of the parameters are missing: ' + str(e), status=400) try: taxo_id = int(params['taxo_id']) except KeyError: app.logger.info( 'No taxo_id passed. Setting to default to E.Coli (83333)') taxo_id = 83333 except ValueError: app.logger.warning( 'taxo_id is not recognised. Setting to default E.Coli (83333)') taxo_id = 83333 status = rpSelenzyme.runCollection( rpcollection_file, taxo_id, rpcollection_file, is_cleanup=False, uniprot_aa_length=SELENZYME_UNIPROT_AA_LENGTH, data_dir=SELENZYNE_DATA_DIR, pc=SELENZYME_PC, rpcache=GLOBAL_RPCACHE) #rpcollection_file.seek(0) if not status: app.logger.error( 'rpSelenzyme has encountered a problem.... please investigate futher' ) return Response( 'rpSelenzyme has encountered a problem.... please investigate futher', status=400) return send_file(rpcollection_file, as_attachment=True, attachment_filename='rpcollection.tar.xz', mimetype='application/x-tar')
def rpSelenzyme(): with tempfile.TemporaryDirectory() as tmpdir: rpcollection_file = os.path.join(tmpdir, 'rpcollection.tar.xz') with open(rpcollection_file, 'wb') as fo: fo.write(request.files['rpcollection_file'].read()) status = rpSelenzyme.runCollection( rpcollection_file, params['taxo_id'], rpcollection_file, uniprot_aa_length=SELENZYME_UNIPROT_AA_LENGTH, data_dir=SELENZYNE_DATA_DIR, pc=SELENZYME_PC, rpcache=GLOBAL_RPCACHE) rpcollection_file.seek(0) return send_file(rpcollection_file, as_attachment=True, attachment_filename='rpcollection.tar.xz', mimetype='application/x-tar')
taxo_id = model_taxo_id[s] except IndexError: logging.error('Index error in lines: ' + str(lines)) continue except FileNotFoundError: logging.error('Cannot find the file') continue except KeyError: logging.error('KeyError for ' + str(s)) continue if not taxo_id: logging.error('Taxonomy id has not been defined') continue rpsel_status = rpSelenzyme.runCollection( rpcollection_file, taxo_id, rpcollection_file, cache_path=selenzyme_cache_file, rpcache=global_rpcache) if not rpsel_status: logging.error('Problem running rpSelenzyme') continue logging.info('---------- rpGlobalScore -----') rpglo_status = rpGlobalScore.runCollection(rpcollection_file, rpcollection_file, rpcache=global_rpcache) if not rpglo_status: logging.error('Problem running rpGlobalScore') continue ################ generate the various netowrk JSON and SBML JSON ##### logging.info('------------ JSON ----------') rpSBML.batchAsDict(rpcollection_file)
def rpPipelineService(): with tempfile.TemporaryDirectory() as tmpdir: ########### file in ################ rp2_file = os.path.join(tmpdir, 'rp2_file.csv') rp2paths_compounds_file = os.path.join(tmpdir, 'rp2paths_compounds_file.csv') rp2paths_pathways_file = os.path.join(tmpdir, 'rp2paths_pathways_file') gem_file = os.path.join(tmpdir, 'gem_file.sbml') try: with open(rp2_file, 'wb') as fo: fo.write(request.files['rp2_file'].read()) with open(rp2paths_compounds_file, 'wb') as fo: fo.write(request.files['rp2paths_compounds_file'].read()) with open(rp2paths_pathways_file, 'wb') as fo: fo.write(request.files['rp2paths_pathways_file'].read()) with open(gem_file, 'wb') as fo: fo.write(request.files['gem_file'].read()) except KeyError as e: app.logger.error('A required file is missing: ' + str(e)) return Response('A required file is missing: ' + str(e), status=400) ############ parameters ########## try: params = json.load(request.files['data']) except ValueError as e: app.logger.error('One or more parameters are malformed: ' + str(e)) return Response('One or more parameters are malformed: ' + str(e), status=400) except KeyError as e: app.logger.error('One or more of the parameters are missing: ' + str(e)) return Response('One or more of the parameters are missing: ' + str(e), status=400) try: ph = float(params['ph']) except KeyError: app.logger.info('No ph passed. Setting to default to 7.5') ph = 7.5 except ValueError: app.logger.warning('ph is not recognised. Setting to default 7.5') ph = 7.5 try: temp_k = float(params['temp_k']) except KeyError: app.logger.info('No temp_k passed. Setting to default to 298.15') temp_k = 298.15 except ValueError: app.logger.warning( 'temp_k is not recognised. Setting to default 298.15') temp_k = 298.15 try: ionic_strength = float(params['ionic_strength']) except KeyError: app.logger.info( 'No ionic_strength passed. Setting to default to 200.0') ionic_strength = 200.0 except ValueError: app.logger.warning( 'ionic_strength is not recognised. Setting to default 200.0') ionic_strength = 200.0 try: num_workers = int(params['num_workers']) except KeyError: app.logger.info('No num_workers passed. Setting to default to 1') num_workers = 1 except ValueError: app.logger.warning( 'num_workers is not recognised. Setting to default 1') num_workers = 1 try: keep_merged = bool(params['keep_merged']) except KeyError: app.logger.info( 'No keep_merged passed. Setting to default to True') keep_merged = True except ValueError: app.logger.warning( 'keep_merged is not recognised. Setting to default True') keep_merged = True try: del_sp_pro = bool(params['del_sp_pro']) except KeyError: app.logger.info( 'No del_sp_pro passed. Setting to default to False') del_sp_pro = False except ValueError: app.logger.warning( 'del_sp_pro is not recognised. Setting to default False') del_sp_pro = False try: del_sp_react = bool(params['del_sp_react']) except KeyError: app.logger.info( 'No del_sp_react passed. Setting to default to False') del_sp_react = False except ValueError: app.logger.warning( 'del_sp_react is not recognised. Setting to default False') del_sp_react = False try: taxo_id = int(params['taxo_id']) except KeyError: app.logger.info( 'No taxo_id passed. Setting to default to None to try and recover from GEM SBML' ) taxo_id = None except ValueError: app.logger.warning( 'taxo_id is not recognised. Setting to default None to try to recover from GEM SBML' ) taxo_id = None rpcollection_file = os.path.join(tmpdir, 'rpcollection.tar.xz') rpre_status = rpReader.rp2ToCollection(rp2_file, rp2paths_compounds_file, rp2paths_pathways_file, rpcollection_file, rpcache=GLOBAL_RPCACHE) if not rpre_status: app.logger.error( 'rpReader has encountered a problem.... please investigate futher' ) return Response( 'rpReader has encountered a problem.... please investigate futher', status=400) rpeq_status = rpEquilibrator.runCollection( rpcollection_file, rpcollection_file, ph=ph, ionic_strength=ionic_strength, temp_k=temp_k, rpcache=GLOBAL_RPCACHE) if not rpeq_status: app.logger.error( 'rpEquilibrator has encountered a problem.... please investigate futher' ) return Response( 'rpEquilibrator has encountered a problem.... please investigate futher', status=400) rpfba_status = rpFBA.runCollection(rpcollection_file, gem_file, rpcollection_file, num_workers=num_workers, keep_merged=keep_merged, del_sp_pro=del_sp_pro, del_sp_react=del_sp_react, rpcache=GLOBAL_RPCACHE) if not rpfba_status: app.logger.error( 'rpFBA has encountered a problem.... please investigate futher' ) return Response( 'rpFBA has encountered a problem.... please investigate futher', status=400) if taxo_id == None: #if you cannot find the annotation then try to recover it from the GEM file rpsbml_gem = rpSBML(model_name='tmp', path=gem_file) taxo_id = rpsbml_gem.readTaxonomy() logging.info('The taxonomy_id is ' + str(taxo_id)) try: taxo_id = taxo_id[0] except IndexError: app.logger.error( 'Could not retreive the taxonomy id and none was passed') return Response( 'Could not retreive the taxonomy id and none was passed', status=400) rpsel_status = rpSelenzyme.runCollection( rpcollection_file, taxo_id, rpcollection_file, is_cleanup=False, uniprot_aa_length=SELENZYME_UNIPROT_AA_LENGTH, data_dir=SELENZYNE_DATA_DIR, pc=SELENZYME_PC, rpcache=GLOBAL_RPCACHE) if not rpsel_status: app.logger.error( 'rpSelenzyme has encountered a problem.... please investigate futher' ) return Response( 'rpSelenzyme has encountered a problem.... please investigate futher', status=400) rpglo_status = rpGlobalScore.runCollection(rpcollection_file, rpcollection_file, rpcache=GLOBAL_RPCACHE) if not rpglo_status: app.logger.error( 'rpGlobalScore has encountered a problem.... please investigate futher' ) return Response( 'rpGlobalScore has encountered a problem.... please investigate futher', status=400) #rpcollection_file.seek(0) return send_file(rpcollection_file, as_attachment=True, attachment_filename='rpcollection.tar.xz', mimetype='application/x-tar')