Programmer’s documentation for influx_si

In this chapter, Application Programming Interface (API) docs are collected. It can be helpful for programmers desiring to extend some features of influx_si or to fix some bugs. This chapter can be safely skipped by users aiming at simple usage of influx_si for biological research.

C13_ftbl

  • Parse .ftbl
  • Analyse ftbl
Restrictions:
  • metabolite name cannot have

    “:”

    it’s a separator in measure id

    “+”

    in measurements it can be metab1+metab2+…

C13_ftbl.aglom(na, ta, loop)[source]

new matrix A (na), transpose A (ta) are used to aglomerate neigbour mutually influencing nodes in a supernode. Aglomerated noeds are put in the loop dictionnary. Return False if no nodes were aglomerated.

C13_ftbl.aglom_loop1(A)[source]

Agglomerate nodes of A if they mutually influence each other i.e. they are in a loop of length 1. Return a new dictionary of influence where entries are those of A aglomerated and glued “by” tab symbol

C13_ftbl.allprods(srcs, prods, isos, metab, isostr)[source]

Return a set of tuples (cmetab, cisostr, vmetab, visostr) where cmetab and cisostr describe a contex metabolite which combined with metab+isostr produced vmetab+visostr. if metab is alone on its reaction part cmetab and cisostr are set to an empty string (“”). The set covers all combination of metab+isostr and its co-substrates which produce isotopes having at least one labeled carbon from metab+isostr. Co-substrate isotops are in a dictionary isos[cmetab]=list(cisotopes).

C13_ftbl.bcumo_decomp(bcumo)[source]

bcumo is a string of the form #[01x]+. It has to be decomposed in the linear combination of cumomers #[1x]+. The coefficients of this linear combination are 1 or -1. So it can be represented as sum(cumos_positive)-sum(cumos_negative). The result of this function is a dictionary {“+”: list of icumos, “-”: list of icumos}. icumo is an integer whose binary form indicates 1’s positions in a cumomer.

C13_ftbl.conv_mid(x, y) → z[source]

convolute two mid vectors (numpy arrays) and return the result as numpy array.

C13_ftbl.cumo_infl(netan, cumo)->list(tuple(in_cumo, fl, imetab, iin_metab))[source]

return the list of tuples (in_cumo, fl, imetab, iin_metab): input cumomer, flux (fwd.fl or rev.fl), index of metab and index of in_metab generating cumo. cumo is in format “metab:icumo”. Condenstation reaction will give the same flux and icumo but various iin_metab. Convergent point will give multiple fluxes.

C13_ftbl.cumo_iw(w, nlen)[source]

iterator for a given cumomer weight w in the carbon length nlen

C13_ftbl.cumo_path(starts, A, visited={})[source]

Enumerate cumomers along reaction pathways. Algo: start from an input, follow chemical pathways till no more neighbours or till only visited metabolite rest in network. Return a list of cumomer pathways. Each pathways is an ordered list.

C13_ftbl.dom_cmp(A, i, j)[source]

Compares influances of i-th and j-th lements of A. Returns 0 if i and j are mutually influenced, 1 if i in A[j] (i influences j) , -1 otherwise

C13_ftbl.enum_path(starts, netw, outs, visited={})[source]

Enumerate metabilites along to reaction pathways. Algo: start from an input, follow chemical pathways till an output or already visited metabolite. Returns a list of metabolite pathways. Each pathways is an ordered list.

C13_ftbl.formula2dict(f, pterm=re.compile('([+-])'), pflux=re.compile('(?P<coef>\\d+\\.?\\d*|^)?\\s*\\*?\\s*(?P<var>[a-zA-Z_[\\]()][\\w\\. -\\[\\]]*)\\W*'))[source]

