def collect_processes_metabolites_compartments( reactions=None): collection = {} for reaction in reactions.values(): processes = reaction['processes'] for process in processes: if process not in collection: collection[process] = {} metabolites = collect_reaction_participants_value( key='metabolite', criteria={}, participants=reaction['participants']) for metabolite in metabolites: if metabolite not in collection[process]: collection[process][metabolite] = [] compartments = 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 collect_reaction_transports( reaction): metabolites_reactant = collect_reaction_participants_value( key='metabolite', criteria={'roles': ['reactant']}, participants=reaction['participants']) metabolites_product = collect_reaction_participants_value( key='metabolite', criteria={'roles': ['product']}, participants=reaction['participants']) # Collect metabolites that participate as both reactants and products metabolites = 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 = collect_reaction_participants_value( key='compartment', criteria={ 'metabolites': [metabolite], 'roles': ['reactant']}, participants=reaction['participants']) compartments_product = 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 compare_lists_by_mutual_inclusion( list_one=compartments_reactant, list_two=compartments_product) if transport: compartments = compartments_reactant + compartments_product compartments_unique = collect_unique_elements( elements_original=compartments) record = { 'metabolite': metabolite, 'compartments': compartments_unique} transports.append(record) return transports
def determine_reaction_conversion( reaction): reactant_metabolites = collect_reaction_participants_value( key='metabolite', criteria={'roles': ['reactant']}, participants=reaction['participants']) product_metabolites = collect_reaction_participants_value( key='metabolite', criteria={'roles': ['product']}, participants=reaction['participants']) return not compare_lists_by_mutual_inclusion( list_one=reactant_metabolites, list_two=product_metabolites)
def collect_reactions_replicates( reactions): reactions_replicates = [] for reaction in reactions.values(): identifier = reaction['identifier'] # Collect identifiers of metabolites that participate as reactants and # products in the reaction reactants = collect_reaction_participants_value( key='metabolite', criteria={'roles': ['reactant']}, participants=reaction['participants']) products = 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 convert_reactions_export_text(reactions, metabolites, compartments, processes): records = [] for reaction in reactions.values(): # Get participants # Write a function to compose identifier (name) human readable... # Compartments compartments_identifiers = collect_value_from_records( key='compartment', records=reaction['participants']) compartments_identifiers_unique = collect_unique_elements( elements_original=compartments_identifiers) compartments_names = collect_values_from_records_in_reference( key='name', identifiers=compartments_identifiers_unique, reference=compartments) # Processes processes_names = collect_values_from_records_in_reference( key='name', identifiers=reaction['processes'], reference=processes) # Metabolites reactants_identifiers = collect_reaction_participants_value( key='metabolite', criteria={'roles': ['reactant']}, participants=reaction['participants']) reactants_names = collect_values_from_records_in_reference( key='name', identifiers=reactants_identifiers, reference=metabolites) products_identifiers = collect_reaction_participants_value( key='metabolite', criteria={'roles': ['product']}, participants=reaction['participants']) products_names = 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_recon': ('; '.join(reaction['references']['recon'])), '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