sbmlutils.data.interpolation

Create files for interpolation of datasets.

https://github.com/allyhume/SBMLDataTools https://github.com/allyhume/SBMLDataTools.git

TODO: fix composition with existing models TODO: support coupling with existing models via comp The functionality is very useful, but only if this can be applied to existing models in a simple manner.

Module Contents

Classes

Interpolator

Interpolator class handles the 2D interpolation of given data series.

Interpolation

Create SBML model which interpolates the given data.

Attributes

logger

notes

INTERPOLATION_CONSTANT

INTERPOLATION_LINEAR

INTERPOLATION_CUBIC_SPLINE

sbmlutils.data.interpolation.logger[source]
sbmlutils.data.interpolation.notes[source]
sbmlutils.data.interpolation.INTERPOLATION_CONSTANT = 'constant'[source]
sbmlutils.data.interpolation.INTERPOLATION_LINEAR = 'linear'[source]
sbmlutils.data.interpolation.INTERPOLATION_CUBIC_SPLINE = 'cubic spline'[source]
class sbmlutils.data.interpolation.Interpolator(x, y, method=INTERPOLATION_CONSTANT)[source]

Interpolator class handles the 2D interpolation of given data series.

Two data series and the type of interpolation are provided.

Parameters:
  • x (pandas.Series) –

  • y (pandas.Series) –

  • method (str) –

property xid: str[source]

X id.

Return type:

str

property yid: str[source]

Y id.

Return type:

str

__str__()[source]

Convert to string.

Return type:

str

formula()[source]

Get formula string.

Return type:

str

static _formula_cubic_spline(x, y)[source]

Get formula for the cubic spline.

This is more complicated and requires the coefficients from the spline interpolation.

Parameters:
  • x (pandas.Series) –

  • y (pandas.Series) –

Return type:

str

static _natural_spline_coeffs(X, Y)[source]

Calculate natural spline coefficients.

Calculation of coefficients for

di*(x - xi)^3 + ci*(x - xi)^2 + bi*(x - xi) + ai

for x in [xi, xi+1]

Natural splines use a fixed second derivative, such that S’’(x0)=S’’(xn)=0, whereas clamped splines use fixed bounding conditions for S(x) at x0 and xn.

A trig-diagonal matrix is constructed which can be efficiently solved.

Equations and derivation from: https://jayemmcee.wordpress.com/cubic-splines/ http://pastebin.com/EUs31Hvh

Returns:

Return type:

Parameters:
  • X (pandas.Series) –

  • Y (pandas.Series) –

static _formula_linear(col1, col2)[source]

Linear interpolation between data points.

Parameters:
  • col1 (pandas.Series) –

  • col2 (pandas.Series) –

Return type:

str

static _formula_constant(col1, col2)[source]

Define constant value between data points.

Returns the piecewise formula string for the constant interpolation.

piecewise x1, y1, [x2, y2, ][…][z] A piecewise function: if (y1), x1.Otherwise, if (y2), x2, etc.Otherwise, z.

Parameters:
  • col1 (pandas.Series) –

  • col2 (pandas.Series) –

Return type:

str

class sbmlutils.data.interpolation.Interpolation(data, method='linear')[source]

Create SBML model which interpolates the given data.

The second to last components are interpolated against the first component.

Parameters:
  • data (pandas.DataFrame) –

  • method (str) –

validate_data()[source]

Validate the input data.

  • The data is expected to have at least 2 columns.

  • The data is expected to have at least three data rows.

  • The first column should be in ascending order.

Returns:

Return type:

static from_csv(csv_file, method='linear', sep=',')[source]

Interpolation object from csv file.

Parameters:
  • csv_file (Union[pathlib.Path, str]) –

  • method (str) –

  • sep (str) –

Return type:

Interpolation

static from_tsv(tsv_file, method='linear')[source]

Interpolate object from tsv file.

Parameters:
  • tsv_file (Union[pathlib.Path, str]) –

  • method (str) –

Return type:

Interpolation

write_sbml_to_file(sbml_out)[source]

Write the SBML file.

Parameters:

sbml_out (pathlib.Path) – Path to SBML file

Returns:

Return type:

None

write_sbml_to_string()[source]

Write the SBML file.

Returns:

SBML str

Return type:

Optional[str]

_create_sbml()[source]

Create the SBMLDocument.

Return type:

None

_init_sbml_model()[source]

Create and initialize the SBML model.

Return type:

None

static create_interpolators(data, method)[source]

Create all interpolators for the given data set.

The columns 1, … (Ncol-1) are interpolated against column 0.

Parameters:
  • data (pandas.DataFrame) –

  • method (str) –

Return type:

List[Interpolator]

static add_interpolator_to_model(interpolator, model)[source]

Add interpolator to model.

The parameters, formulas and rules have to be added to the SBML model.

Parameters:
  • interpolator (Interpolator) –

  • model (libsbml.Model) – Model

Returns:

Return type:

None