dexom_python package top-level modules
Submodules
model_functions module
- dexom_python.model_functions.check_model_options(model, timelimit=600, tolerance=1e-07, mipgaptol=0.001, verbosity=1)[source]
Sets model options such as timelimit, tolerance, mipgapt tolerance, and verbosity
- Parameters:
model (cobra.Model) –
timelimit (int) –
tolerance (float) –
mipgaptol (float) –
verbosity (int) –
- Returns:
model
- Return type:
cobra.Model
- dexom_python.model_functions.check_model_primals(model, rw, eps=0.01, thr=0.001, savename='primal_check.csv')[source]
- dexom_python.model_functions.check_threshold_tolerance(model, epsilon, threshold)[source]
Checks if model.tolerance, epsilon and threshold parameters are compatible. If not, new epsilon and threshold values are returned.
- Parameters:
model (cobra.Model) –
epsilon (float) –
threshold (float) –
- Returns:
epsilon (float)
threshold (float)
- 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
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 pandas.Series or pandas.DataFrame) – a dictionary/pandas Series containing gene IDs as keys/index & weights as values
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, significant_genes='both', relative=True, save=True, outpath='geneweights')[source]
Transforms gene expression values/ gene scores into qualitative gene weights
- Parameters:
genes (pandas.DataFrame or pandas.Series) – 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 (tuple or float) – proportion of genes to be used for determining low and high gene expression
significant_genes (str) – one of “high”, “low” or “both”. chooses whether the conversion is applied only for the genes with highest expression, lowest epxression, or both
relative (bool) – if True, proportion parameter will be interpreted as a percentile if False, proportion parameter will be interpreted as an absolute value of gene expression
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
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.create_optimality_constraint(model, reaction_weights, prev_sol, obj_tol=0.001, name='optimality', full=False)[source]
Creates the optimality constraint based on the imat objective function This constraint conserves the optimal objective value of the previous solution For detailed explanation of parameters see documentation of imat function.
- Parameters:
model (cobra.Model) –
reaction_weights (dict) –
prev_sol (cobra.Solution or float) – either the previous iMAT solution or the objective value of that solution
obj_tol (float) – variance allowed in the objective_value of the solution
name (string) –
full (bool) –
- Returns:
- Return type:
optlang Constraint object (dependent on current solver)
- dexom_python.imat_functions.imat(model, reaction_weights=None, epsilon=0.01, threshold=0.001, 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
- dexom_python.imat_functions.parsimonious_imat(model, reaction_weights=None, prev_sol=None, obj_tol=0.0, epsilon=0.01, threshold=0.001, full=False)[source]
This function applies parsimonious iMAT. If no previous solution is supplied, an imat solution is computed. Then, the absoulte sum of reaction fluxes is minimzed, while maintaining the original objective value within a certain tolerance. For more complete description of parameters, see imat function.
- Parameters:
model (cobra.Model) –
reaction_weights (dict) –
prev_sol (cobra.Solution) – (optional) a previously computed imat solution
obj_tol (float) – the relative tolerance on the objective function. By default, no tolerance is allowed
epsilon (float) –
threshold (float) –
full (bool) –
- Returns:
solution – a solution which maintains the imat objective while minimizing the absolute sum of fluxes
- Return type:
cobra.Solution
result_functions module
- dexom_python.result_functions.calc_objval_from_flux(fluxsol, model, rw, eps=0.01, thr=0.001)[source]
Calculates the objective value of a solution based on the flux values
- Parameters:
fluxsol (pandas.Series) – a flux solution in which the index contains the model reaction IDs
model (cobra.model) –
rw (dict) –
eps (float) –
thr (float) –
- Returns:
objval
- Return type:
float
- 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 the solution files math the sollution_pattern parameter
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, reaction_weights=None, solution_index=0, eps=0.01, thr=0.001)[source]
Reads a solution from a .csv file. If the provided file is a file containing fluxes (as output by enumeration methods), the solution number solution_index will be read
- Parameters:
filename (str) – name of the file containing the solution
model (cobra.Model) – optional unless the filename points to a solution file without reaction IDs
reaction_weights (dict) – optional unless the filename points to a flux file, in which case it is needed for calculating objective values
solution_index (int) – defines which solution will be read from the binary solution file
eps (float) –
thr (float) –
- 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
- Parameters:
model (cobra.Model) –
solution (cobra.Solution) –
threshold (float) –
filename (str) –
- Returns:
solution (cobra.Solution)
solution_binary (numpy.array)
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, subsystem='')[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/model folder
- Parameters:
export (bool) – if True, exports the model as .json, .xml and .mat, 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.Fisher_groups(model, solpath, outpath='Fisher_groups')[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_subsystems function
Performs pathway over- and underrepresentation analysis
- Parameters:
model (cobra.Model) –
solpath (str) – file containing DEXOM solutions
outpath (str) – 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_subsystems(solpath, subframe, sublist, outpath='Fisher_subsystems')[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 Fischer_groups function
Performs pathway over- and underrepresentation analysis
- Parameters:
solpath (str) – file containing DEXOM solutions
subframe (pandas.DataFrame) – dataframe with ‘ID’ column containing reaction IDs and one ‘subsystem’ column containing pathways
sublist (list) – list of subsystems
outpath (str) – 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.perform_ora(gene_list, pathway_genes_dict, total_genes)[source]
Smaller function for performing ORA without reading files
- Parameters:
gene_list (list) – list of genes
pathway_genes_dict (dict) – dictionary with pathway names as keys and list of genes as values
total_genes (int) – total number of genes in the background set
- Returns:
pandas.Series
- Return type:
sorted p-values with BH-correction