psctb.utils.misc package

Submodules

psctb.utils.misc._misc module

class psctb.utils.misc._misc.DotDict(*args, **kwargs)[source]

Bases: dict

A class that inherits from dict.

The DotDict class has the same functionality as dict but with the added feature that dictionary elements may be accessed via dot notation.

See also

dict
PseudoDotDict

Methods

clear()

copy()

fromkeys(iterable[, value])

Create a new dictionary with keys from iterable and values set to value.

get(key[, default])

Return the value for key if key is in the dictionary, else default.

items()

keys()

pop(key[, default])

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem(/)

Remove and return a (key, value) pair as a 2-tuple.

setdefault(key[, default])

Insert key with a value of default if key is not in the dictionary.

update([E, ]**F)

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()

update([E, ]**F) None.  Update D from dict/iterable E and F.[source]

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

class psctb.utils.misc._misc.PseudoDotDict(*args, **kwargs)[source]

Bases: object

A class that acts like a dictionary with dot accessible elements.

This class is not subsclassed from dict like DotDict, but rather wraps dictionary functionality.

This object has trouble being pickled :’(

See also

dict
DotDict

Methods

update

update(dic)[source]
psctb.utils.misc._misc.cc_dict(mod)[source]
psctb.utils.misc._misc.cc_list(mod)[source]

Retuns a list of control coefficients of a model.

The list contains both flux and species control coefficients and control coefficients follow the syntax of ‘cc_controlled_controller’.

Parameters
modPysMod

The Pysces model contains the reactions and species which is used to construct the control coefficient list.

Returns
list of str

The cc_list is sorted alphabetically.

See also

ec_list, rc_list, prc_list
psctb.utils.misc._misc.column_multiply(arr)[source]

For any 2d array returns a column vector with the product of the columns of each row.

Parameters
arrnumpy.ndarray
Returns
numpy.ndarray

A ndarray (column vector) with the products of columns of each row of arr as values

Examples

>>> arr = np.arrange(10).reshape(5,2)
>>> arr
array([[0, 1],
       [2, 3],
       [4, 5],
       [6, 7],
       [8, 9]])
>>> column_multiply(arr)
array([[  0.],
       [  6.],
       [ 20.],
       [ 42.],
       [ 72.]])
psctb.utils.misc._misc.do_safe_state(mod, parameter, value, type='ss')[source]
psctb.utils.misc._misc.ec_dict(mod)[source]
psctb.utils.misc._misc.ec_list(mod)[source]

Retuns a list of elasticity coefficients of a model.

The list contains both species and parameter elasticity coefficients and elasticity coefficients follow the syntax of ‘ec_reaction_sp-or-param’.

Parameters
modPysMod

The Pysces model contains the reactions, species and parameters which is used to construct the elasticity coefficient list.

Returns
list of str

The ec_list is sorted alphabetically.

See also

cc_list, rc_list, prc_list
psctb.utils.misc._misc.extract_model(obj)[source]
psctb.utils.misc._misc.find_max(array_like)[source]
psctb.utils.misc._misc.find_min(array_like)[source]
psctb.utils.misc._misc.flux_list(mod)[source]
psctb.utils.misc._misc.formatter_factory(min_val=None, max_val=None, default_fmt=None, outlier_fmt=None)[source]

Returns a custom html_table object cell content formatter function.

Parameters
min_valint or float, optional (Default0.001)

The minimum value for float display cutoff.

max_valint of float, optional (Default10000)

The maximum value for float display cutoff.

default_fmtstr, options (Default‘%.3f’)

The default format for any number within the range of min_val to max_val.

outlier_fmtstr, optional (Default‘%.3e’)

The format for any number not in the range of min_val to max_val

Returns
formatterfunction

A function which formats input for html_table using the values set up by this function.

Examples

>>> f = formatter_factory(min_val=1,
                          max_val=10,
                          default_fmt='%.2f',
                          outlier_fmt='%.2e')
>>> f(1)
'1.00'
>>> f(5.235)
'5.24'
>>> f(10)
'10.00'
>>> f(0.99842)
'9.98e-01'
>>> f('abc')
'abc'
psctb.utils.misc._misc.get_filename_from_caller()[source]
psctb.utils.misc._misc.get_value(expression, subs_dict)[source]
psctb.utils.misc._misc.get_value_eval(expression, subs_dict)[source]
psctb.utils.misc._misc.get_value_sympy(expression, subs_dict)[source]
psctb.utils.misc._misc.group_sort(old_list, num_of_groups)[source]
psctb.utils.misc._misc.html_table(matrix_or_array_like, float_fmt=None, raw=False, first_row_headers=False, caption=None, style=None, formatter=None)[source]

Constructs an html compatible table from 2D list, numpy array or sympy matrix.

Parameters
matrix_or_array_likelist of lists or array or matrix

A compatible object to be converted to an html table

float_fmtstr, optional (Default‘%.2f’)

The formatter string for numbers. This formatter will be applied to all numbers. This optional argument is only used when the argument formatter is None. Useful for simple tables where different types of formatting is not needed.

rawboolean, optional (DefaultFalse)

If True a raw html string will be returned, otherwise an IPython HTML object will be returned.

first_row_headersboolean, optional (DefaultFalse)

If True elements in the fist row in matrix_or_array_like will be considered as part of a header and will get the <th></th> tag, otherwise there will be no header.

captionstr, optional (DefaultNone)

An optional caption for the table.

stylestr, optional (DefaultNone)

An optional html table style

formatter: function, optional (DefaultNone)

An optional formatter function. If none float_fmt will be used to format numbers.

Returns
str

A string containing an html table.

OR
HTML

An IPython notebook HTML object.

psctb.utils.misc._misc.is_attr(attr, model)[source]
psctb.utils.misc._misc.is_cc(attr, model)[source]
psctb.utils.misc._misc.is_ec(attr, model)[source]
psctb.utils.misc._misc.is_iterable(obj)[source]

Returns True if an object is iterable and False if it is not.

This function makes the assumtion that any iterable object can be cast as an iterator using the build-in function iter. This might not be the case, but works within the context of PySCeSToolbox.

Parameters
objobject

Any object that might or might not be iterable.

Returns
bool

A boolean indicating if ob is iterable.

psctb.utils.misc._misc.is_linear(scan_range)[source]

For any 1-demensional data structure containing numbers return True if the numbers follows a linear sequence.

Within the context of PySCeSToolbox this function will be called on either a linear range or a log range. Thus, while not indicative of log ranges, this is what a False return value indicates in this software.

Parameters
scan_rangeiterable

Any iterable object containing a range of numbers.

Returns
bool

A boolean indicating if scan_range is a linear sequence of numbers.

psctb.utils.misc._misc.is_mca_coef(attr, model)[source]
psctb.utils.misc._misc.is_number(suspected_number)[source]

Test if an object is a number

Parameters
suspected_number: object

This can be any object which might be a number.

Returns
boolean

True if object is a number, else false

psctb.utils.misc._misc.is_parameter(attr, model)[source]
psctb.utils.misc._misc.is_prc(attr, model)[source]
psctb.utils.misc._misc.is_rc(attr, model)[source]
psctb.utils.misc._misc.is_reaction(attr, model)[source]
psctb.utils.misc._misc.is_species(attr, model)[source]
psctb.utils.misc._misc.is_variable(attr, model)[source]
psctb.utils.misc._misc.memoize(function)[source]
psctb.utils.misc._misc.mod_ec_list(mod)[source]

Returns a list of modifier elasticity coefficients of a model.

Returns
list of str

The mod_ec_list is sorted alphabetically.

psctb.utils.misc._misc.prc_dict(mod)[source]
psctb.utils.misc._misc.prc_list(mod)[source]

Retuns a list of partial response coefficients of a model.

The list contains both species and flux partial response coefficients and partial response coefficients follow the syntax of ‘prc_responder_parameter_route’.

Parameters
modPysMod

The Pysces model contains the reactions, species and parameters which is used to construct the partial response coefficient list.

Returns
list of str

The prc_list is sorted alphabetically.

See also

cc_list, ec_list, rc_list
psctb.utils.misc._misc.print_f(message, status)[source]

Prints a message if status is True Parameters ———- message : object

Any object with a __str__ method.

status : bool

psctb.utils.misc._misc.prod_ec_list(mod)[source]

Returns a list of product elasticity coefficients of a model.

Returns
list of str

The prod_ec_list is sorted alphabetically.

psctb.utils.misc._misc.rc_dict(mod)[source]
psctb.utils.misc._misc.rc_list(mod)[source]

Retuns a list of response coefficients of a model.

The list contains both species and flux response coefficients and response coefficients follow the syntax of ‘rc_responder_parameter’.

Parameters
modPysMod

The Pysces model contains the reactions, species and parameters which is used to construct the response coefficient list.

Returns
list of str

The rc_list is sorted alphabetically.

See also

cc_list, ec_list, prc_list
psctb.utils.misc._misc.scanner_range_setup(scan_range)[source]

From a range of numbers, returns its start point, end point, number of points and if it is a log range.

The assumption is made that only log or linear ranges are valid inputs, thus lists of random numbers would likely be classified as logarithmic.

Parameters
scan_rangeiterable

Any iterable object containing a range of numbers. Most probably numpy.ndarray.

Returns
startnumber

A number indicating the start point of the scan range.

end: number

A number indicating the end point of the scan range.

scan_points: number

A number indicating the number of scan point in the scan range

is_log_range: bool

A boolean indicating whether the scan range has a logarithmic scale or not.

psctb.utils.misc._misc.silence_print(func)[source]

A function wrapper that silences the stdout output of a function.

This function is very useful for silencing pysces functions that print a lot of unneeded output.

Parameters
funcfunction

A function that talks too much.

Returns
function

A very quiet function

psctb.utils.misc._misc.split_coefficient(coefficient_name, mod)[source]
psctb.utils.misc._misc.ss_species_list(mod)[source]
psctb.utils.misc._misc.stringify(symbol_or_list)[source]

Returns a list of strings from a list of sympy.Symbol objects or a string from a sympy.Symbol.

Parameters
symbol_or_listsympy.Symbol or list of sympy.Symbol.
Returns
str or list of str

A str or list of str representation of the sympy.Symbol or list of sympy.Symbol.

Examples

>>> import sympy
>>> symbol_list = sympy.sympify(['a','c','d'])
>>> a = stringify(symbol_list[0])
>>> a
'a'
>>> type(a)
<type 'str>'
>>> str_list = stringify(symbol_list)
>>> str_list
['a', 'b', 'c']
>>> type(str_list[0])
<type 'str>'
psctb.utils.misc._misc.unix_to_windows_path(path_to_convert, drive_letter='C')[source]

For a string representing a POSIX compatible path (usually starting with either ‘~’ or ‘/’), returns a string representing an equivalent Windows compatible path together with a drive letter.

Parameters
path_to_convertstring

A string representing a POSIX path

drive_letterstring (Default‘C’)

A single character string representing the desired drive letter

Returns
string

A string representing a Windows compatible path.

Module contents