Example #1
0
def get_mets_in_path(path, pathway_dict, reaction_dict):
    ov_mets = []
    rxns = pathway_dict[path]['rxns']
    for rxn in rxns:
        rxn_string = reaction_dict[rxn]['bigg_string']
        [mets, stoich, rev] = parseRxnString(rxn_string)
        ov_mets = list(set(ov_mets + mets))
    return ov_mets
Example #2
0
def create_rxn_met_dict(rxn_string):
    [mets,stoich,rev] = parseRxnString(rxn_string)
    metabolites = {}
    for i in range(0,len(mets)):
        met = mets[i]
        s = stoich[i]
        metabolites[met] = s
    return metabolites
Example #3
0
def findRxnsFromMet(met, reaction_dict, metabolite_dict):
    involved_rxns = []
    met_id = metabolite_dict[met]['bigg_id']
    for rxn in reaction_dict['reactions']:
        rxn_string = reaction_dict[rxn]['bigg_string']
        [rxn_mets, rxn_stoich, rxn_rev] = parseRxnString(rxn_string)
        if met_id in rxn_mets:
            involved_rxns.append(rxn)
    return involved_rxns
Example #4
0
def from_rev_get_bounds(rxn_string):
    [mets,stoich,rev] = parseRxnString(rxn_string)
    if rev == 0:
        lb = 0
        ub = 1000
    elif rev == 1:
        lb = -1000
        ub = 1000
    return lb,ub
Example #5
0
def combineRxnStrings(str1, str2):
    # example inputs
    #   str1 = 'pyr_c + nadh_c + 2 h_c => etoh_c + co2_c + nad_c'
    #   str2 = 'etoh_c + accoa_c =>  etylace_c + coa_c'
    [mets1, stoich1, rev1] = parseRxnString(str1)
    [mets2, stoich2, rev2] = parseRxnString(str2)
    ov_mets = list(set(mets1 + mets2))
    ov_stoich = list(np.zeros((len(ov_mets), ), dtype=int))
    for met in mets1:
        met_stoich = stoich1[mets1.index(met)]
        ov_met_index = ov_mets.index(met)
        ov_stoich[ov_met_index] = ov_stoich[ov_met_index] + met_stoich
    for met in mets2:
        met_stoich = stoich2[mets2.index(met)]
        ov_met_index = ov_mets.index(met)
        ov_stoich[ov_met_index] = ov_stoich[ov_met_index] + met_stoich
    ov_string = write_rxn_string_from_mets_and_stoich(ov_mets, ov_stoich)
    return ov_string
Example #6
0
def rxnChargeBalance(rxn, reaction_dict, metabolite_dict):
    charge_sum = 0
    [mets, stoich, rev] = parseRxnString(reaction_dict[rxn]['bigg_string'])
    for met in mets:
        met_i = mets.index(met)
        met_id = met[:-2]
        met_name = findMetNameFromID(met, metabolite_dict)
        charge = metabolite_dict[met_name]['charge']
        charge_sum = charge_sum + charge * stoich[met_i]
    return charge_sum
Example #7
0
def calculateMissingCharge(rxn, missing_met, reaction_dict, metabolite_dict):
    [mets, stoich, rev] = parseRxnString(reaction_dict[rxn]['bigg_string'])
    cum = 0
    met_i = mets.index(missing_met)
    for met in mets:
        if met != missing_met:
            m_i = mets.index(met)
            met_name = findMetNameFromID(met, metabolite_dict)
            cum = cum + stoich[m_i] * metabolite_dict[met_name]['charge']
    missing_charge = -1 * (cum / stoich[met_i])
    return missing_charge
Example #8
0
def isRxnSolvable(rxn, reaction_dict, metabolite_dict):
    [mets, stoich, rev] = parseRxnString(reaction_dict[rxn]['bigg_string'])
    solve_check = 0
    for met in mets:
        met_name = findMetNameFromID(met, metabolite_dict)
        if metabolite_dict[met_name]['charge'] == 'NA':
            solve_check = solve_check + 1
    if solve_check > 1:
        solvable = False
    else:
        solvable = True
    return solvable
Example #9
0
def check_rxn_mass_sum(rxn, reaction_dict, metabolite_dict):
    [mets, stoich, rev] = parseRxnString(reaction_dict[rxn]['bigg_string'])
    mass_sum = 0
    for met in mets:
        met_i = mets.index(met)
        #print(met)
        met_name = findMetNameFromID(met, metabolite_dict)
        met_formula = metabolite_dict[met_name]['formula']
        #print(met_formula)
        mf = Formula(met_formula)
        met_mass = mf.mass
        mass_sum = mass_sum + met_mass * stoich[met_i]
    return mass_sum
Example #10
0
def mass_check_for_rxn(rxn, reaction_dict, metabolite_dict):
    missing_mets = find_missing_metabolites(metabolite_dict)
    [mets, stoich, rev] = parseRxnString(reaction_dict[rxn]['bigg_string'])
    met_check = any(item in missing_mets for item in mets)
    if met_check is True:
        mass_check = False
    else:
        mass_sum = check_rxn_mass_sum(rxn, reaction_dict, metabolite_dict)
        if mass_sum <= 0.01 and mass_sum >= -0.01:
            mass_check = True
        else:
            mass_check = False
    return mass_check
