def collect_reactions_replicates(reactions=None): """ Collects information about reactions' replications arguments: reactions (dict<dict>): information about reactions returns: (list<dict>): information about reactions' replications raises: """ reactions_replicates = [] for reaction in reactions.values(): identifier = reaction["identifier"] # Collect identifiers of metabolites that participate as reactants and # products in the reaction reactants = utility.collect_reaction_participants_value( key="metabolite", criteria={"roles": ["reactant"]}, participants=reaction["participants"]) products = utility.collect_reaction_participants_value( key="metabolite", criteria={"roles": ["product"]}, participants=reaction["participants"]) # Determine whether collection includes a record for an identical # combination of reactants and products index = find_index_reactions_replicates_reactants_products( reactants=reactants, products=products, reactions_replicates=reactions_replicates) if index == -1: # Record does not exist # Create novel record record = { "reactions": [reaction["identifier"]], "reactants": reactants, "products": products } reactions_replicates.append(record) else: # Record exists # Include reaction in record reactions_replicates[index]["reactions"].append(identifier) return reactions_replicates
def collect_processes_metabolites_compartments(reactions=None): """ Collects information about processes' metabolites and compartments arguments: reactions (dict<dict>): information about reactions returns: (dict<dict<list<str>>>): information about compartments in which each metabolite participates in each process raises: """ collection = {} for reaction in reactions.values(): processes = reaction["processes"] for process in processes: if process not in collection: collection[process] = {} metabolites = utility.collect_reaction_participants_value( key="metabolite", criteria={}, participants=reaction["participants"]) for metabolite in metabolites: if metabolite not in collection[process]: collection[process][metabolite] = [] compartments = utility.collect_reaction_participants_value( key="compartment", criteria={"metabolites": [metabolite]}, participants=reaction["participants"]) for compartment in compartments: if compartment not in collection[process][metabolite]: collection[process][metabolite].append(compartment) return collection
def determine_reaction_conversion(reaction=None): """ Determines whether a reaction involves chemical conversion arguments: reaction (dict): information about a reaction returns: (bool): whether the reaction involves chemical conversion raises: """ reactant_metabolites = utility.collect_reaction_participants_value( key="metabolite", criteria={"roles": ["reactant"]}, participants=reaction["participants"]) product_metabolites = utility.collect_reaction_participants_value( key="metabolite", criteria={"roles": ["product"]}, participants=reaction["participants"]) return not utility.compare_lists_by_mutual_inclusion( list_one=reactant_metabolites, list_two=product_metabolites)
def convert_reactions_export_text( reactions=None, metabolites=None, compartments=None, processes=None, ): """ Converts information about reactions to text format. Converts identifiers of metabolites, compartments, and processes to names. arguments: reactions (dict<dict>): information about reactions metabolites (dict<dict>): information about metabolites compartments (dict<dict>): information about compartments processes (dict<dict>): information about processes returns: (list<dict>): information about reactions raises: """ records = [] for reaction in reactions.values(): # Participants. # Write a function to compose identifier (name) human readable... # Compartments compartments_identifiers = utility.collect_value_from_records( key="compartment", records=reaction["participants"]) compartments_identifiers_unique = utility.collect_unique_elements( elements_original=compartments_identifiers) compartments_names = utility.collect_values_from_records_in_reference( key="name", identifiers=compartments_identifiers_unique, reference=compartments, ) # Processes processes_names = utility.collect_values_from_records_in_reference( key="name", identifiers=reaction["processes"], reference=processes, ) # Metabolites reactants_identifiers = utility.collect_reaction_participants_value( key="metabolite", criteria={"roles": ["reactant"]}, participants=reaction["participants"]) reactants_names = utility.collect_values_from_records_in_reference( key="name", identifiers=reactants_identifiers, reference=metabolites, ) products_identifiers = utility.collect_reaction_participants_value( key="metabolite", criteria={"roles": ["product"]}, participants=reaction["participants"]) products_names = utility.collect_values_from_records_in_reference( key="name", identifiers=products_identifiers, reference=metabolites, ) # Compile information. record = { "identifier": reaction["identifier"], "name": reaction["name"], "reactants": "; ".join(reactants_names), "products": "; ".join(products_names), "compartments": "; ".join(compartments_names), "processes": ";".join(processes_names), "reversibility": reaction["reversibility"], "reference_metanetx": ("; ".join(reaction["references"]["metanetx"])), "reference_recon2m2": ("; ".join(reaction["references"]["recon2m2"])), "reference_gene": "; ".join(reaction["references"]["gene"]), "reference_enzyme": "; ".join(reaction["references"]["enzyme"]), "reference_kegg": "; ".join(reaction["references"]["kegg"]), "reference_reactome": ("; ".join(reaction["references"]["reactome"])), "reference_metacyc": "; ".join(reaction["references"]["metacyc"]), "reference_bigg": "; ".join(reaction["references"]["bigg"]), } records.append(record) return records
def collect_reaction_transports(reaction=None): """ Collects information about a reaction's transports. This procedure applies an overly restrictive definition of transport that requires chemically-identical metabolites in two separate compartments. Some transports involve chemical conversion of substrates as part of transport. arguments: reaction (dict): information about a reaction returns: (list<dict>): information about a reaction's transports raises: """ metabolites_reactant = utility.collect_reaction_participants_value( key="metabolite", criteria={"roles": ["reactant"]}, participants=reaction["participants"]) metabolites_product = utility.collect_reaction_participants_value( key="metabolite", criteria={"roles": ["product"]}, participants=reaction["participants"]) # Collect metabolites that participate as both reactants and products metabolites = utility.filter_common_elements(list_one=metabolites_product, list_two=metabolites_reactant) transports = [] for metabolite in metabolites: # Determine metabolite's compartments as reactant and product compartments_reactant = utility.collect_reaction_participants_value( key="compartment", criteria={ "metabolites": [metabolite], "roles": ["reactant"] }, participants=reaction["participants"]) compartments_product = utility.collect_reaction_participants_value( key="compartment", criteria={ "metabolites": [metabolite], "roles": ["product"] }, participants=reaction["participants"]) # Determine whether there is a difference between the metabolite's # compartments as reactant and product transport = not utility.compare_lists_by_mutual_inclusion( list_one=compartments_reactant, list_two=compartments_product) if transport: compartments = compartments_reactant + compartments_product compartments_unique = utility.collect_unique_elements( elements_original=compartments) record = { "metabolite": metabolite, "compartments": compartments_unique } transports.append(record) return transports