parse a linear combination sum([+|-][a_i][*]f_i) where a_i is a positive number and f_i is a string starting by non-digit and not white character (# is allowed). Output is a dict f_i:[+-]a_i

C13_ftbl.frag_prod(metab, frag, s, cmetab, cfrag, cs, prods)[source]

Get fragments from labeled substrates

C13_ftbl.ftbl_netan(ftbl, netan, emu_framework=False, fullsys=False, case_i=False)[source]

analyse ftbl dictionary to find

  • network inputs (input)
  • network outputs (output)
  • substrates (subs)
  • products (prods)
  • metabolites (metabs)
  • reactions (reacs)
  • not reversible reactions (subset of reacs) (notrev) all above items are in named sets
  • stocheometric matrix (sto_r_m)
  • stocheometric matrix (sto_m_r)
  • fwd-rev flux matrix (flux_m_r)
  • cumomer balances (cumo_m_r_m)
  • carbon length (Clen)
  • reaction formula (formula)
  • metabolite network (metab_netw)
  • carbon transitions (carbotrans)
  • free fluxes (flux_free)
  • constrained fluxes (flux_constr)
  • measured fluxes (flux_measured)
  • variable growth fluxes (flux_vgrowth)
  • input isotopomers (iso_input)
  • input isotopomers functions (funlab for case_i=True)
  • input cumomers (cumo_input)
  • input reduced cumomers (rcumo_input)
  • flux inequalities (flux_ineqal)
  • flux equalities (flux_eqal)
  • label measurements, H1 (label_meas)
  • peak measurements, C13 (peak_meas)
  • mass measurements (mass_meas)
  • cumomer ordered lists (vcumo)
  • unknown fluxes ordered lists (vflux)
  • linear problem on fluxes (Afl, bfl)
  • free fluxes ordered lists (vflux_free)
  • fw-rv fluxes ordered lists (vflux_fwrv)
  • row names ordered lists for Afl (vrowAfl)
  • in-out fluxes (flux_in, flux_out)
  • measured concentrations (metab_measured)
C13_ftbl.ftbl_parse(f) → dict[source]

read and parse .ftbl file. The only input parameter f is a stream pointer with read permission or a file name. This function parses the input and returns a dictionnary with items corresponding to sections in .ftbl. One section is added. “TRANS” correponds to carbon transitions.

C13_ftbl.infl(metab, netan)->oset(fluxes)[source]

List incoming fluxes for this metabolite (fwd.reac, rev.reac, …)

C13_ftbl.iso2cumo(netan, strin, in_cumo, icumo, in_metab)[source]

calculate cumomer fraction from isotopomer ones

C13_ftbl.iso2emu(netan, inmetab, mask, mpi, e)[source]

calculate emu fraction from isotopomer dict iso_input. The fraction corresponds to a fragment defined by a mask and the mass component mpi. Return a real number in [0; 1] interval.

C13_ftbl.label_meas2matrix_vec_dev(netan)[source]

use netan[“label_meas”] list to construct a corresponding list of measure matrix matx_lab such that scale_diag*metab_pool_diag*matx_lab*(cumos_vector,1) corresponds to label_measurements_vector. matx_lab is defined as list of dict{“scale”:scale_name, “coefs”:dict{icumo:coef}, “metab”: metabolite, “poolid”: metabolite pool id if pooled} where coef is a contribution of cumo in linear combination for given measure. scale_name is of the form “metabs;group”. Group number is to group measurements of the same measurement set. poolid is the index of pool list in pooled where each list regroups 0-based indexes rows in returned matrix for what has to be pooled together. vec is a list of measurements (values in .ftbl) dev is a list of deviations. Elements in matx_lab, vec and dev are ordered in the same way. The returned result is a dict (mat,vec,dev)

C13_ftbl.labprods(prods, metab, isostr, strs)[source]

Return a set of tuples (vmetab,visostr) which receive at least one labeled carbon from (metab, isostr)

C13_ftbl.lowtri(A)[source]

Try low triangular ordering of matrix A entries

C13_ftbl.mass_meas2matrix_vec_dev(netan)[source]

use netan[“mass_meas”] list to construct a corresponding list of measure matrix matx_mass such that scale_diag*matx_mass*cumos_vector corresponds to mass_measures_vector. matx_mass is defined as matx_lab in label_meas2matrix_vec_dev() Elements in matx_mass, vec and dev are ordered in the same way. scale name is defined as “metab;fragment_mask” The returned result is a dict (mat,vec,dev)

C13_ftbl.mat2graph(A, fp)[source]

write digraph file on file pointer fp representing links in matrix A given as bi-level dictionnary. A key of first level (row index) is influenced by keys of second level (column indicies).

C13_ftbl.mat2pbm(A, v, fp)[source]

Write an image map of non-zero entries of matrix A to file pointer fp. Matrix A is a dictionnary, v is a list ordering keys of A.

C13_ftbl.mecoparse(terms, pmeco=re.compile('\\s*((?P<coef>\\d+\\.?\\d*|^)\\s*\\*\\s*)?(?P<metab>[^*+ ]*)\\s*$'))[source]

Parse a string term from a list (or a sing string) of chemical equation entries. The general form of each term is ‘coef*metab’. coef (if present) must be separated from metab by ‘*’ and be convertible to float. metab can start with a number (e.g. ‘6PG’) so the presence of ‘*’ is mandatory to separate coef from metab.If coef is absent, it is considered to be 1. Return a list of (or a single for str) tuples (metab (str), coef (real)).

C13_ftbl.mkfunlabli(d)[source]

transform ‘d’ dict to a string representing a body of an R function calculating labeling dependent on time ‘t’

C13_ftbl.ms_frag_gath(netan)[source]

gather metabolite fragments necessary to obtain a given set of data observed in MS measurements. The fragment mask is encoded in the same way as cumomers, Met:7 <=> Met#(0)111

C13_ftbl.ntimes(n)[source]

Return charcater string ‘once’ for n=1, ‘twice’ for n=2 and ‘n times’ for other n

class C13_ftbl.oset(**kwds)[source]
copy() → a shallow copy of D[source]
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]

