dexom_python package top-level modules

Submodules

model_functions module

dexom_python.model_functions.check_model_options(model, timelimit=None, feasibility=1e-07, mipgaptol=0.001, verbosity=1)[source]
dexom_python.model_functions.get_all_reactions_from_model(model, save=True, shuffle=True, out_path='')[source]

Outputs a list of all reactions in the model. If possible, all blocked reactions are removed. Optionally, the reaction-list can be shuffled.

Parameters
  • model (cobra.Model) –

  • save (bool) – by default, exports the reactions in a csv format

  • shuffle (bool) – set to True to shuffle the order of the reactions

  • out_path (str) – output path

Returns

rxn_list

Return type

A list of all reactions in the model

dexom_python.model_functions.get_subsystems_from_model(model, save=True, out_path='')[source]

Creates a list of all subsystems of a model and their associated reactions

Parameters
  • model (cobra.Model) –

  • save (bool) –

  • out_path (str) –

Returns

  • rxn_sub (pandas.DataFrame) – a DataFrame with reaction names as index and subsystem name as column

  • sub_list (list) – a list of subsystems

dexom_python.model_functions.load_reaction_weights(filename, rxn_names='reactions', weight_names='weights')[source]

loads reaction weights from a .csv file

Parameters
  • filename (str) – the path + name of a .csv file containing reaction weights

  • rxn_names (str) – the name of the column containing the reaction names

  • weight_names (str) – the name of the column containing the weights

Returns

reaction_weights

Return type

dict

dexom_python.model_functions.read_model(modelfile, solver='cplex')[source]
dexom_python.model_functions.save_reaction_weights(reaction_weights, filename='reaction_weights.csv')[source]
Parameters
  • reaction_weights (dict) – a dictionary where keys = reaction IDs and values = weights

  • filename (str) –

Returns

reaction_weights

Return type

pandas.DataFrame

gpr_rules module

dexom_python.gpr_rules.apply_gpr(model, gene_weights, save=True, filename='reaction_weights', duplicates='remove', null=0.0)[source]

Applies the GPR rules from a given metabolic model for creating reaction weights

Parameters
  • model (cobra.Model) – a cobrapy model

  • gene_weights (dict or pd.Series) – a dictionary of pandas Series containing gene IDs & weights

  • save (bool) – if True, saves the reaction weights as a csv file

  • filename (str) – path where the file will be saved

  • duplicates (str, any of "remove", "max", "min", "mean", "median") – determines how to deal with genes presenting several expression values

  • null (float) – value to return for reactions/genes with no information

Returns

reaction_weights

Return type

dict where keys = reaction IDs and values = weights

dexom_python.gpr_rules.expression2qualitative(genes, column_list=None, proportion=0.25, method='keep', save=True, outpath='geneweights')[source]

Transforms gene expression values/ gene scores into qualitative gene weights

Parameters
  • genes (pandas.DataFrame) – dataframe with gene IDs in the index and gene expression values in a later column

  • column_list (list) – column indexes containing gene expression values to be transformed. If empty, all columns will be transformed

  • proportion (float) – proportion of genes to be used for determining high/low gene expression

  • method (str) – one of “max”, “mean” or “keep”. chooses how to deal with genes containing multiple conflicting expression values

  • save (bool) – if True, saves the resulting gene weights

  • outpath (str) – if save=True, the .csv file will be saved to this path

Returns

gene_weights – (-1 for low expression, 1 for high expression, 0 for in-between or no information)

Return type

a pandas DataFrame containing qualitative gene weights

dexom_python.gpr_rules.replace_MulMax_AddMin(expression)[source]

Function used for parsing gpr expressions

Parameters

expression (symengine expression) – a symengine/sympy expression of a gpr rule

imat_functions module

dexom_python.imat_functions.create_full_variable_single(model, rid, reaction_weights, epsilon, threshold)[source]
dexom_python.imat_functions.create_full_variables(model, reaction_weights, epsilon, threshold)[source]

Creates binary indicator variables in the model for every reaction.

dexom_python.imat_functions.create_new_partial_variable_single(model, rid, epsilon, threshold, pos)[source]
dexom_python.imat_functions.create_new_partial_variables(model, reaction_weights, epsilon, threshold)[source]

Creates binary indicator variables in the model for reactions with nonzero weight.

dexom_python.imat_functions.imat(model, reaction_weights=None, epsilon=0.0001, threshold=0.0001, full=False)[source]

Modified version of the integrative Metabolic Analysis Tool with reaction weights

Parameters
  • model (cobra.Model) – a cobrapy model

  • reaction_weights (dict) – keys are reaction IDs, values are weights

  • epsilon (float) – activation threshold for highly expressed reactions

  • threshold (float) – activation threshold for all reactions

  • full (bool) – if True, create variables for all reactions. if False, only for reactions with non-zero weights

Returns

solution

Return type

cobra.Solution

result_functions module

dexom_python.result_functions.combine_binary_solutions(sol_path, solution_pattern='*solutions*.csv', out_path='')[source]

Combines several binary solution files into one

Parameters
  • sol_path (str) – folder in which binary solutions are saved

  • solution_pattern (str) – pattern which is used to find binary solution files

  • out_path (str) – path to which the combined solutions are saved

Returns

uniquesol

Return type

pandas.DataFrame

