Python · chapter 12 of 13
Function reference
All functions live in the grnlab package (import grnlab as grn). Arguments after the first are keyword arguments; defaults are in parentheses. Gene indices are 0-based; labels may be used wherever a gene is named.
Networks
m = grn.motif(name, size=4) — Registered motif: Motif with name, S, labels, description, preset. Names: toggle, repressilator, nar, par, ffl_coherent, ffl_incoherent, cascade, sim, bifan, goodwin. grn.MOTIF_NAMES lists them.
S = grn.random_network(n, ...) — Random signed adjacency. topology ("erdosrenyi" | "scalefree" | "smallworld" | "modular"), mean_degree (2), fraction_repressors (0.4), self_regulation (0), modules (4), within_fraction (0.8), rewire (0.1), seed (0), info (False: return (S, info) when True). grn.TOPOLOGIES lists the topologies.
rows = grn.catalog(show=True) — Prints motifs and topologies; returns (name, genes, description) tuples.
Models
model = grn.build_model(S, ...) — Kinetic model from an adjacency, motif name, or Motif. logic ("additive" | "multiplicative"), stages (1 | 2), seed (0), params (dict: k, K, hill, basal, gamma, vmax, beta, gammaP, ic), labels, name, hill_range ((1, 4)), gamma_range ((0.5, 1.5)), vmax_range ((1, 5)), k_rel_range ((0.3, 1.2)), basal_fraction ((0, 0.1)), gammap_range ((0.2, 1)), beta_ratio_range ((1, 1)).
model = grn.perturb(model, ...) — Scale production of genes; returns a copy. knockout, knockdown, overexpress (indices or labels), knockdown_factor (0.5), overexpress_factor (2).
s = grn.stimulus(gene, type, ...) — Time-varying input. type ("step" | "ramp" | "sine" | "custom"), amplitude, baseline, start (0), stop (inf), period (10), rise (0), mode ("scale" | "add"), function, breaks.
model = grn.stimulate(model, s) — Attach a stimulus or a list of stimuli to a copy of the model; None removes them.
model = grn.attach_handles(model) — Rebuild callables and derived attributes after editing parameters by hand.
model.copy() — Deep copy of the parameter arrays with fresh callables.
Simulation
sol = grn.simulate(model, ...) — Expression time series. duration (50), sample_dt (0.1), transient (0), cells (1), random_ic (False), initial_condition, solver ("ode45" | "ode15s"), noise ("none" | "additive" | "multiplicative" | "langevin"), noise_strength (0.1), dt (sample_dt/20), noise_sigma (0), seed (0), knockout, knockdown, overexpress, knockdown_factor, overexpress_factor, stimulus, logic (when model is a name or array).
xss = grn.steady_state(model, ...) — Fixed point; info=True returns (xss, info). initial_condition, max_time (2000), tol (1e-8), perturbation arguments, stimulus, time (0), logic, seed, info (False).
screen = grn.knockout_screen(model, ...) — Steady states under single-gene perturbations. type ("knockout" | "knockdown" | "overexpress"), factor, genes, noise_sigma (0), seed (0), max_time, tol, stimulus, time, logic.
Output
files = grn.export(data, filename) — .csv (plus _truth.csv and _adjacency.csv), .npz, or .pkl.
fig = grn.plot_network(model, ...) — layout ("auto" | "circle" | "force" | "layered"), labels, curvature (0.12), ax, title (True), legend (True), seed (1).
fig = grn.plot_motifs(names=None, ...) — columns (5), size (4).
fig = grn.plot_expression(sol, ...) — cell (0), max_lines (12), overlay (True), species ("protein" | "mrna").
grn.export_figure(fig, filename, ...) — resolution (300), style (True).
grn.style() — House-style palette and sizes.
Objects
Model, Solution, Screen, Motif, Stimulus are dataclasses; see Concepts and conventions for their attributes. Model and the data objects pickle cleanly.
Errors
Every error raised by the package is a grn.GRNError (a ValueError) whose message starts with an identifier shared with the MATLAB toolbox:
| Identifier | Raised when |
|---|---|
grn:badAdjacency | S is not a finite square matrix |
grn:badParameter, grn:unknownParameter | A params value is invalid or its key unknown |
grn:badLabels | labels has the wrong length |
grn:unknownMotif | Motif name not registered |
grn:badMeanDegree, grn:badTopology | mean_degree exceeds n - 1; unknown topology |
grn:unknownGene | A gene index or label does not exist |
grn:badStimulus | Inconsistent stimulus arguments |
grn:badInitialCondition, grn:badNoiseSigma, grn:badSampleDt, grn:badDuration | Simulation arguments inconsistent with the model |
grn:badSolver, grn:badNoise, grn:badLogic, grn:badStages, grn:badType, grn:badLayout | An option outside its allowed set |
grn:integrationFailed | The ODE solver stopped early |
grn:badExportFormat | Unsupported file extension |