nulogo

Dynamics Module

flyeye.dynamics provides methods for analyzing and visualizing protein expression dynamics.

Moving Averages

Tools for evaluating the moving average of empirical timeseries data.

flyeye.dynamics.averages.apply_custom_roller(func, x, **kwargs)[source]

Apply function to rolling window.

Args:

func (function) - function applied to each window, returns 1 x N_out

x (np.ndarray) - ordered samples, length N

kwargs: keyword arguments for window specification

Returns:

fx (np.ndarray) - function output for each window, N/resolution x N_out

flyeye.dynamics.averages.bootstrap(x, func=<function mean>, confidence=95, N=1000)[source]

Returns point estimate obtained by parametric bootstrap.

Args:

x (np.ndarray) - ordered samples, length N

func (function) - function applied to each bootstrap sample

confidence (float) - confidence interval, between 0 and 100

N (int) - number of bootstrap samples

Returns:

interval (np.ndarray) - confidence interval bounds

flyeye.dynamics.averages.detrend_signal(x, window_size=99, order=1)[source]

Detrend and scale fluctuations using first-order univariate spline.

Args:

x (np array) -ordered samples

window_size (int) - size of interpolation window for lowpass filter

order (int) - spline order

Returns:

residuals (np array) - detrended residuals

trend (np array) - spline fit to signal

flyeye.dynamics.averages.get_binned_mean(x, window_size=100)[source]

Returns mean values within non-overlapping sequential windows.

Args:

x (np.ndarray) - ordered samples, length N

window_size (int) - size of window, W

Returns:

means (np.ndarray) - bin means, N/W x 1

flyeye.dynamics.averages.get_rolling_gaussian(x, window_size=100, resolution=10)[source]

Returns gaussian fit within sliding window.

Args:

x (np.ndarray) - ordered samples

window_size (int) - size of window

resolution (int) - sampling interval

Returns:

model (scipy.stats.norm)

flyeye.dynamics.averages.get_rolling_mean(x, **kw)[source]

Compute rolling mean. This implementation permits flexible sampling intervals and multi-dimensional time series, but is slower than get_running_mean for 1D time series.

Args:

x (np.ndarray) - ordered samples, length N

kw: arguments for window specification

Returns:

means (np.ndarray) - moving average of x, N/resolution x 1

flyeye.dynamics.averages.get_rolling_mean_interval(x, window_size=100, resolution=1, confidence=95, nbootstraps=1000)[source]

Evaluate confidence interval for moving average of ordered values.

Args:

x (np.ndarray) - ordered samples, length N

window_size (int) - size of window, W

resolution (int) - sampling interval

confidence (float) - confidence interval, between 0 and 100

nbootstraps (int) - number of bootstrap samples

Returns:

interval (np.ndarray) - confidence interval bounds, N/resolution x 2

flyeye.dynamics.averages.get_rolling_window(x, window_size=100, resolution=1)[source]

Return array slices within a rolling window.

Args:

x (np.ndarray) - ordered samples, length N

window_size (int) - size of window, W

resolution (int) - sampling interval

Returns:

windows (np.ndarray) - sampled values, N/resolution x W

flyeye.dynamics.averages.get_running_mean(x, window_size=100)[source]

Returns running mean for a 1D vector. This is the fastest implementation, but is limited to one-dimensional arrays and doesn’t permit interval specification.

Args:

x (np.ndarray) - ordered samples, length N

window_size (int) - size of window, W

Returns:

means (np.ndarray) - moving average of x

flyeye.dynamics.averages.savgol(x, window_size=100, polyorder=1)[source]

Perform Savitzky-Golay filtration of 1-D array.

Args:

x (np.ndarray) - ordered samples

window_size (int) - filter size

polyorder (int) - polynomial order

Returns:

trend (np.ndarray) - smoothed values

flyeye.dynamics.averages.subsample(x, frac=1)[source]

Subsample array with replacement.

Args:

x (np.ndarray) - ordered samples, length N

frac (float) - sample size (fraction of array)

Returns:

sample (np.ndarray) - subsampled values

Moving Averages

Tools for resampling discretized data.

class flyeye.dynamics.resampling.DiscResampler(cells, variable, window_size=250, resolution=10, nbootstraps=1000, confidence=95)[source]

Class for evaluating the moving average across multiple discrete populations of cells. Measurements are resampled from pools of cells generated by resampling the discrete populations.

Attributes:

data (pd.DataFrame) - cell measurement data, including a disc_id attribute

variable (str) - variable to be averaged

window_size (int) - rolling window size

resolution (int) - sampling resolution

nbootstraps (int) - number of resampling

confidence (float) - confidence interval, 0 to 100

point_estimates (np.ndarray[float]) - array of point estimates within each window

apply(f, x)[source]

Applies function <f> to rolling window over <x>.

bootstrap(idx, variable, f=<function mean>, nbootstraps=1000)[source]

Returns list of point estimates obtained by resampling eye discs.

Args:

idx (pd.Index) - indices for current window

variable (str) - name of variable

nbootstraps (int) - number of resamplings

Returns:

point_estimates (list) - point estimates obtained by resampling eye discs

property confidence_interval

95% confidence interval for rolling average of variable.