dexom_python.result_functions.compile_solutions(solutions, out_path='compiled_solutions', solution_pattern='*.csv', model=None, threshold=None)[source]

Compiles individual solution files into one binary solution DataFrame

Parameters
  • solutions (list or str) – If list, must contain either solution files in .csv format, or Solution objects, or binary solution arrays. - If str, must be a folder in which all .csv files are solutions

  • out_path (str) – path to which the combined solutions will be saved

  • solution_pattern (str) – If reading solutions from a folder, this is the pattern which will be used to recognize solution files

  • model (cobrapy Model) – required if the solutions parameter is a list of Solution objects

  • threshold (float) – required if the solutions parameter is a list of Solution objects

Returns

sol_frame

Return type

pandas DataFrame containg binary solutions

dexom_python.result_functions.plot_pca(solution_path, rxn_enum_solutions=None, save=True, save_name='')[source]

Plots a 2-dimensional PCA of enumeration solutions

Parameters
  • solution_path (str) – csv file of enumeration solutions

  • rxn_enum_solutions (str) – csv file of enumeration solutions. If specified, will plot these solutions in a different color

  • save (bool) – if True, the pca-plot will be saved

  • save_name (str) – name of the file to save

Returns

pca

Return type

sklearn.decomposition.PCA

dexom_python.result_functions.read_solution(filename, model=None)[source]

Reads a solution from a .csv file. If the provided file is a binary solutions file (as output by enumeration methods), the first solution will be read

Parameters
  • filename (str) – name of the file containing the solution

  • model (cobra.Model) – required if the filename points to a binary solution file

Returns

  • solution (cobra.Solution)

  • sol_bin (numpy.array)

dexom_python.result_functions.write_solution(model, solution, threshold, filename='imat_sol.csv')[source]

Writes an optimize solution as a txt file. The solution is written in a column format :param solution: :type solution: cobra.Solution :param threshold: :type threshold: float :param filename: :type filename: str

toy_models module

dexom_python.toy_models.create_reaction(model, rname, formula, gene_rule=None, fullname=None, lower_bound=0.0, upper_bound=1000.0)[source]
dexom_python.toy_models.dagNet(num_layers, num_metabolites_per_layer, export=False, solver='cplex')[source]

Creates a dagNet model where the metabolites of successive layers are all interconnected

Parameters
  • num_layers (int) – number of layers

  • num_metabolites_per_layer (int) – number of metabolites per layer

  • export (bool) – if True, exports the model as .json and the reaction weights as .csv

  • solver (str) – a valid cobrapy solver

Returns

  • model (cobra.Model)

  • reaction_weights (dict)

dexom_python.toy_models.r13m10(export=False, solver='cplex')[source]

This is the model that is used for the unit tests in the tests folder :param export: if True, exports the model as .json and the reaction weights as .csv :type export: bool :param solver: a valid cobrapy solver :type solver: str

Returns

  • model (cobra.Model)

  • reaction_weights (dict)

dexom_python.toy_models.small4M(export=False, solver='cplex')[source]

creates the small4M model

Parameters
  • export (bool) – if True, exports the model as .json and the reaction weights as .csv

  • solver (str) – a valid cobrapy solver

Returns

  • model (cobra.Model)

  • reaction_weights (dict)

dexom_python.toy_models.small4S(export=False, solver='cplex')[source]

creates the small4S model

Parameters
  • export (bool) – if True, exports the model as .json and the reaction weights as .csv

  • solver (str) – a valid cobrapy solver

Returns

  • model (cobra.Model)

  • reaction_weights (dict)

pathway_enrichment module

dexom_python.pathway_enrichment.Fischer_groups(model, solpath, outpath='test')[source]

!!! This only works if the pathway name is stored in the model.groups property !!! For models where the pathways are stored in the model.reactions.subsystem property, use the Fischer_pathways function

Performs pathway over- and underrepresentation analysis

Parameters
  • solpath (file containing DEXOM solutions) –

  • subframe (csv file associating reactions with subsystems) –

  • sublist (list of subsystems) –

  • outpath (path to which results are saved) –

Returns

over, under

Return type

pandas.DataFrames (saved as .csv files) containing -log10 BH-adjusted p-values

dexom_python.pathway_enrichment.Fisher_pathways(solpath, subframe, sublist, outpath='')[source]

!!! This only works if the pathway name is stored in the model.reaction.subsystem property !!! For models where the pathways are stored in the model.groups property, use the new Fischer_groups function

Performs pathway over- and underrepresentation analysis

Parameters
  • solpath (file containing DEXOM solutions) –

  • subframe (csv file associating reactions with subsystems) –

  • sublist (list of subsystems) –

  • outpath (path to which results are saved) –

Returns

over, under

Return type

pandas.DataFrames (saved as .csv files) containing -log10 BH-adjusted p-values

dexom_python.pathway_enrichment.plot_Fisher_pathways(filename_over, filename_under, sublist, outpath='pathway_enrichment')[source]

dexom_cluster_results module

dexom_python.dexom_cluster_results.analyze_dexom_cluster_results(in_folder, out_folder, approach=1, filenums=100)[source]
Parameters
  • in_folder (str) – folder containing dexom results

  • out_folder (str) – folder in which output files will be saved

  • approach (int) – which parallelization approach was used (1, 2, or 3, see enum_functions/enumeration for details)

  • filenums (int) – number of parallel dexom threads that were run

Module contents