{ "metadata": { "name": "", "signature": "sha256:6beabf4f7341b77308ce7652d05a0bc127bac90cd89859a4b47e64a632def4db" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Measuring chromatin fluorescence\n", "\n", "Goal: we want to quantify the amount of a particular protein (red fluorescence) localized on the centromeres (green) versus the rest of the chromosome (blue).\n", "\n", "![Chromosomes](images/chromosomes.jpg)\n", "\n", "The main challenge here is the uneven illumination, which makes isolating the chromosomes a struggle." ] }, { "cell_type": "code", "collapsed": false, "input": [ "%matplotlib inline\n", "import numpy as np\n", "from matplotlib import cm, pyplot as plt\n", "import skdemo\n", "plt.rcParams['image.cmap'] = 'cubehelix'\n", "plt.rcParams['image.interpolation'] = 'none'" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "from skimage import io\n", "image = io.imread('images/chromosomes.tif')\n", "skdemo.imshow_with_histogram(image)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's separate the channels so we can work on each individually." ] }, { "cell_type": "code", "collapsed": false, "input": [ "protein, centromeres, chromosomes = image.transpose((2, 0, 1))" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Getting the centromeres is easy because the signal is so clean:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "from skimage.filter import threshold_otsu\n", "centromeres_binary = centromeres > threshold_otsu(centromeres)\n", "skdemo.imshow_all(centromeres, centromeres_binary)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "But getting the chromosomes is not so easy:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "chromosomes_binary = chromosomes > threshold_otsu(chromosomes)\n", "skdemo.imshow_all(chromosomes, chromosomes_binary)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's try using an adaptive threshold:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "from skimage.filter import threshold_adaptive\n", "chromosomes_adapt = threshold_adaptive(chromosomes, block_size=51)\n", "# Question: how did I choose this block size?\n", "skdemo.imshow_all(chromosomes, chromosomes_adapt)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Not only is the uneven illumination a problem, but there seem to be some artifacts due to the illumination pattern!\n", "\n", "**Exercise:** Can you think of a way to fix this?\n", "\n", "(Hint: in addition to everything you've learned so far, check out [`skimage.morphology.remove_small_objects`](http://scikit-image.org/docs/dev/api/skimage.morphology.html#skimage.morphology.remove_small_objects))" ] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now that we have the centromeres and the chromosomes, it's time to do the science: get the distribution of intensities in the red channel using both centromere and chromosome locations." ] }, { "cell_type": "code", "collapsed": false, "input": [ "# Replace \"None\" below with the right expressions!\n", "centromere_intensities = None\n", "chromosome_intensities = None\n", "all_intensities = np.concatenate((centromere_intensities,\n", " chromosome_intensities))\n", "minint = np.min(all_intensities)\n", "maxint = np.max(all_intensities)\n", "bins = np.linspace(minint, maxint, 100)\n", "plt.hist(centromere_intensities, bins=bins, color='blue',\n", " alpha=0.5, label='centromeres')\n", "plt.hist(chromosome_intensities, bins=bins, color='orange',\n", " alpha=0.5, label='chromosomes')\n", "plt.legend(loc='upper right')\n", "plt.show()" ], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }