def get_r_id2fva_bounds(model, threshold=None, rs=None): r_id2min_max = flux_variability_analysis(model, reaction_list=rs) r_id2bounds = {} for r_id, values in r_id2min_max.items(): min_v, max_v = round_value(values['minimum']), round_value(values['maximum']) if threshold is None or abs(min_v) > threshold or abs(max_v) > threshold: r_id2bounds[r_id] = min_v, max_v return r_id2bounds
def get_fluxes_larger_than_threshold(model, threshold=0): r_id2val = {} for r_id, value in model.solution.x_dict.items(): value = round_value(value) if threshold is None or abs(value) > threshold: r_id2val[r_id] = value return r_id2val
def get_boundary_metabolites(N, v): ms = np.dot(N, v) replace_zeros(ms) divider = 1.0 * min(chain([0], (abs(it) for it in ms if it))) if divider: ms /= divider return np.array([round_value(it) for it in ms])
def analyse_by_fva(cobra_model, bm_r_id, objective_sense=MAXIMIZE, threshold=0): cobra_bm_r_id = format_r_id(bm_r_id) opt_value = optimise_biomass(cobra_model, cobra_bm_r_id, objective_sense, level=logging.DEBUG) if opt_value: opt_value = round_value(opt_value) r_id2bounds = get_r_id2fva_bounds(cobra_model, threshold=threshold) return r_id2bounds, opt_value return {}, None
def analyse_by_fba(cobra_model, bm_r_id, objective_sense=MAXIMIZE, threshold=0): cobra_bm_r_id = format_r_id(bm_r_id) opt_value = optimise_biomass(cobra_model, cobra_bm_r_id, objective_sense, level=logging.DEBUG) if opt_value: opt_value = round_value(opt_value) r_id2val = get_fluxes_larger_than_threshold(cobra_model, threshold=threshold) return r_id2val, opt_value return {}, None
def filter_efms(in_path, r_id2i, rev_r_id2i, out_path, r_id2rev=None, threshold=ZERO_THRESHOLD): i2r_id = {i: (r_id, False) for (r_id, i) in r_id2i.items()} i2r_id.update({i: (r_id, True) for (r_id, i) in rev_r_id2i.items()}) efms = [] rejected_bad, rejected_different = 0, 0 get_key = lambda r_id2coeff: \ tuple(sorted(((r_id, coefficient_to_binary(coeff)) for (r_id, coeff) in r_id2coeff.items()))) processed = set() with open(out_path, 'w+') as out_f: with open(in_path, 'r') as in_f: for line in in_f: values = line.replace("\n", "").strip().split(" ") r_id2coefficient = {} bad_em = False for i, v in enumerate(values, start=1): v = round_value(v) if not v or abs(v) <= threshold: continue r_id, rev = i2r_id[i] if rev: v *= -1 # The same reaction participates in different directions # => don't want such an EFM if r_id in r_id2coefficient: bad_em = True break r_id2coefficient[r_id] = v if bad_em: rejected_bad += 1 continue if r_id2rev: for (r_id, rev) in r_id2rev.items(): if r_id not in r_id2coefficient or (rev is not None and rev != (r_id2coefficient[r_id] < 0)): rejected_different += 1 bad_em = True break if bad_em: continue key = get_key(r_id2coefficient) if key in processed: continue processed.add(key) out_f.write(line) efms.append(r_id2coefficient) if rejected_different: logging.info('Rejected %d EFMs as not all of the reactions of interest were present in them.' % rejected_different) if rejected_bad: logging.info('Rejected %d EFMs as they contained reversible reactions in both directions' % rejected_bad) return efms
def format_p(p_id): fm_yield = S.get_yield(p_id, in_m_id, out_m_id) if fm_yield is not None: return 'Yield: %g' % round_value(fm_yield) return ''