C13_ftbl.peak_meas2matrix_vec_dev(netan, dmask={'D+': 3, 'D-': 6, 'DD': 7, 'S': 2, 'T': 7})[source]

use netan[“peak_meas”] list to construct a corresponding list of measure matrix matx_peak such that scale_diag*matx_peak*cumos_vector corresponds to peak_measures_vector. dmask is a dictionary with 3 carbon labeling pattern mask for various peak types. The middle bit corresponds to the targeted carbon, lower bit corresponds to the next neighbour (D+) and higher bit corresponds to previous carbon (D-). matx_peak is defined as matx_lab in label_meas2matrix_vec_dev() Elements in matx_peak, vec and dev are ordered in the same way. scale name is defined as “metab;c_no;irow” The returned result is a dict (mat,vec,dev)

C13_ftbl.proc_kinopt(ftbl, netan)[source]

Proceed label kinetics options from OPTIONS section: file_labcin, dt, tmax, nsubdiv_dt, funlab

C13_ftbl.proc_label_input(ftbl, netan, case_i=False)[source]

Proceed LABEL_INPUT section in ftbl and add result to the list netan[“iso_input”] and netan[“funlab”] (case_i) List item is a dict {}metab;{isotop_int_index:fraction}}

C13_ftbl.proc_label_meas(ftbl, netan)[source]

Proceed LABEL_MEASUREMENT section of ftbl file, add the result to a list of dicts

C13_ftbl.proc_mass_meas(ftbl, netan)[source]

Proceed PEAK_MEASUREMENT section of ftbl file, add the result to a list of dicts

C13_ftbl.proc_peak_meas(ftbl, netan)[source]

Proceed PEAK_MEASUREMENT section of ftbl file, add the result to a list of dicts

C13_ftbl.prod(metab, iso, s, cmetab, ciso, cs, prods)->oset()[source]

get isotops from labeled substrates

C13_ftbl.rcumo_sys(netan, emu=False)[source]

Calculate reduced cumomers or EMU systems A*x=b we start with observed cumomers (emus) of max weight and we include only needed involved cumomers (emus) A list of cumomer (emu) lists (by weight) is stored in netan[“vrcumo”] (netan[“vemu”])

C13_ftbl.src_ind(substrate, product, iprod)[source]

