psctb.analyse package

Subpackages

Submodules

psctb.analyse._ratechar module

class psctb.analyse._ratechar.RateChar(mod, min_concrange_factor=100, max_concrange_factor=100, scan_points=256, auto_load=False)[source]

Bases: object

Methods

do_ratechar

load_session

save_results

save_session

do_ratechar(fixed='all', scan_min=None, scan_max=None, min_concrange_factor=None, max_concrange_factor=None, scan_points=None, solver=0, auto_save=False)[source]
load_session(file_name=None)[source]
save_results(folder=None, separator=',', format='%f')[source]
save_session(file_name=None)[source]

psctb.analyse._thermokin module

class psctb.analyse._thermokin.ThermoKin(mod, path_to_reqn_file=None, overwrite=False, warnings=True, ltxe=None)[source]

Bases: object

Methods

save_results

save_results(file_name=None, separator=',', fmt='%.9f')[source]

psctb.analyse._thermokin_file_tools module

exception psctb.analyse._thermokin_file_tools.FormatException[source]

Bases: Exception

psctb.analyse._thermokin_file_tools.check_for_negatives(terms)[source]

Returns True for a list of sympy expressions contains any expressions that are negative.

Parameters
termslist of sympy expressions

A list where expressions may be either positive or negative.

Returns
bool

True if any negative terms in expression. Otherwise False

psctb.analyse._thermokin_file_tools.check_term_format(lines, term_type)[source]

Inspects a list of string for the correct ThermoKin syntax. Returns True in case of correct format. Throws exception otherwise.

Correct format is a str matching the pattern “X{w*}{w*} .*” . Where “X” is either “!G” or “!T” as specified by term_type.

Parameters
lineslist of str

Clean list of lines from a ‘.reqn’ file.

term_typestr

This string specifies the type of term.

Returns
bool
psctb.analyse._thermokin_file_tools.construct_dict(lines)[source]

Constructs a dictionary of dictionaries for each reaction.

Here keys of the outer dictionary is reaction name strings while the inner dictionary keys are the term names. The inner dictionary values are the term expressions

Parameters
lineslist of str
Returns
dict of str:{str:str}
psctb.analyse._thermokin_file_tools.create_gamma_keq_reqn_data(mod)[source]
psctb.analyse._thermokin_file_tools.create_reqn_data(mod)[source]
psctb.analyse._thermokin_file_tools.filter_irreversible(sympy_terms)[source]
psctb.analyse._thermokin_file_tools.get_all_terms(path_to_read)[source]
psctb.analyse._thermokin_file_tools.get_binding_vc_terms(sympy_formulas, ma_terms)[source]

Returns dictionary with a combined “rate capacity” and “binding” term as values.

Uses the symbolic rate equations dictionary and mass action term dictionaries to construct a new dictionary with “rate capacity- binding” terms. The symbolic rate equations are divided by their mass action terms. The results are the “rate capacity-binding” terms. This use case requires reaction names as they appear in pysces as keys for both dictionaries.

Parameters
sympy_formulasdict of str:sympy expression

Full rate equations for all reactions in model. Keys are reaction names and correspond to this in ma_terms.

ma_termsdict of str:sympy expression

Mass action terms for all reactions in model. Keys are reaction names and correspond to this in sympy_formulas.

Returns
dict of str:sympy expression

A dictionary with reaction names as keys and sympy expressions representing “rate capacity-binding” terms as values.

psctb.analyse._thermokin_file_tools.get_gamma_keq_terms(mod, sympy_terms)[source]
psctb.analyse._thermokin_file_tools.get_ma_terms(mod, sympy_terms)[source]

Returns dict with reaction names as keys and mass action terms as values from a dict with reaction names as keys and lists of sympy expressions as values.

Only reversible reactions are handled. Any list in the sympy_terms dict that does not have a length of 2 will be ignored.

Parameters
modPysMod

The model from which the sympy_terms dict was originally constructed.

sympy_terms: dict of str:list of sympy expressions

This dictionary should be created by get_sympy_terms.

Returns
dict of str:sympy expression

Each value will be a mass action term for each reaction key with a form depending on reversibility as described above.

psctb.analyse._thermokin_file_tools.get_reqn_path(mod)[source]

Gets the default path and filename of`.reqn` files belonging to a model

The .reqn files which contain rate equations split into different (arbitrary) components should be saved in the same directory as the model file itself by default. It should have the same filename (sans extension) as the model file.

Parameters
modPysMod

A pysces model which has corresponding .reqn file saved in the same directory with the same file name as the model file.

Returns
str

A sting with the path and filename of the .reqn file.

psctb.analyse._thermokin_file_tools.get_st_pt_keq(expression, substrates, products)[source]

Takes an expression representing “substrates/products * Keq_expression” and returns substrates, products and keq_expression separately.

Parameters
expressionsympy expression

The expression containing “substrates/products * Keq_expression”

substrateslist of sympy symbols

List with symbolic representations for each substrate involved in the reaction which expression represents.

productslist of sympy symbols

List with symbolic representations for each product involved in the reaction which expression represents. Returns

——-
tuple of sympy expressions and int

This tuple contains sympy expressions for the substrates, products and keq_expression in that order. The final value will be an int which indicates the strategy followed.

psctb.analyse._thermokin_file_tools.get_str_formulas(mod)[source]

Returns a dictionary with reaction_name:string_formula as key:value pairs.

Goes through mod.reactions and constructs a dictionary where reaction_name is the key and mod.reaction_name.formula is the value.

Parameters
modPysMod

The model which will be used to construct the dictionary

