{ "metadata": { "name": "", "signature": "sha256:e2b988ec2072f53f76001e59a307580dceb17180cd75dd7ced527dda42dc84ea" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Quantifying spinal cord regeneration in zebrafish\n", "\n", "We want to quantify the amount of fluorescent cells in a wounded zebrafish embryo spinal column:\n", "\n", "\"Zebrafish\n", "\n", "The key steps are:\n", "\n", "- estimating the position and width of the cord\n", "- estimating the average fluorescence along the length of the cord" ] }, { "cell_type": "code", "collapsed": false, "input": [ "%matplotlib inline\n", "from matplotlib import pyplot as plt, cm\n", "from skimage import io\n", "image = io.imread('images/zebrafish-spinal-cord.png')" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# SciPy to estimate coordinates\n", "\n", "First, we get just the top and bottom rows of pixels, and use a 1D gaussian filter to smooth the signal." ] }, { "cell_type": "code", "collapsed": false, "input": [ "from scipy import ndimage as nd\n", "top, bottom = image[[0, -1], :]\n", "\n", "fig, (ax0, ax1) = plt.subplots(nrows=1, ncols=2, figsize=(8, 3))\n", "\n", "top_smooth = nd.gaussian_filter1d(top, sigma=20)\n", "ax0.plot(top, color='blue', lw=2)\n", "ax0.plot(top_smooth, color='orange', lw=2)\n", "ax0.set_title('top')\n", "\n", "bottom_smooth = nd.gaussian_filter1d(bottom, sigma=20)\n", "ax1.plot(bottom, color='blue', lw=2)\n", "ax1.plot(bottom_smooth, color='orange', lw=2)\n", "ax1.set_title('bottom')" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "With smooth curves, we can get the mode (the position of the center) and width of the signal." ] }, { "cell_type": "code", "collapsed": false, "input": [ "top_mode = top_smooth.argmax()\n", "top_max = top_smooth[top_mode]\n", "top_width = (top_smooth > float(top_max) / 2).sum()\n", "\n", "bottom_mode = bottom_smooth.argmax()\n", "bottom_max = bottom_smooth[bottom_mode]\n", "bottom_width = (bottom_smooth > float(bottom_max) / 2).sum()\n", "\n", "width = max(bottom_width, top_width)\n", "\n", "print(top_mode, top_width, bottom_mode, bottom_width)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# scikit-image to trace the profile\n", "\n", "Now, use `measure.profile_line` to trace from (0, `top_mode`) to (-1, `bottom_mode`)." ] }, { "cell_type": "code", "collapsed": false, "input": [ "from skimage import measure\n", "trace = measure.profile_line(None) # Replace `None` with correct args" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Finally, plot the trace." ] }, { "cell_type": "code", "collapsed": false, "input": [ "plt.plot(trace, color='black', lw=2)\n", "plt.xlabel('position along embryo')\n", "plt.ylabel('mean fluorescence intensity')" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "From this trace, we can compute various summary statistics (e.g. min/max, gap width, slope, etc), and plot these over time as the wound recovers." ] } ], "metadata": {} } ] }