def run(self):
        """Run flux consistency check command"""

        # Load compound information
        def compound_name(id):
            if id not in self._model.compounds:
                return id
            return self._model.compounds[id].properties.get('name', id)

        epsilon = self._args.epsilon

        if self._args.unrestricted:
            # Allow all exchange reactions with no flux limits
            for reaction in self._mm.reactions:
                if self._mm.is_exchange(reaction):
                    del self._mm.limits[reaction].bounds

        loop_removal = self._get_loop_removal_option()
        enable_tfba = loop_removal == 'tfba'
        enable_fastcore = self._args.fastcore

        if enable_tfba and enable_fastcore:
            self.argument_error(
                'Using Fastcore with thermodynamic constraints'
                ' is not supported!')
        start_time = time.time()

        if enable_fastcore:
            solver = self._get_solver()
            try:
                inconsistent = set(fastcore.fastcc(
                    self._mm, epsilon, solver=solver))
            except fluxanalysis.FluxBalanceError as e:
                self.report_flux_balance_error(e)
        else:
            if enable_tfba:
                solver = self._get_solver(integer=True)
            else:
                solver = self._get_solver()

            if self._args.reduce_lp:
                logger.info('Running with reduced number of LP problems.')
                try:
                    inconsistent = set(
                        fluxanalysis.consistency_check(
                            self._mm, self._mm.reactions, epsilon,
                            tfba=enable_tfba, solver=solver))
                except fluxanalysis.FluxBalanceError as e:
                    self.report_flux_balance_error(e)
            else:
                logger.info('Using flux bounds to determine consistency.')
                try:
                    inconsistent = set(self._run_fva_fluxcheck(
                        self._mm, solver, enable_tfba, epsilon))
                except FluxCheckFVATaskError:
                    self.report_flux_balance_error()

        logger.info('Solving took {:.2f} seconds'.format(
            time.time() - start_time))

        # Count the number of reactions that are fixed at zero. While these
        # reactions are still inconsistent, they are inconsistent because they
        # have been explicitly disabled.
        disabled_exchange = 0
        disabled_internal = 0

        count_exchange = 0
        total_exchange = 0

        count_internal = 0
        total_internal = 0

        # Print result
        for reaction in sorted(self._mm.reactions):
            disabled = self._mm.limits[reaction].bounds == (0, 0)

            if self._mm.is_exchange(reaction):
                total_exchange += 1
                count_exchange += int(reaction in inconsistent)
                disabled_exchange += int(disabled)
            else:
                total_internal += 1
                count_internal += int(reaction in inconsistent)
                disabled_internal += int(disabled)

            if reaction in inconsistent:
                rx = self._mm.get_reaction(reaction)
                rxt = rx.translated_compounds(compound_name)
                print('{}\t{}'.format(reaction, rxt))

        logger.info('Model has {}/{} inconsistent internal reactions'
                    ' ({} disabled by user)'.format(
                        count_internal, total_internal, disabled_internal))
        logger.info('Model has {}/{} inconsistent exchange reactions'
                    ' ({} disabled by user)'.format(
                        count_exchange, total_exchange, disabled_exchange))
def run ( self ) : def compound_name ( id ) : if id not in self . _model . compounds : return id return self . _model . compounds [ id ] . properties . get ( 'name' , id ) epsilon = self . _args . epsilon if self . _args . unrestricted : for reaction in self . _mm . reactions : if self . _mm . is_exchange ( reaction ) : del self . _mm . limits [ reaction ] . bounds loop_removal = self . _get_loop_removal_option ( ) enable_tfba = loop_removal == 'tfba' enable_fastcore = self . _args . fastcore if enable_tfba and enable_fastcore : self . argument_error ( 'Using Fastcore with thermodynamic constraints' ' is not supported!' ) start_time = time . time ( ) if enable_fastcore : solver = self . _get_solver ( ) try : inconsistent = set ( fastcore . fastcc ( self . _mm , epsilon , solver = solver ) ) except fluxanalysis . FluxBalanceError as e : self . report_flux_balance_error ( e ) else : if enable_tfba : solver = self . _get_solver ( integer = True ) else : solver = self . _get_solver ( ) if self . _args . reduce_lp : logger . info ( 'Running with reduced number of LP problems.' ) try : inconsistent = set ( fluxanalysis . consistency_check ( self . _mm , self . _mm . reactions , epsilon , tfba = enable_tfba , solver = solver ) ) except fluxanalysis . FluxBalanceError as e : self . report_flux_balance_error ( e ) else : logger . info ( 'Using flux bounds to determine consistency.' ) try : inconsistent = set ( self . _run_fva_fluxcheck ( self . _mm , solver , enable_tfba , epsilon ) ) except FluxCheckFVATaskError : self . report_flux_balance_error ( ) logger . info ( 'Solving took {:.2f} seconds' . format ( time . time ( ) - start_time ) ) disabled_exchange = 0 disabled_internal = 0 count_exchange = 0 total_exchange = 0 count_internal = 0 total_internal = 0 for reaction in sorted ( self . _mm . reactions ) : disabled = self . _mm . limits [ reaction ] . bounds == ( 0 , 0 ) if self . _mm . is_exchange ( reaction ) : total_exchange += 1 count_exchange += int ( reaction in inconsistent ) disabled_exchange += int ( disabled ) else : total_internal += 1 count_internal += int ( reaction in inconsistent ) disabled_internal += int ( disabled ) if reaction in inconsistent : rx = self . _mm . get_reaction ( reaction ) rxt = rx . translated_compounds ( compound_name ) print ( '{}\t{}' . format ( reaction , rxt ) ) logger . info ( 'Model has {}/{} inconsistent internal reactions' ' ({} disabled by user)' . format ( count_internal , total_internal , disabled_internal ) ) logger . info ( 'Model has {}/{} inconsistent exchange reactions' ' ({} disabled by user)' . format ( count_exchange , total_exchange , disabled_exchange ) )
Run flux consistency check command