For a given substrate and product carbon strings (e.g. “abc”, “ab”) calculate substrate index corresponding to product index. Return None if no source found. Return 0 if iprod==0 and intersection of product and substrate strings is not empty

C13_ftbl.t_iso2cumo(n)[source]

t_iso2cumo(n) return transition matrix from isotopomers fractions to cumomer vector n - carbon number return numpy array of size (2**n,2**n)

C13_ftbl.t_iso2m(n)[source]

t_iso2m(n) return transition matrix from isotopomers fractions to MID vector n - carbon number return numpy array of size (n+1,2**n)

C13_ftbl.t_iso2pos(n)[source]

t_iso2pos(n) return transition matrix from isotopomers fractions to positional labelling vector (cumomers of weight 1) n - carbon number return numpy array of size (n,2**n)

C13_ftbl.topo_order(A, tA)[source]

Try to sort keys of A in topological order. tA is just a transpose of A

C13_ftbl.transpose(A)[source]

Transpose a matrix defined as a dict.

C13_ftbl.werr()

Write string to stream. Returns the number of characters written (which is always equal to the length of the string).

C13_ftbl.wout()

Write string to stream. Returns the number of characters written (which is always equal to the length of the string).

txt2ftbl

transform a series of TXT and TSV files into FTBL file.

Copyright 2021, INRAE, INSA, CNRS Author: Serguei Sokol (sokol at insa-toulouse dot fr) License: Gnu Public License (GPL) v2 http://www.gnu.org/licenses/gpl.html

txt2ftbl.compile(mtf, cmd, case_i=False, clen=None)[source]

Compile FTBL content from mtf names: netw, miso etc. Return a dict of ftbl lines

txt2ftbl.dsec2out(dsec, fout)[source]

write lines from dsec to fout

txt2ftbl.dtstamp()[source]

formatted date-time stamp

txt2ftbl.itvl2li(v)[source]

convert interval like ‘2-5’ to [‘2’, ‘3’, ‘4’, ‘5’]

txt2ftbl.parse_cnstr(f)[source]

Parse constraint TSV file. Return a tuple of 2 dicts (eq, ineq) with lines to add to ftbl

txt2ftbl.parse_linp(f, clen={})[source]

Parse label input TSV file. Return a list of lines to add to ftbl

txt2ftbl.parse_mflux(f, dfl={})[source]

Parse flux measurements TSV file. Return a list of lines to add to ftbl

txt2ftbl.parse_miso(fmiso, clen, case_i=False)[source]

Parse isotopic measurements TSV file. Return dict with keys: ms, lab, peak

txt2ftbl.parse_mmet(f, smet={})[source]

Parse metabolite concentration measurements TSV file. Return a list of lines to add to ftbl

txt2ftbl.parse_opt(f)[source]

Parse options TSV file. Return a list of lines to add to ftbl

txt2ftbl.parse_tvar(f, dfl={}, itnl_met={})[source]

Parse variable type TSV file. Return a tuple of a dict and a list with lines to add to ftbl

txt2ftbl.try_ext(f, li)[source]

See if file ‘f’ exists, if not try with extensions from ‘li’. The first found is returned as Path() otherwise an exception is raised.

txt2ftbl.tsv2df(f, sep='\t', comment='#', skip_blank_lines=True, append_iline='iline')[source]

Read file ‘f’ as TSV and return a DataFrame. Separator is ‘sep’, comment char is ‘comment’, blank lines are skept, header is in the first row, file line numbers are stored in a column ‘line_nb’ if there is no a column with this name

txt2ftbl.txt_parse(ftxt, re_metab=re.compile('(?:(?P<coef>[\\d\\.]*)\\s+)?(?:(?P<metab>[^() \\t\\r]+)\\s*)(?:\\(\\s*(?P<carb>[^()]*)\\s*\\))?\\s*'), re_labpat=re.compile('^[./*\\d\\s]*(?P<labpat>[a-zA-Z]*)\\s*$'))[source]

Parse txt file from fname which is in format: ### Glycolysis and OPP pathway GLYC (abcdef) -> G6P (abcdef) G6P (abcdef) <-> F6P (abcdef) i.e.

