From 89283523e141e7013f0512864966eec0055970f2 Mon Sep 17 00:00:00 2001 From: "Gwendolyn O. Gusak" <81755070+GwennyGit@users.noreply.github.com> Date: Mon, 21 Aug 2023 15:26:18 +0100 Subject: [PATCH] Updated get_model_reacs_or_metabs in entities to be more general #43 The function get_model_reacs_or_metabs now takes a new parameter. If the model's metabolites/reactions are not from the BiGG namespace the parameter col_name can now be changed to a user-specific string. To not break the original code, col_name is by default set to 'bigg_id'. --- refinegems/entities.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/refinegems/entities.py b/refinegems/entities.py index 3ce8f07b..d583b30f 100644 --- a/refinegems/entities.py +++ b/refinegems/entities.py @@ -59,15 +59,16 @@ def compare_gene_lists(gps_in_model: pd.DataFrame, db_genes: pd.DataFrame, kegg: # Function originally from refineGEMs.genecomp/refineGEMs.KEGG_analysis --- Modified -def get_model_reacs_or_metabs(model_libsbml: libModel, metabolites: bool=False) -> pd.DataFrame: +def get_model_reacs_or_metabs(model_libsbml: libModel, metabolites: bool=False, col_name: str='bigg_id') -> pd.DataFrame: """Extracts table of reactions/metabolites with BiGG IDs from model Args: - model_libsbml (libModel): Model loaded with libSBML - metabolites (bool): Set to True if metabolites from model should be extracted + - col_name (str): Name to be used for column in Table, default: 'bigg_id' Returns: - pd.DataFrame: Table with BiGG IDs of reactions in the model + pd.DataFrame: Table with model identifiers for either metabolites or reactions """ reac_or_metab_list = model_libsbml.getListOfSpecies() if metabolites else model_libsbml.getListOfReactions() @@ -76,7 +77,7 @@ def get_model_reacs_or_metabs(model_libsbml: libModel, metabolites: bool=False) list_of_reacs_or_metabs.append(reac_or_metab.id[2:]) reac_or_metab_list_df = pd.Series(list_of_reacs_or_metabs) - reac_or_metab_list_df = pd.DataFrame(reac_or_metab_list_df, columns=['bigg_id']) + reac_or_metab_list_df = pd.DataFrame(reac_or_metab_list_df, columns=[col_name]) return reac_or_metab_list_df