def run(self):
obj_reaction = self._get_objective()<EOL>genes = set()<EOL>gene_assoc = {}<EOL>for reaction in self._model.reactions:<EOL><INDENT>assoc = None<EOL>if reaction.genes is None:<EOL><INDENT>continue<EOL><DEDENT>elif isinstance(reaction.genes, string_types):<EOL><INDENT>assoc = boolean.Expression(reaction.genes)<EOL><DEDENT>else:<EOL><INDENT>variables = [boolean.Variable(g) for g in reaction.genes]<EOL>assoc = boolean.Expression(boolean.And(*variables))<EOL><DEDENT>genes.update(v.symbol for v in assoc.variables)<EOL>gene_assoc[reaction.id] = assoc<EOL><DEDENT>reactions = set(self._mm.reactions)<EOL>start_time = time.time()<EOL>testing_genes = set(self._args.gene)<EOL>deleted_reactions = set()<EOL>logger.info('<STR_LIT>'.format(<EOL>'<STR_LIT:U+002CU+0020>'.join(sorted(testing_genes))))<EOL>for reaction in reactions:<EOL><INDENT>if reaction not in gene_assoc:<EOL><INDENT>continue<EOL><DEDENT>assoc = gene_assoc[reaction]<EOL>if any(boolean.Variable(gene) in assoc.variables<EOL>for gene in testing_genes):<EOL><INDENT>new_assoc = assoc.substitute(<EOL>lambda v: v if v.symbol not in testing_genes else False)<EOL>if new_assoc.has_value() and not new_assoc.value:<EOL><INDENT>logger.info('<STR_LIT>'.format(reaction))<EOL>deleted_reactions.add(reaction)<EOL><DEDENT><DEDENT><DEDENT>if self._args.method in ['<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>solver = self._get_solver(quadratic=True)<EOL><DEDENT>else:<EOL><INDENT>solver = self._get_solver()<EOL><DEDENT>if self._args.method == '<STR_LIT>':<EOL><INDENT>logger.info('<STR_LIT>')<EOL>prob = fluxanalysis.FluxBalanceProblem(self._mm, solver)<EOL>try:<EOL><INDENT>prob.maximize(obj_reaction)<EOL><DEDENT>except fluxanalysis.FluxBalanceError as e:<EOL><INDENT>self.report_flux_balance_error(e)<EOL><DEDENT>wild = prob.get_flux(obj_reaction)<EOL>for reaction in deleted_reactions:<EOL><INDENT>flux_var = prob.get_flux_var(reaction)<EOL>prob.prob.add_linear_constraints(flux_var == <NUM_LIT:0>)<EOL><DEDENT>prob.maximize(obj_reaction)<EOL>deleteflux = prob.get_flux(obj_reaction)<EOL><DEDENT>elif self._args.method in ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>prob = moma.MOMAProblem(self._mm, solver)<EOL>wt_fluxes = prob.get_minimal_fba_flux(obj_reaction)<EOL>wild = wt_fluxes[obj_reaction]<EOL>for reaction in deleted_reactions:<EOL><INDENT>flux_var = prob.get_flux_var(reaction)<EOL>prob.prob.add_linear_constraints(flux_var == <NUM_LIT:0>)<EOL><DEDENT>try:<EOL><INDENT>if self._args.method == '<STR_LIT>':<EOL><INDENT>logger.info('<STR_LIT>')<EOL>prob.moma(wt_fluxes)<EOL><DEDENT>elif self._args.method == '<STR_LIT>':<EOL><INDENT>logger.info('<STR_LIT>')<EOL>prob.lin_moma(wt_fluxes)<EOL><DEDENT>elif self._args.method == '<STR_LIT>':<EOL><INDENT>logger.info('<STR_LIT>')<EOL>prob.moma2(obj_reaction, wild)<EOL><DEDENT>elif self._args.method == '<STR_LIT>':<EOL><INDENT>logger.info('<STR_LIT>')<EOL>prob.lin_moma2(obj_reaction, wild)<EOL><DEDENT><DEDENT>except moma.MOMAError:<EOL><INDENT>self.fail('<STR_LIT>')<EOL><DEDENT>deleteflux = prob.get_flux(obj_reaction)<EOL><DEDENT>logger.info(<EOL>'<STR_LIT>'.format(time.time() - start_time))<EOL>logger.info(<EOL>'<STR_LIT>'.format(<EOL>deleteflux + <NUM_LIT:0>))<EOL>if wild != <NUM_LIT:0>:<EOL><INDENT>logger.info(<EOL>'<STR_LIT>'.format(<EOL>abs(deleteflux / wild)))<EOL><DEDENT>
Delete the specified gene and solve using the desired method.