Returns
dict of str:str

A dictionary with reaction_name:string_formula as key:value pairs

psctb.analyse._thermokin_file_tools.get_subs_dict(expression, mod)[source]

Builds a substitution dictionary of an expression based of the values of these symbols in a model.

Parameters
expressionsympy expression
modPysMod
Returns
dict of sympy.Symbol:float
psctb.analyse._thermokin_file_tools.get_sympy_formulas(str_formulas)[source]

Converts dict with str values to sympy expression values.

Used to convert key:string_formula to key:sympy_formula. Intended use case is for automatic separation of rate equation terms into mass action and binding terms. This use case requires reaction names as they appear in pysces as keys.

Parameters
str_formulasdict of str:str

Dictionary with str values that represent reaction expressions. This dictionary needs to have already passed through all sanitising functions/methods (e.g. replace_pow).

Returns
dict with sympy_expression values and original keys

Dictionary where values are symbolic sympy expressions

psctb.analyse._thermokin_file_tools.get_sympy_terms(sympy_formulas)[source]

Converts a dict with sympy expressions as values to a new dict with list values containing either the original expression or a negative and a positive expressions.

This is used to separate reversible and irreversible reactions. Reversible reactions will have two terms, one negative and one positive. Here expressions are expanded and split into terms and tested for the above criteria: If met the dict value will be a list of two expressions, each representing a term of the rate equation. Otherwise the dict value will be a list with a single item - the original expression. This use case requires reaction names as they appear in pysces as keys.

Parameters
sympy_formulasdict of str:sympy expression values

Dictionary with values representing rate equations as sympy expressions. Keys are reaction names

Returns
dict of str:list sympy expression

Each list will have either have one item, the original dict value OR two items -the original dict value split into a negative and positive expression.

psctb.analyse._thermokin_file_tools.get_term_dict(raw_lines, term_type)[source]

Returns the term dictionary from a list of raw lines from a file.

The contents of a ‘.reqn’ file is read and passed to this function. Here the contents is parsed and ‘main terms’ are extracted and returned as a dict of str:{str:str}.

Parameters
raw_lineslist of str

List of lines from a ‘.reqn’ file.

Returns
dict of str:{str:str}
psctb.analyse._thermokin_file_tools.get_term_types_from_raw_data(raw_data_dict)[source]

Determines the types of terms defined for ThermoKin based on the file contents. This allows for generation of latex expressions based on these terms.

Parameters
raw_data_dictdict of str:{str:str}
Returns
set of str
psctb.analyse._thermokin_file_tools.get_terms(raw_lines, term_type)[source]

Takes a list of strings and returns a new list containing only lines starting with term_type and strips line endings.

Term can be either of the “main” (or !T) type or additional (or !G) type

Parameters
raw_lineslist of str

List of lines from a ‘.reqn’ file.

term_typestr

This string specifies the type of term.

Returns
list of str
psctb.analyse._thermokin_file_tools.read_reqn_file(path_to_file)[source]

Reads the contents of a file and returns it as a list of lines.

Parameters
path_to_filestr

Path to file that is to read in

Returns
list of str

The file contents as separate strings in a list

psctb.analyse._thermokin_file_tools.replace_pow(str_formulas)[source]

Creates new dict from an existing dict with “pow(x,y)” in values replaced with “x**y”.

Goes through the values of an dictionary and uses regex to convert the pysces internal syntax for powers with standard python syntax. This is needed before conversion to sympy expressions. This use case requires reaction names as they appear in pysces as keys.

Parameters
str_formulasdict of str:str

A dictionary where the values as contain pysces format strings representing rate equation expressions with powers in the syntax “pow(x,y)”

Returns
dict of str:str

A new dictionary with str rate equations where powers are represented by standard python syntax e.g. x**y

psctb.analyse._thermokin_file_tools.sort_terms(terms)[source]

Returns a list of two sympy expressions where the expression is positive and the second expression is negative.

Parameters
termslist of sympy expressions

A list with length of 2 where one element is positive and the other is negative (starts with a minus symbol)

Returns
tuple of sympy expressions

A tuple where the first element is positive and the second is negative.

psctb.analyse._thermokin_file_tools.st_pt_keq_from_expression(expression, substrates, products, failure_threshold=10)[source]

Take an expression representing “substrates/products * Keq_expression” and returns substrates, products and keq_expression separately.

In this strategy there is no inspection of the stoichiometry as provided by the model map. Here the expressions is divided/multiplied by each substrate/product until it no longer appears in the expression. If the substrates or products are not removed after a defined number of attempts a total failure occurs and the function returns None

This is a fallback for cases where defined stoichiometry does not correspond to the actual rate equation.

Here cases where the substrate/product do not appear in the rate equation at all throws an assertion error.

Parameters
expressionsympy expression

The expression containing “substrates/products * Keq_expression”

substrateslist of sympy symbols

List with symbolic representations for each substrate involved in the reaction which expression represents.

productslist of sympy symbols

List with symbolic representations for each product involved in the reaction which expression represents.

failure_thresholdint, optional (Default: 10)

A threshold value the defines the number of times the metabolite removal strategy should be tried before failure.

Returns
tuple of sympy_expressions or None

This tuple contains sympy expressions for the substrates, products and keq_expression in that order. None is returned if this strategy fails.

psctb.analyse._thermokin_file_tools.term_to_file(file_name, expression, parent_name=None, term_name=None)[source]
psctb.analyse._thermokin_file_tools.write_reqn_file(file_name, model_name, ma_terms, vc_binding_terms, gamma_keq_terms, messages)[source]

Module contents