generate_point_estimates()[source]

Returns an array of point estimates within each window.

property mean

Rolling average of variable.

roll(x)[source]

Returns rolling window over <x>.

subsample_discs(values_per_disc)[source]

Subsample discs within the specified set of positional indices, then cells within them.

Args:

values_per_disc (dict) - dictionary of values keyed by disc indices

Returns:

sample (np.ndarray[float]) - sample randomized within and between discs

Timeseries Visualization

Tools for visualizing empirical timeseries data.

class flyeye.dynamics.visualization.IntervalPlot(x, y_lower, y_upper, y=None, ax=None)[source]

Object describes the 95% confidence interval for a 1D timeseries.

Attributes:

x (np.ndarray) - independent variable

y_lower (np.ndarray) - lower bound for dependent variable

y_upper (np.ndarray) - upper bound for dependence variable

y (np.ndarray) - mean or median value for dependent variable

ax (matplotlib.axes.AxesSubplot)

average(smooth=True, color='k', alpha=1, lw=1, linestyle=None, **addtl)[source]

Plot moving average of x and y data.

Args:

smooth (bool) - if True, apply first-order savgol filter

color, alpha, lw, linestyle - formatting parameters

interval(color='k', alpha=0.5, **additional)[source]

Plot confidence interval for moving average of x and y data.

Args:

color, alpha - formatting parameters

plot(average=True, interval=False, line_kw={}, interval_kw={})[source]

Plot timeseries data.

Args:

average (bool) - if True, add moving average

interval (bool) - if True, add moving average interval

line_kw (dict) - keyword arguments for line formatting

interval_kw (dict) - keyword arguments for interval formatting

class flyeye.dynamics.visualization.TimeseriesPlot(x, y, ax=None)[source]

Object describes a 1D timeseries.

Attributes:

x (np.ndarray) - independent variable

y (np.ndarray) - dependent variable

ax (matplotlib.axes.AxesSubplot)

average(ma_type='savgol', window_size=100, resolution=1, smooth=True, color='k', alpha=1, lw=1, linestyle=None, **additional)[source]

Plot moving average of x and y data.

Args:

ma_type (str) - type of average, ‘savgol’, ‘sliding’, or ‘binned’

window_size (int) - size of sliding window or bin (num of cells)

resolution (int) - sampling resolution for confidence interval

smooth (bool) - if True, apply secondary savgol filter

color, alpha, lw, linestyle - formatting parameters

create_figure()[source]

Instantiate figure.

interval(ma_type='sliding', window_size=100, resolution=25, nbootstraps=1000, confidence=95, color='k', alpha=0.5, **additional)[source]

Plot confidence interval for moving average of x and y data.

Args:

ma_type (str) - type of moving average, ‘sliding’ or ‘binned’

window_size (int) - size of sliding window or bin (num of cells)

resolution (int) - sampling resolution for confidence interval

nbootstraps (int) - number of bootstraps

confidence (float) - confidence interval, between 0 and 100

color, alpha - formatting parameters

plot(scatter=False, average=True, interval=False, marker_kw={}, line_kw={}, interval_kw={}, ma_kw={})[source]

Plot timeseries data.

Args:

scatter (bool) - if True, add datapoints

average (bool) - if True, add moving average

interval (bool) - if True, add moving average interval

marker_kw (dict) - keyword arguments for marker formatting

line_kw (dict) - keyword arguments for line formatting

interval_kw (dict) - keyword arguments for interval formatting

ma_kw (dict) - keyword arguments for moving average

scatter(color='k', alpha=1, s=1, rasterized=False, **additional)[source]

Scatterplot markers for x and y data.

Args:

color (str) - marker color

alpha (float) - marker alpha

s (float) - marker size

rasterized (bool) - if True, rasterize markers

flyeye.dynamics.visualization.plot_mean(x, y, ax, label=None, ma_type='sliding', window_size=100, resolution=1, line_color='k', line_width=1, line_alpha=1, linestyle=None, markersize=2, smooth=False, **kw)[source]

Plot moving average.

Args:

x, y (array like) - timeseries data

ax (matplotlib.axes.AxesSubplot) - axis which to which line is added

label (str) - data label

ma_type (str) - type of average used, either sliding, binned, or savgol

window_size (int) - size of window

resolution (int) - sampling interval

line_color, line_width, line_alpha, linestyle - formatting parameters

smooth (bool) - if True, apply secondary savgol filter

Returns:

line (matplotlib.lines.Line2D)

flyeye.dynamics.visualization.plot_mean_interval(x, y, ax, ma_type='sliding', window_size=100, resolution=10, nbootstraps=1000, confidence=95, color='grey', alpha=0.25, error_bars=False, lw=0.0)[source]

Adds confidence interval for line average (sliding window or binned) to existing axes.

Args:

x, y (array like) - data

ax (axes) - axis which to which line is added

ma_type (str) - type of average used, either ‘sliding’ or ‘binned’

window_size (int) - size of sliding window or bin (num of cells)

interval_resolution (int) - sampling resolution for confidence interval

nbootstraps (int) - number of bootstraps

confidence (float) - confidence interval, between 0 and 100

color, alpha - formatting parameters