dexom_python.enum_functions enumeration modules
Submodules
enumeration module
- class dexom_python.enum_functions.enumeration.EnumSolution(solutions, binary, objective_value)[source]
Bases:
objectclass for solutions of enumeration methods
- Parameters
solutions (list) – A list of pandas dataframes containing flux values with reaction ids as index
binary (list) – A list containing binary arrays of reaction activity (0 for inactive, 1 for active)
objective_value (float) – objective value returned by the solver at the end of the optimization
- dexom_python.enum_functions.enumeration.analyze_div_enum_results(result_path, solution_path, out_path)[source]
This function calculates the average pairwise hamming distance and average next neighbour distance for each iteration - it’s very slow
- Parameters
result_path (csv results file from diversity-enum) –
solution_path (csv solution file from diversity-enum) –
out_path (path for saving) –
- dexom_python.enum_functions.enumeration.create_enum_variables(model, reaction_weights, eps=0.01, thr=1e-05, full=False)[source]
- dexom_python.enum_functions.enumeration.get_recent_solution_and_iteration(dirpath, startsol_num)[source]
This functions fetches a solution from a given directory. The solutions are ordered by creation time, and one solution is picked using an exponential distribution (meaning that the most recent solution has the highest probability of being chosen)
- Parameters
dirpath (str) – a directory containing imat or enumeration solutions
startsol_num (int) – the number of starting solutions present in the directory
- Returns
solution (a Solution object)
iteration (int) – calculates the current iteration, based on how many solutions are already present in the folder
- dexom_python.enum_functions.enumeration.write_batch_script1(directory, modelfile, weightfile, cplexpath, reactionlist=None, imatsol=None, objtol=0.01, filenums=100, iters=100)[source]
Writes bash scripts for dexom-python parallelization approach 1 on a slurm cluster. Within each batch, reaction-enumeration and diversity-enumeration are performed. These scripts assume that you have setup a virtual environment called env.
- Parameters
directory (str) – directory in which the files will be generated. If it does not exist, it will be created
modelfile (str) – path to the model
weightfile – path to the reaction weights
cplexpath (str) – path to a cplex installation on the cluster
reactionlist (str) – list of reactions for reaction-enumeration
imatsol (str) – path to imat solution
objtol (float) – objective tolerance
filenums (int) – number of parallel batches
iters (int) – number of diversity-enumeration iterations per batch
- dexom_python.enum_functions.enumeration.write_batch_script2(directory, modelfile, weightfile, cplexpath, objtol=0.01, filenums=100)[source]
Writes bash scripts for dexom-python parallelization approach 2 on a slurm cluster. In this approach, indiviual diversity-enumeration iterations are laucnhed in each batch - this requires the existance of reaction-enumeration solutions beforehand. These scripts assume that you have setup a virtual environment called env.
- Parameters
directory (str) – directory in which the files will be generated
modelfile (str) – path to the model
weightfile – path to the reaction weights
cplexpath (str) – path to a cplex installation on the cluster
objtol (float) – objective tolerance
filenums (int) – number of parallel batches
rxn_enum_functions module
- class dexom_python.enum_functions.rxn_enum_functions.RxnEnumSolution(all_solutions, unique_solutions, all_binary, unique_binary, all_reactions=None, unique_reactions=None, objective_value=-1.0)[source]
Bases:
object
- dexom_python.enum_functions.rxn_enum_functions.rxn_enum(model, reaction_weights, prev_sol=None, rxn_list=[], eps=0.0001, thr=0.0001, obj_tol=0.001, out_path='enum_rxn', save=False)[source]
Reaction enumeration method
- Parameters
model (cobrapy Model) –
reaction_weights (dict) – keys = reactions and values = weights
prev_sol (imat Solution object) – an imat solution used as a starting point
eps (float) – activation threshold in imat
thr (float) – detection threshold of activated reactions
tlim (int) – time limit for imat
tol (float) – tolerance for imat
obj_tol (float) – variance allowed in the objective_values of the solutions
out_path (str) – path to which the solutions are saved if save==True
save (bool) – if True, every individual solution is saved in the iMAT solution format
- Returns
solution
- Return type
RxnEnumSolution object
icut_functions module
- dexom_python.enum_functions.icut_functions.create_icut_constraint(model, reaction_weights, threshold, prev_sol, name, full=False)[source]
Creates an icut constraint on the previously found solution. This solution is excluded from the solution space.
- dexom_python.enum_functions.icut_functions.icut(model, reaction_weights, prev_sol=None, eps=0.0001, thr=0.0001, obj_tol=0.001, maxiter=10, full=False)[source]
integer-cut method
- Parameters
model (cobrapy Model) –
reaction_weights (dict) – keys = reactions and values = weights
prev_sol (imat Solution object) – an imat solution used as a starting point
eps (float) – activation threshold in imat
thr (float) – detection threshold of activated reactions
obj_tol (float) – variance allowed in the objective_values of the solutions
maxiter (foat) – maximum number of solutions to check for
full (bool) – if True, carries out integer-cut on all reactions; if False, only on reactions with non-zero weights
- Returns
solution – In the case of integer-cut, all_solutions and unique_solutions are identical
- Return type
EnumSolution object
maxdist_functions module
- dexom_python.enum_functions.maxdist_functions.create_maxdist_constraint(model, reaction_weights, prev_sol, obj_tol, name='maxdist_optimality', full=False)[source]
Creates the optimality constraint for the maxdist algorithm. This constraint conserves the optimal objective value of the previous solution
- dexom_python.enum_functions.maxdist_functions.create_maxdist_objective(model, reaction_weights, prev_sol, prev_sol_bin, only_ones=False, full=False)[source]
Create the new objective for the maxdist algorithm. This objective is the minimization of similarity between the binary solution vectors If only_ones is set to False, the similarity will only be calculated with overlapping ones
- dexom_python.enum_functions.maxdist_functions.maxdist(model, reaction_weights, prev_sol=None, eps=0.0001, thr=0.0001, obj_tol=0.001, maxiter=10, icut=True, full=False, only_ones=False)[source]
- Parameters
model (cobrapy Model) –
reaction_weights (dict) – keys = reactions and values = weights
prev_sol (imat Solution object) – an imat solution used as a starting point
eps (float) – activation threshold in imat
thr (float) – detection threshold of activated reactions
obj_tol (float) – variance allowed in the objective_values of the solutions
maxiter (foat) – maximum number of solutions to check for
icut (bool) – if True, icut constraints are applied
full (bool) – if True, carries out integer-cut on all reactions; if False, only on reactions with non-zero weights
only_ones (bool) – if True, only the ones in the binary solution are used for distance calculation (as in dexom matlab)
- Returns
solution
- Return type
EnumSolution object
diversity_enum_functions module
- dexom_python.enum_functions.diversity_enum_functions.diversity_enum(model, reaction_weights, prev_sol=None, eps=0.0001, thr=0.0001, obj_tol=0.001, maxiter=10, dist_anneal=0.995, out_path='enum_dexom', icut=True, full=False, save=False)[source]
diversity-based enumeration
- Parameters
model (cobrapy Model) –
reaction_weights (dict) – keys = reactions and values = weights
prev_sol (Solution instance) – a previous imat solution
eps (float) – activation threshold for highly expressed reactions
thr (float) – detection threshold of activated reactions
obj_tol (float) – variance allowed in the objective_values of the solutions
maxiter (foat) – maximum number of solutions to search for
dist_anneal (float) – parameter which influences the probability of selecting reactions
out_path (str) – path to which the solutions are saved if save==True
icut (bool) – if True, icut constraints are applied
full (bool) – if True, the full-DEXOM implementation is used
save (bool) – if True, every individual solution is saved in the iMAT solution format
- Returns
solution
- Return type
an EnumSolution object