isosolve module¶
Take symbolic measure matrix and reconstruct possible isotopomer/cumomer/emu groups (as elementary as possible, idealy each group composed of only one i/c/e) for each combination of measurement methods
-
class
isosolve.
Object
¶ Bases:
object
Object to which user can add fields
-
isosolve.
assign
(name, value, d)¶ assign a ‘value’ to ‘name’ in dictionary ‘d’, e.g. ‘d’ can be locals(). Return ‘value’.
-
isosolve.
dhms
(f, dig=2)¶ Convert float number ‘f’ representing seconds to a ‘D days Hh Mm Ss
-
isosolve.
e2li
(e)¶ transform expression ‘e’ in a nested list. Each nested level corresponds to Add, Mul and Pow arguments, Add being the highest level.
-
isosolve.
ech
(m, d={}, c={}, sc={}, nd={}, ld={}, fast=False)¶ reduce augmented matrix m to echelon form applying substitutions from d. Return echelon matrix and permutation list of col-index couples. No check is made for non zero terms in the last column in all zero rows.
-
isosolve.
echsol
(m, *unk, pe=[], d={}, c={}, sc={}, nsub={}, fast=False)¶ solves augmented linear system in echelon form resulted from ech(…). Unknown symbols are taken from *unk. pe is a possible permutation list of ij-tuples from ech(…). Return a symbolic column vector
-
isosolve.
hascumo
(s1, s2)¶ return a cumulated string (or None if not conformant) for binary cumomers in s1 and s2. E.g. 01x+11x => x1x
-
isosolve.
iainb
(a, b)¶ return a list of indexes of a in b or None if a is not strictly in b. An empty list is returned for empty a. Repeated values in a must be repeated at least the same number of times in b.
-
isosolve.
is_intstr
(s)¶ check if a string ‘s’ represents exactly an integer number
-
isosolve.
isstr
(s)¶ return True if ‘s’ is of type ‘str’
-
isosolve.
lfact
(e, esub={}, cache={}, scache={}, pr=False, nsub={}, fast=False)¶ factorize terms in expression ‘e’
-
isosolve.
lico2tb
(lico, mdFile=None, text_align='center')¶ transform list of columns in lico to a flat list of strings suitable for md table writing. Write md table if mdFile is set.
-
isosolve.
limi
(li, negative=False)¶ apply or not sign ‘-‘ to all terms of the list li
-
isosolve.
main
(li=None, mm=None, colsel=None, tim=None, data=None, w=None, s=None, rd=None, path=None, fast=False, vers=None, inchi=False)¶ Resolve symbolically and numerically iso-, cumo- and EMU-mers from isotope labeling measurements (NMR, MS, …)
Parameters: - li (list, optional) – list of argument to be processed, typically a
sys.argv[1:]
, cf.isosolve -h
or isosolve command line options section for parameter significance. Defaults to None. - mm (str or pandas.FataFrame, optional) – mapping matrix describes symbolically the mapping of each measurements method to isotopic space. Can be a file name in tsv format or a pandas data.frame. Either this parameter must be set or the only positional argument in li. Defaults to None.
- colsel (str or iterable, optional) – if str, coma separated column selection from mm. The syntax is described in
isosolve -h
. If iterable, a collection of items describing column selection. Each item can be an integer (positive or negative for exclusion), slice or string with column name. Column numbers are 1-based (not 0-based as usual for Python). Defaults to None which is equivalent to proceeding all the columns from mm. - tim (logical, optional) – if True, print CPU time after some key steps. Defaults to None.
- data (str or pandas.DataFrame, optional) – if DataFrame, numeric values and sd of measurements described in mm. If str, a file name in tsv format with such data in three columns: name, value, sd. Defaults to None.
- w (logical, optional) – if True, write formatted results in .md (plain text, MarkDown format) and .html files. The basis of file name is the same as in mm when mm is string, or
mm
if mm is a DataFrame. The namemm
can be overwritten with path parameter (cf. hereafter). Defaults to None which is equivalent to True when used in command line and to False when used programmatically. - s (int, optional) – seed for pseudo random generation. When used, randomly drawn values become reproducible. Only useful for debugging or issue reporting. Defaults to None.
- rd (logical, optional) – if True, use randomly generated values for checking obtained formulas. In the output HTML file, numerical values that are not coinciding are typeset in bold. Only useful for debugging and issue reporting. Defaults to None.
- path (str, optional) – directory (when ends with “/”) of file name (otherwise) for formatted output. Can be useful when mm is a DataFrame. Defaults to None which is equivalent to the current working directory.
- fast (logical, optional) – if True, skip calculation of elementary measurable combinations.
- vers (logical, optional) – if True, print the version number and return without any result.
- inchi – if True, writes TSV files with International Chemical Identifiers (InChI) for isotopomers, cumomers, EMUs and elementary measurable combinations.
Returns: dictionary with the following entries:
xbc: 1-column DataFrame, randomly drawn values for isotopomers;
xv: dict, key=measurement name and value=numeric value deduced from xbc;
am: sympy Matrix, augmented matrix of system equations. The last column is the right hand side;
rdn_mes: list, names of redundant measurements;
smm: DataFrame, mapping matrix after column selection;
mmd: dict, key=measurement name, value=numpy array with isotopomer indexes mapped onto this measurements;
uvals: dict, key=method name (i.e. column name in mm), value=list of unique measurement names involved in this method;
sy_meas: list, symbolic equations defining measurements;
sbc: dict, key=isotopomer name (i.e. row name in mm), value=isotopomer symbolic variable;
sols: list, symbolic solution for isotopomers. The order is the same as in mm;
vsubs: dict, key=full symbolic expression, value=simplified symbolic expression. Used for simplification procedures;
metrics: dict, the fields are:
idef: list, defined isotopomer indexes; idef_c: set, indexes of defined cumomers; idef_e: dict, key=EMU name, value=set of defined M+i mass isotopologues in this EMU; emusol: dict, key=EMU name, value=list of symbolic solutions for M+i;
cusol: dict, key=cumomer name, value=symbolic solution;
ls: dict, least square solution. The fields are:
iso: list, isotopomer values and sd; cov: isotopomer covariance matrix; cumo: list, cumomer values and sd; emu: list of dicts. Each dict has a key=EMU name and value=list of values (the first dict) or sd (the second one); mec: list, measurable elementary combinations values and sd; inchi: dict, InChI information. The fields are:
iso: DataFrame for isotopomers; cumo: DataFrame for cumomers; emu: DataFrame for EMUs; mcomb: DataFrame for measurable elementary combinations; Return type: dict
- li (list, optional) – list of argument to be processed, typically a
-
isosolve.
main_arg
()¶ Wrapper for main(li=sys.argv[1:]) call when used from executable script
-
isosolve.
new_header
(level=None, title='', mdFile=None)¶
-
isosolve.
partcomb
(x, p)¶ return iterator of iterator tuples ([p distinct elements of x], [the rest len(x)-p distinct elements of x])
-
isosolve.
pdiff
(expr, vs)¶ partial derivatives of expr by vars in vs
-
isosolve.
revenum
(x)¶ reversed enumerated iterable x
-
isosolve.
rsubs
(e, d, c={})¶ restricted substitution of keys from ‘d’ found in ‘e’ by d[key]. c is an optional cache dict
-
isosolve.
setsub
(l, it, v)¶ in a list l set values with indexes from it to v, i.e. l[it]=v where it is iterator. v is recycled if needed
-
isosolve.
sumi2sd
(covmat, i, tol=2.842170943040401e-14)¶ calculate sd for a new variable defined as sum of components in ‘i’
-
isosolve.
timeme
(s='', dig=2)¶ if a global variable TIMEME is True and another global variable _T0 is set, print current CPU time relative to _T0. This printing is preceded by a message from ‘s’
-
isosolve.
useq
(seq)¶ return iterator of unique elements in a sequence preserving initial order