Example #11
0
def charge_check_for_rxn(rxn, reaction_dict, metabolite_dict):
    missing_mets = find_missing_metabolites(metabolite_dict)
    [mets, stoich, rev] = parseRxnString(reaction_dict[rxn]['bigg_string'])
    met_check = any(item in missing_mets for item in mets)
    if met_check is True:
        charge_check = False
    else:
        charge_sum = rxnChargeBalance(rxn, reaction_dict, metabolite_dict)
        if charge_sum == 0:
            charge_check = True
        else:
            charge_check = False
    return charge_check
Example #12
0
def findRxnsThatConsumeMet(met_id, reaction_dict, metabolite_dict):
    consuming_rxns = []
    #met_id = metabolite_dict[met]['bigg_id']
    for rxn in reaction_dict['reactions']:
        rxn_string = reaction_dict[rxn]['bigg_string']
        [rxn_mets, rxn_stoich, rxn_rev] = parseRxnString(rxn_string)
        if rxn_rev == 1:
            if met_id in rxn_mets:
                consuming_rxns.append(rxn)
        elif rxn_rev == 0:
            if met_id in rxn_mets:
                if rxn_stoich[rxn_mets.index(met_id)] < 0:
                    consuming_rxns.append(rxn)
    return consuming_rxns
Example #13
0
def get_all_info_from_db_path(path,pathway_dict,reaction_dict,metabolite_dict,mmdb_path):
    if path not in pathway_dict['pathways']:
        pathway_dict = add_path_from_db_to_dict(path,pathway_dict,mmdb_path)
        pathway_rxns = get_db_pathway_rxns_from_id(mmdb_path,path)
        for rxn in pathway_rxns:
            if rxn not in reaction_dict['reactions']:
                reaction_dict = retrieve_rxn_info_from_db(rxn,reaction_dict,mmdb_path)
                rxn_string = reaction_dict[rxn]['bigg_string']
                [mets,stoich,rev] = parseRxnString(rxn_string)
                for met_id in mets:
                    list_of_ids = get_list_of_met_bigg_ids_in_metabolite_dict(metabolite_dict)
                    if met_id not in list_of_ids:
                        met = find_met_name_from_bigg_id_in_db(met_id,mmdb_path)
                        metabolite_dict = retrieve_metabolite_info_from_db(met,mmdb_path,metabolite_dict)
    return metabolite_dict,reaction_dict,pathway_dict
Example #14
0
def write_node_rxn_string(rxn, reaction_dict, metabolite_dict):
    rxn_string = reaction_dict[rxn]['bigg_string']
    [mets, stoich, rev] = parseRxnString(rxn_string)
    node1 = reaction_dict[rxn]['nodes'][0]
    node2 = reaction_dict[rxn]['nodes'][1]
    node1_id = node1
    node2_id = node2
    node1_ind = mets.index(node1_id)
    node2_ind = mets.index(node2_id)
    node_mets = [node1_id, node2_id]
    node_stoich = [stoich[node1_ind], stoich[node2_ind]]
    pos = [idx for idx, val in enumerate(node_stoich) if val > 0][0]
    neg = [idx for idx, val in enumerate(node_stoich) if val < 0][0]
    reactant = node_mets[neg]
    product = node_mets[pos]
    arrow = get_rxn_arrow_from_rev(rev)
    node_rxn_string = reactant + ' ' + arrow + ' ' + product
    return node_rxn_string
Example #15
0
def get_pathway_stoich(path, precursor, pathway_dict, reaction_dict,
                       metabolite_dict):
    ov_mets = get_mets_in_path(path, pathway_dict, reaction_dict)
    ov_stoich = list(np.zeros((len(ov_mets), ), dtype=int))
    rxns = pathway_dict[path]['rxns']
    current_node = metabolite_dict[precursor]['bigg_id']
    for rxn in rxns:
        rxn_string = reaction_dict[rxn]['bigg_string']
        [mets, stoich, rev] = parseRxnString(rxn_string)
        current_node_index = mets.index(current_node)
        current_node_stoich = stoich[current_node_index]
        nodes = reaction_dict[rxn]['nodes']
        next_node = get_next_node(current_node, rxn, reaction_dict)
        if current_node_stoich > 0 and rev == 1:
            stoich = [i * -1 for i in stoich]
        for met in mets:
            met_stoich = stoich[mets.index(met)]
            ov_met_index = ov_mets.index(met)
            ov_stoich[ov_met_index] = ov_stoich[ov_met_index] + met_stoich
        current_node = next_node
    return ov_mets, ov_stoich
Example #16
0
def addAllRxnsFromRxnDict(reaction_dict, metabolite_dict):
    # add metabolites and reactions to a cobra model
    model = Model('local_network')
    for rxn in reaction_dict['reactions']:
        nodes = reaction_dict[rxn]['nodes']
        node1 = nodes[0]
        node2 = nodes[1]
        id1 = metabolite_dict[node1]['bigg_id']
        id2 = metabolite_dict[node2]['bigg_id']
        rxn_string = reaction_dict[rxn]['bigg_string']
        [mets, stoich, rev] = parseRxnString(rxn_string)
        node1_i = mets.index(id1)
        node2_i = mets.index(id2)
        stoich1 = stoich[node1_i]
        stoich2 = stoich[node2_i]
        [ub, lb] = getBoundsFromRev(rev)
        reaction = Reaction(rxn)
        reaction.lower_bound = lb
        reaction.upper_bound = ub
        n1 = Metabolite(id1)
        n2 = Metabolite(id2)
        reaction.add_metabolites({n1: stoich1, n2: stoich2})
        model.add_reactions([reaction])
    return model