comment: # blabla non reversible reaction: [reac: ][N1] metab1 [(carb1)] [… + [N_i] metab_i [(carb_i)]] -> … where

reac is an optional reaction name; N_i is optional stoechiometric coefficient metab_i is i-th metabolite name (carb_i) is optional 1-letter carbon names for carbon transition mapping

reversible reaction is represented by “<->” sign non reversible reaction is represented by “->” sign. reaction with imposed sens of reaction (from left to right) is representd with double “>>”, i.e. “->>” for non reversible reaction or “<->>” for reversible reaction. This reaction with imposed sens will have an inequality “reac_name >= 0” in FTBL/INEQUAITIES/NET section.

Retrun a list with following items: - a list of carbon exchange reactions - a list of non carbon echanging reactions - a list of equalities net and xch - a list of flux tuples (reac, rev, imposed_sens) - a list of two lists: left and right metabolites [(metab, clen),] - a carbon length dictionary {met: N}

the first item is a list of: plain string == just a comments list == reaction items: input, output: lists of tuples (metab, carb, coeff)

ftbl2mtf

Parse ftbl file from first parameter or from stdin (if input file is ‘-‘) and write a series of mtf (multiple TSV files). The file stem (‘network’ in ‘network.ftbl’) is used as file name basis for produced files, e.g. ‘network.miso’. Parameter –out can be used to change it. If out path includes non existing directories, they are automatically created. Caution! If an existing output file starts with a comment “# Created by ‘ftbl2mft …” or is empty, it is silently overwritten. Otherwise, the writing is aborted with a warning. Other files may continue to be created. To force the overwriting, use ‘–force’.

Output files will have following extensions/meanings:
.netw: stoichiometric equations and label transitions in the biochemical network; .linp: label input; .miso: isotopic measurements (MS, label, peak); .mflux: flux measurements; .mmet: biochemical specie concentration measurements; .tvar: flux/specie types partition (free, dependent, constrained) and starting values; .cnstr: constraints (equalities, inequalities for both fluxes and concentrations); .opt: options.

Copyright 2022 INRAE, INSA, CNRS Author: Serguei Sokol (sokol [at] insa-toulouse [dot] fr)

ftbl2mtf.dtstamp()[source]

formatted date-time stamp

ftbl2code

Module for translation of .ftbl file to R code

ftbl2code.netan2Abcumo_spr(varname, Al, bl, vcumol, minput, f, fwrv2i, incu2i_b1)[source]

Transform cumomer linear sytems collection (from ftbl file) to a R code calculating sparse matrix A and vector b in A*x+b=0 for a given weight of fragment iw (index in resulting list) Flux vector fl of all fwd. and rev. fluxes are known at R runtime.

Resulting code is a list sprAb indexed by cumomer weight (cf. generated R comments for details on sprAb) cumomer vector incu=c(1, xi, xl), xi - input cumomers, xl - lighter cumomers.

incu2i_b1 gives i in incu from cumomer name. i=1 corresponds to the constant 1.

ftbl2code.netan2R_cumo(netan, org, f) → dict[source]

generate data structures for full cumomer matrices

ftbl2code.netan2R_fl(netan, org, f)[source]

generate R code for flux and pool part for more details cf. netan2Rinit()

ftbl2code.netan2R_ineq(netan, org, f)[source]

generate inequality code

ftbl2code.netan2R_meas(netan, org, f)[source]

generate code for measure treatment

ftbl2code.netan2Rinit(netan, org, f, fullsys, emu=False, ropts=[])[source]

Write R code for initialization of all variables before cumomer system resolution by chi2 minimization. :param netan: a collection of parsed ftbl information :param f: R code output pointer :param fullsys (logical): write a code for the full or only reduced cumomer system :param emu (logical): write equations in EMU framework or cumomer (default) :param ropts: list of items “param=value” to be written as is in R file.

Returns:a dictionnary with some python variables: * “measures”: measures, * “o_mcumos”: o_mcumos, * “cumo2i”: cumo2i, * …

ftbl2netan

