fluxpy.utils ============ .. py:module:: fluxpy.utils .. autoapi-nested-parse:: Provide utilities for metabolic modeling analysis tasks Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/fluxpy/utils/analysis/index /autoapi/fluxpy/utils/format/index /autoapi/fluxpy/utils/model/index /autoapi/fluxpy/utils/utils/index Classes ------- .. autoapisummary:: fluxpy.utils.Models fluxpy.utils.NameIdConverter fluxpy.utils.CompareModels Functions --------- .. autoapisummary:: fluxpy.utils.nonzero_fluxes fluxpy.utils.get_rxns_producing_consuming_met fluxpy.utils.extract_model_namespace fluxpy.utils.convert_gbk_to_faa fluxpy.utils.get_nutrients_gradient fluxpy.utils.parse_qfca fluxpy.utils.samples_on_qfca fluxpy.utils.producing_or_consuming_a_met fluxpy.utils.get_reactions_producing_a_met fluxpy.utils.trace_path_with_backtracking_iterative fluxpy.utils.map_namespace_to_ModelSEEDDatabase fluxpy.utils.map_to_namespace fluxpy.utils.sync_with_medium Package Contents ---------------- .. py:function:: nonzero_fluxes(fluxes: Union[cobra.Solution, pandas.Series]) -> None Returns nonzero fluxes from a pandas Series. This function takes a pandas Series containing flux values and returns a new Series with only the nonzero fluxes. :param sol: A pandas Series representing flux values. :type sol: pd.Series, mandatory :returns: A pandas Series containing only the nonzero flux values from the input Series. :rtype: pd.Series .. py:function:: get_rxns_producing_consuming_met(met_id, model: cobra.Model = None, flux_vector: pandas.Series = None) Returns a DataFrame with the reaction IDs of those consuming and producing a given metabolite in a model. This function optimizes the given metabolic model to identify reactions involving a specified metabolite. It categorizes reactions into those producing and those consuming the metabolite and returns this information in a DataFrame. :param model: The metabolic model to be analyzed. :type model: cobra.Model, mandatory :param met_id: The ID of the metabolite of interest. :type met_id: str, optional :param flux_vector: :type flux_vector: pd.Series, optional :returns: A DataFrame with two columns: - `consuming_{met_id}`: Reactions consuming the specified metabolite in flux vector provided - `producing_{met_id}`: Reactions producing the specified metabolite in flux vector provided :rtype: pd.DataFrame .. rubric:: Examples >>> import cobra >>> model = cobra.io.read_sbml_model('e_coli_core.xml') >>> df = get_reactions_producing_met(model, 'met_id') >>> print(df) consuming_met_id producing_met_id 0 reaction1 reaction2 .. rubric:: Notes - The function assumes the model is properly optimized and that each reaction's flux can be accessed via the solution object. - Reactions with a flux less than 0 are considered to be consuming reactants and producing products in the reverse direction. - Reactions with a flux greater than 0 are considered to be producing reactants and consuming products in the forward direction. - This applies for the specific medium provided with the model .. py:function:: extract_model_namespace(model) Returns a model's namespace considering only ModelSEED and BiGG :param model: :type model: cobra.Model, mandatory :returns: namespace (str) -- a Literal["modelseed", "bigg"] .. py:function:: convert_gbk_to_faa(gbk_input_filename, faa_output_filename) A function to convert a .gbk file returned from the RAST annotation to a .faa that can be used with ModelSEEDpy .. py:function:: get_nutrients_gradient(model, nutrients=None, upper_bound=None, step=None) -> fluxpy.utils.utils.NestedDataFrameType Assuming a single medium comound changes at a time, it returns FVA findings over the chaning envs. The model.medium will be used, i.e. first set the medium you want to investigate to your model. Returns a df with as many rows as the model.medium and columns as many as their quotient by the step. Each cell of this df includes the fva result for the medium with the corresponding alteration. For example, df.loc[0,0] corresponds to the medium where the first compound has the lowest value possible. model -- a cobra model nutrients -- list of reaction ids for which a gradient will be calculated upper_bound -- maximum a flux can get step -- increase of upper_bound in each iteration of the gradient .. py:function:: parse_qfca(qfca_output, model=None, remove_exchange_routes=True, exclude_biomass=True, format='csv') Parses QFCA (Quantitative Fatty Acid Composition Analysis) output data into a networkx graph representation. :param qfca_output: Path to the QFCA output file in CSV or Excel format. :type qfca_output: str :param model: Metabolic model object. Default is None. :type model: object, optional :param remove_exchange_routes: Whether to remove exchange reactions from the graph. Default is True. :type remove_exchange_routes: bool, optional :param exclude_biomass: Whether to exclude biomass reaction from the graph. Default is True. :type exclude_biomass: bool, optional :param format: Format of the QFCA output file. Can be 'csv' or 'xlsx'. Default is 'csv'. :type format: str, optional :returns: A networkx Graph representing the interactions between metabolic reactions based on QFCA data. :rtype: nx.Graph .. py:function:: samples_on_qfca(qfca_graph, samples) ongoing .. py:function:: producing_or_consuming_a_met(model, reaction_id, metabolite_id) Returns whether a metabolite is being produced or consumed when model is optimized. :param model: :type model: cobra.Model :param reaction_id: :type reaction_id: str :param metabolite_id: :type metabolite_id: str :returns: 'producing | consuming' (str) .. py:function:: get_reactions_producing_a_met(model, metabolite_id) Get reactions that produce a specific metabolite. .. rubric:: Notes Exloits the producing_or_consuming_a_met() function :param model: :type model: cobra.Model :param metabolite_id: :type metabolite_id: str :returns: list of reactions (cobra.Reaction) .. py:function:: trace_path_with_backtracking_iterative(model, start_reaction_id, target_reaction_id, ignore_mets=None) Trace a path from the start reaction to the target reaction through reactants, using an iterative DFS approach, with backtracking when exchange reactions are encountered. :param model: COBRApy model object. :type model: cobra.Model :param start_reaction_id: The ID of the starting reaction. :type start_reaction_id: str :param target_reaction_id: The ID of the target reaction. :type target_reaction_id: str :param ignore_mets: A list of metabolite IDs to ignore during tracing (optional). :returns: A set of reactions needed to go from start to target, avoiding dead-end exchange reactions. :rtype: keep_rxns .. py:function:: map_namespace_to_ModelSEEDDatabase(seed_compounds: List[str], path_to_modelSEEDDatabase: str, annotations_to_keep=['BiGG', 'BiGG1']) This function makes use of the ModelSEEDpy and the ModelSEEDDatabase libraries to map a list of ModelSEED compounds to their annotations returning a pandas dataframe with those seed_compouds -- a list with seed compound ids path_to_modelSEEDDatabase -- path to the modelSEEDDatabase. To get it: git clone https://github.com/ModelSEED/ModelSEEDDatabase.git .. py:function:: map_to_namespace(compounds, from_namespace='seed', to_namespace='bigg') compounds -- a list from_namesapce -- to_namespace -- .. py:function:: sync_with_medium(model: cobra.Model, medium: Dict) Adds metabolites and reactions required to allow a medium to be assigned to a cobra.Model :param model: model to which the new medium will be assigned to and to which metabolites and reactions will be added to :type model: cobra.Model, mandatory :param medium: a dictionary with the medium to be used with the metabolites as keys and their boundaries as values :type medium: Dict, mandatory :returns: A cobra.Model with added metabolites and reactions to enable medium to be used .. py:class:: Models(model_list: List[str], model_names: List[str] = None) Load a list of sbml models with cobra as attributes of a class. .. py:class:: NameIdConverter(model, to_convert: Union[pandas.DataFrame, Dict, List, cobra.Solution], convert: str, to: str) A class to switch indexes of a dataframe from ids to names and vice versa for metabolites and reactions of a model. .. py:attribute:: met_map_df .. py:attribute:: react_map_df .. py:attribute:: convert .. py:attribute:: to .. py:attribute:: model .. py:attribute:: isIndex .. py:method:: run_convert() .. py:method:: _met_ids_to_met_names() .. py:method:: _met_names_to_met_ids() .. py:method:: _react_ids_to_react_names() .. py:method:: _react_names_to_react_ids() .. py:class:: CompareModels(model_list: List[str], trans_to_db=None) Using mergem to compare a pair of models and returns a dataframe with reactions unique in model1 and model2 and those they share. Key arguments: model_list -- list of paths to model files to compare trans_to_db -- mergem allows to map metabolite and reaction ids to a series of namespaces. .. py:attribute:: number_of_models .. py:attribute:: model_names .. py:attribute:: models .. py:attribute:: namespace :value: None .. py:attribute:: res .. py:attribute:: metabolites_df .. py:attribute:: reactions_df .. py:method:: unique_metabolites(model_name) Returns: unique_mets -- a pd.Index with the metabolites that are only present in model_name and not in any other of those in model_list .. py:method:: unique_reactions(model_name) Key arguments: model_name -- the name (column name) of the model for which unique reactions will be found Returns: model_unique_reactions -- a pd.Index with the reactions that are only present in the model_name and not in any other of those in model_list .. py:method:: compare_model_pair(base_model=None, model_to_compare=None) Compare pairwise models Key arguments: base_model -- name of the model as in dataframe, i.e. filename without the extension model_to_compare -- name of the model as in dataframe, i.e. filename without the extension Returns: r1 -- reactions only present in base model r2 -- reactions only present in model_to_compare m1 -- metabolites only present in base_model m2 -- metabolites only present in model_to_compare .. py:method:: shared_metabolites(models_subset=None) Key arguments: models_subset -- list of models to get shared metabolites and reactions Returns: shared_reactions -- a pd.Index with rearctions present among all models of models_subset .. py:method:: shared_reactions(models_subset=None) Key arguments: models_subset -- list of models to get shared metabolites and reactions Returns: shared_reactions -- a pd.Index with rearctions present among all models of models_subset