dexom_python package top-level modules
Submodules
model_functions module
- dexom_python.model_functions.check_model_options(model, timelimit=600, 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
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, method='keep', significant_genes='both', 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
method (str) – one of “max”, “mean” or “keep”. chooses how to deal with genes containing multiple conflicting expression values
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
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.imat(model, reaction_weights=None, epsilon=0.0003, threshold=0.0002, 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.calc_objval_from_flux(fluxsol, model, rw, eps=0.0003, thr=0.0002)[source]
Calculates the objective value of a solution based on the flux values :param fluxsol: a flux solution in which the index contains the model reaction IDs :type fluxsol: pandas.Series :param model: :type model: cobra.model :param rw: :type rw: dict :param eps: :type eps: float :param thr: :type 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.0003, thr=0.0002)[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 :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, 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