Parse ftbl file from stdin or from first parameter and write netan in kvh format on stdout usage: ftbl2netan.py network[.ftbl] [-h] [-i] [–emu] [–clownr] [–fullsys] [> network.netan]

ftbl2optR

Transform an ftbl to R code which will solve an optimization of flux analysis problem \(\arg \min_{\Theta} S\), where \(S=||\mathrm{Predicted}-\mathrm{Observed}||^{2}_{\Sigma}\) and \(\Theta\) is a vector of parameters to fit: free fluxes (net+xch), scaling parameters and metabolite concentrations pools. Two variants of R code can be generated: “s” and “i” for stationary and isotopically nonstationary labeling. Predicted vector is obtained from cumomer or emu vector x (calculated from free fluxes and divided in chunks according to the cumo weight) by multiplying it by the measurement matrices, weighted by metabolite pools (in case of pooling) and scale factor (for stationary case only), boths coming from ftbl file. Observed values vector xo is extracted from ftbl file for “s” case and from special text file for “i” case. It is composed of flux, label measurements and metabolite pools. \(\Sigma^2\), covariance diagonal matrices sigma[flux|mass|label|peak|metab.pool] is orginated from the ftbl file.

usage: ./ftbl2optR.py [opts] organism where organism is the ftbl informative part of file name (before .ftbl), e.g. organism.ftbl after execution a file organism.R will be created. If it already exists, it will be silently overwritten. The system Afl*flnx=bfl is created from the ftbl file.

Important python variables:
  • case_i - if True, the case is “i” otherwise it is the “s” case
Collections:
  • netan - (dict) ftbl structured content
  • tfallnx - (3-tuple[reac,[“d”|”f”|”c”], [“net”|”xch”]] list)- total flux collection
  • measures - (dict) exp data
  • rAb - (list) reduced linear systems A*x_cumo=b (a system by weight)
  • scale - unique scale names
  • nrow - counts scale names
  • o_sc - ordered scale names
  • o_meas - ordered measurement types
File names (str):
  • n_ftbl (descriptor f_ftbl)
  • n_R (R code) (f)
  • n_fort (fortran code) (ff)
Counts:
  • nb_fln, nb_flx, nb_fl (dependent fluxes: net, xch, total), nb_ffn, nb_ffx (free fluxes)
Index translators:
  • fwrv2i - flux names to index in R:fwrv
  • cumo2i - cumomer names to index in R:x
  • ir2isc - mapping measurement rows indexes on scale index isc[meas]=ir2isc[meas][ir]
Vector names:
  • cumos (list) - names of R:x
  • o_mcumos - cumomers involved in measurements

Important R variables:

Scalars:
  • nb_w, nb_cumos, nb_fln, nb_flx, nb_fl (dependent or unknown fluxes),
  • nb_ffn, nb_ffx, nb_ff (free fluxes),
  • nb_fcn, nb_fcx, nb_fc (constrained fluxes),
  • nb_ineq, nb_param, nb_fmn
Name vectors:
  • nm_cumo, nm_fwrv, nm_fallnx, nm_fln, nm_flx, nm_fl, nm_par,
  • nm_ffn, nm_ffx,
  • nm_fcn, nm_fcx,
  • nm_mcumo, nm_fmn
Numeric vectors:
  • fwrv - all fluxes (fwd+rev)
  • x - all cumomers (weight1+weight2+…)
  • param - free flux net, free flux xch, scale label, scale mass, scale peak, metabolite concentrations
  • fcn, fcx, fc - constrained fluxes
  • bp - helps to construct the rhs of flux system
  • xi -cumomer input vector
  • fallnx - complete flux vector (constr+net+xch)
  • bc - helps to construct fallnx
  • li - inequality vector (mi%*%fallnx>=li)
  • ir2isc - measure row to scale vector replicator
  • ci - inequalities for param use (ui%*%param-ci>=0)
  • measvec - measurement vector
  • fmn - measured net fluxes
Matrices:
  • Afl, qrAfl, invAfl,
  • p2bfl - helps to construct the rhs of flux system
  • mf, md - help to construct fallnx
  • mi - inequality matrix (ftbl content)
  • ui - inequality matrix (ready for param use)
  • measmat - for measmat*x+memaone=vec of simulated not-yet-scaled measurements
