Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download
Views: 6249
License: OTHER
Kernel: Python 3
from __future__ import division, print_function %matplotlib inline

Measuring chromatin fluorescence

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).

Chromosomes

The main challenge here is the uneven illumination, which makes isolating the chromosomes a struggle.

import numpy as np from matplotlib import cm, pyplot as plt import skdemo plt.rcParams['image.cmap'] = 'cubehelix' plt.rcParams['image.interpolation'] = 'none'
from skimage import io image = io.imread('images/chromosomes.tif') skdemo.imshow_with_histogram(image)
(<matplotlib.axes.AxesSubplot at 0x1087fc8d0>, <matplotlib.axes.AxesSubplot at 0x10967cd90>)
Image in a Jupyter notebook

Let's separate the channels so we can work on each individually.

protein, centromeres, chromosomes = image.transpose((2, 0, 1))

Getting the centromeres is easy because the signal is so clean:

from skimage.filter import threshold_otsu centromeres_binary = centromeres > threshold_otsu(centromeres) skdemo.imshow_all(centromeres, centromeres_binary)
Image in a Jupyter notebook

But getting the chromosomes is not so easy:

chromosomes_binary = chromosomes > threshold_otsu(chromosomes) skdemo.imshow_all(chromosomes, chromosomes_binary)
Image in a Jupyter notebook

Let's try using an adaptive threshold:

from skimage.filter import threshold_adaptive chromosomes_adapt = threshold_adaptive(chromosomes, block_size=51) # Question: how did I choose this block size? skdemo.imshow_all(chromosomes, chromosomes_adapt)
Image in a Jupyter notebook

Not only is the uneven illumination a problem, but there seem to be some artifacts due to the illumination pattern!

Exercise: Can you think of a way to fix this?

(Hint: in addition to everything you've learned so far, check out skimage.morphology.remove_small_objects)

from skimage.morphology import (opening, selem, remove_small_objects) d = selem.diamond(radius=4) chr0 = opening(chromosomes_adapt, d) chr1 = remove_small_objects(chr0.astype(bool), 256) images = [chromosomes, chromosomes_adapt, chr0, chr1] titles = ['original', 'adaptive threshold', 'opening', 'small objects removed'] skdemo.imshow_all(*images, titles=titles, shape=(2, 2))
Image in a Jupyter notebook

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.

# Replace "None" below with the right expressions! centromere_intensities = protein[centromeres_binary] chromosome_intensities = protein[chr1] all_intensities = np.concatenate((centromere_intensities, chromosome_intensities)) minint = np.min(all_intensities) maxint = np.max(all_intensities) bins = np.linspace(minint, maxint, 100) plt.hist(centromere_intensities, bins=bins, color='blue', alpha=0.5, label='centromeres') plt.hist(chromosome_intensities, bins=bins, color='orange', alpha=0.5, label='chromosomes') plt.legend(loc='upper right') plt.show()
Image in a Jupyter notebook