Ejemplo n.º 1
0
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')
Ejemplo n.º 2
0
 def test_runCollection(self):
     with tempfile.TemporaryDirectory() as tmp_output_folder:
         rpEquilibrator.runCollection(
             os.path.join('data', 'rpequilibrator', 'test.rpcol'),
             os.path.join(tmp_output_folder, 'test.rpcol'))
         tar = tarfile.open(os.path.join(tmp_output_folder, 'test.rpcol'),
                            mode='r')
         os.mkdir(os.path.join(tmp_output_folder, 'results'))
         tar.extractall(os.path.join(tmp_output_folder, 'results'))
         self.assertTrue(
             len(
                 glob.glob(
                     os.path.join(tmp_output_folder, 'results',
                                  'rpsbml_collection', 'models', '*'))) ==
             1)
         rpsbml = rpSBML(path=glob.glob(
             os.path.join(tmp_output_folder, 'results', 'rpsbml_collection',
                          'models', '*'))[0])
         asdict = rpsbml.asDict()
         self.assertAlmostEqual(
             asdict['pathway']['brsynth']['dfG_prime_o']['value'],
             1784.7384959433493)
Ejemplo n.º 3
0
def rpEquilibrator():
    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 = rpEquilibrator.runCollection(
            rpcollection_file,
            rpcollection_file,
            ph=params['ph'],
            ionic_strength=params['ionic_strength'],
            temp_k=params['temp_k'],
            rpcache=GLOBAL_RPCACHE)
        rpcollection_file.seek(0)
        return send_file(rpcollection_file,
                         as_attachment=True,
                         attachment_filename='rpcollection.tar.xz',
                         mimetype='application/x-tar')
Ejemplo n.º 4
0
 rpfba_status = rpFBA.runCollection(rpcollection_file,
                                    gem_file,
                                    rpcollection_file,
                                    num_workers=1,
                                    keep_merged=True,
                                    del_sp_pro=False,
                                    del_sp_react=False,
                                    rpcache=global_rpcache)
 if not rpfba_status:
     logging.error('Problem running rpFBA')
     continue
 logging.info('---------- rpEquilibrator -----')
 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:
     logging.error('Problem running rpEquilibrator')
     continue
 logging.info('---------- rpSelenzyme -----')
 #### try to revocer the tax_id
 taxo_id = None
 try:
     with open(os.path.join(strain_dir, 'rp2_report.txt'),
               'r') as rp2_report:
         lines = []
         for i in rp2_report:
             lines.append(i)
Ejemplo n.º 5
0
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')
Ejemplo n.º 6
0
def rpEquilibratorService():
    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:
            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
        status = rpEquilibrator.runCollection(rpcollection_file,
                                              rpcollection_file,
                                              ph=ph,
                                              ionic_strength=ionic_strength,
                                              temp_k=temp_k,
                                              rpcache=GLOBAL_RPCACHE)
        if not status:
            app.logger.error(
                'rpEquilibrator has encountered a problem.... please investigate futher'
            )
            return Response(
                'rpEquilibrator 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')