Functions:
  • lab_sim - translate param to flux and cumomer vector (initial approximation)
  • cumo_cost - cost function (chi2)
  • cumo_gradj - implicit derivative gradient

ftbl2xgmml

read a .ftbl file from a parameter and translate to .xgmml file. The generated xgmml file can be then imported into Cytoscape (www.cytoscape.org). Reactions involving two substrates or two products are represented by an additional almost invisible node while one-to-one reactions are just edges. Node and edge attributes are written in respective xml attributes. Compatibility: cytoscape v2.8.3 and v3.0

usage: ftbl2xgmml.py [-h|–help] mynetwork.ftbl [> mynetwork.xgmml]

OPTIONS -h, –help print this message and exit

param:mynetwork the base of an ftbl file (mynetwork.ftbl)
returns:mynetwork.xgmml – file of the network definition suitable for cytoscape

Copyright 2014, INRA, France Author: Serguei Sokol (sokol at insa-toulouse dot fr) License: Gnu Public License (GPL) v3 http://www.gnu.org/licenses/gpl.html

kvh

kvh.dict2kvh(d, fp=sys.stdout, indent=0)[source]

Write a nested dictionary on the stream fp (stdout by default).

kvh.escape(s, spch="|&;<>()$`\"' tn*?[#~=%", ech="\")[source]

escape special characters in s. The special characters are listed in spch. Escaping is done by putting an ech string before them. Default spch and ech corresponds to quoting Shell arguments in accordance with http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html Example: os.system(“ls %s” % escape(file_name_with_all_meta_chars_but_newline)); .. note:

  1. Escaped <newline> is removed by a shell if not put in a single-quotted string (’ ‘)
  2. A single-quote character even escaped cannot appear in a single-quotted string
kvh.kvh2dict(fp, strip=False)[source]

Read a kvh file from fp pointer then translate its tlist structure to a returned hierarchical dictionnary. Repeated keys at the same level of a dictionnary are silently overwritten

kvh.kvh2obj(fp, strip=False)[source]

Read a kvh file from fp pointer then translate its tlist structure to a returned object hierarchy. Repeated fields at the same level of an object are silently overwritten

kvh.kvh2tlist(fp, lev=[0], indent=[0], strip=False)[source]

Read a kvh file from fp stream descriptor and organize its content in list of tuples [(k1,v1), (k2,[(k2.1, v2.1)])] If fp is a string, it is used in open() operator

kvh.kvh_get_matrix(fp, keys)[source]

Get matrix or vector whose key suite is in a list keys from a kvh file given in fp (file pointer of file name). For big kvh files, this function can be much faster than kvh2tlist()+kvh_getv_by_k() Return a matrix which is a list of lists (rows). The first item in each row is the row name. In case of matrix (i.e. “row_col” is present in kvh file), the very first row contain column names.

kvh.kvh_getv_by_k(kvt, kl) → None|String|kvh tlist[source]

get value from kvt (kvh tlist) according to the key hierarchy defined in the list of keys kl. Return None if no key is found

kvh.kvh_read_key(fp, strip=False)[source]
Read a string from the current position till the first unescaped ,
or the end of stream fp.
Returns:tuple (key, sep), sep=None at the end of the stream
kvh.kvh_read_val(fp, strip=False)[source]
Read a string from current position till the first unescaped
or the end of file.
Return the read string.
kvh.kvh_tlist2dict(tlist)[source]

Translate a tlist structure read from a kvh file to a hierarchical dictionnary. Repeated keys at the same level of a dictionnary are silently overwritten

kvh.kvh_tlist2obj(tlist)[source]

Translate a tlist structure read from a kvh file to a hierarchical dictionnary. Repeated keys at the same level of a dictionnary are silently overwritten

kvh.tlist2kvh(d, fp=sys.stdout, indent=0)[source]

Write a (hierarchichal) list of 2-tuples on the stream fp (stdout by default).

tools_ssg

tools_ssg.aff(name, obj, ident=0, f=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]
print formatted object:
name=obj
tools_ssg.arr2pbm(A, fp)[source]

Write an image map of non-zero entries of matrix A to file pointer fp. Matrix A is an array

tools_ssg.asort(d)[source]

sorts a dictionnary by value preserving key=value association the result is a list of tuples (key,value)

tools_ssg.cumsum(l, tot=0)[source]
Returns:an iterable of the length len(l)+1 with cumulated sum of items in l. First element in cumsum is equal to initial value of tot. Result depends on the meaning of “+” operator for l items and of tot type.
>>> list(cumsum("abc",tot=""))
['', 'a', 'ab', 'abc']
>>> list(cumsum(xrange(1,5)))
[0, 1, 3, 6, 10]
tools_ssg.expandbit(i, pos)[source]

copy bits set to 1 in i to the result position given in the list pos. length of pos must be greater or equal to bitlength of i

tools_ssg.icumo2iiso(icumo, size)[source]
Returns:iterator on isotopomers composing a given icumo. size is carbon number
tools_ssg.isstr(s)[source]
Returns:True if the argument is a string
tools_ssg.iterbit(i, size=0)[source]

iterator on bits in integer starting from 0-position. The iterator stops at highest non-zero bit

tools_ssg.iternumbit(i, size=0)[source]

iterator on bits and its number in integer starting from 0-position. The iterator yields tuples (n,bit). If optional size is zero then it stops at highest non-zero bit. If not, it will stop at bit number size-1.

tools_ssg.join(c, l, p='', s='', a='')[source]

join the items of the list (or iterator) l separated by c. Each item is prefixed with p and suffixed with s. If the join result is empty for any reason, an alternative a is returned. p, s and a are optional

tools_ssg.joint(c, l, p='', s='', a='')[source]

join “true” items of the list (or iterator) l separated by c. Each item is prefixed with p and suffixed with s. If the join result is empty for any reason, an alternative a is returned. p, s and a are optional

tools_ssg.list2count(l, incr=1)[source]

count values in a (short) list l incrementing the counter by optional incr.

Returns:a dictionary {item:count}
tools_ssg.read_table(f) → dict(mat, col_names) read a plain text file f in a numpy mat. If some columns are not numerical, they are replaced by np.nan. If header=True, number of column names in the first row after skip must be the same as the number of values in each following row.[source]
tools_ssg.reverse(it)[source]

reverse order of an iterable

tools_ssg.rstrbit(i, size=0)[source]
Returns:the integer as reversed string binary representation. The lowest bit is on the left side
tools_ssg.setbit32(i, nb)[source]

set a bit number nb (0 based) in an integer i

tools_ssg.setcharbit(s, ch, i)[source]

set character ch in a string s everywhere a corresponding bit of i is set

tools_ssg.ssign(i, sp='+', sm='-')[source]
Returns:a string of i sign: sp (i>=0) or sm (i<0).
tools_ssg.strbit(i, size=0)[source]
Returns:the lowest part of integer as string binary representation
tools_ssg.strbit2int(s)[source]

translate a string of 0’s and 1’s interpreted as bits to an integer all characters different from 0,1 are silently ignored.

tools_ssg.strbit32(i)[source]
Returns:a string of 0-1s (in chunk of 4) in an 32 bit integer
tools_ssg.sumbit(i)[source]
Returns:sum of bits in an integer
tools_ssg.trd(l, d, p='', s='', a='')[source]

translate items in an iterable l by a dictionary d, prefixing translated items by optional p and suffixing them by optional s. If an item is not found in the dictionnary alternative string a is used. If a==None, the item is left unchanged. No prefix or suffix are applied in both case.

Returns:iterator
tools_ssg.ulong(i) → workarounded ulong[source]
tools_ssg.valval(o, keepNone=True)[source]
Returns:an iterator over values of values, i.e. collapsing values of fisrt two nested lists in one list, for example.
tools_ssg.wxlay2py(kvt, parent=[None])[source]
Returns:a string with python code generating wxWindow widget layout described in kvh tlist sturcture