Making a shiny app to visualize brain cell type gene expression

Attention conservation notice: A post-mortem of a small side project that is probably not interesting to you unless you’re interested in molecular neuroscience.


This weekend I put together an R/Shiny app to visualize brain cell type gene expression patterns from 5 different public data sets. Here it is. Putting together a Shiny application turned out to be way easier than expected — I had something public within 3 hours, and most of the rest of my time on the project (for a total of ~ 10 hours?) was spent on cleaning the data on the back end to get it into a presentable format for the website.

What is the actual project? The goal is to visualize gene expression in different brain cell types. This is important because many disease-relevant genes are only expressed in one brain cell type but not others, and figuring this out can be critical to learning about the etiology of that disease.

There’s already a widely-used web app that does this for two data sets, but since this data is pretty noisy and there are subtle but important differences in the data collection processes, I figured that it’d be helpful to allow people to quickly query other data sets as well.

As an example, the gene that causes Huntington’s disease has the symbol HTT. (I say “cause” because variability in the number of repeat regions in this gene correlate almost perfectly with the risk of Huntington’s disease development and disease onset.) People usually discuss neurons when it comes to Huntington’s disease, and while this might be pathologically valid, by analyzing the data sets I’ve assembled you can see that this gene is expressed across a large number of brain cell types. This raises the question of why — and/or if — variation in its number of repeats only causes pathology in neurons.

Screen Shot 2016-06-13 at 11.35.10 AM

Here’s another link to the web app. If you get a chance to check it out, please let me know if you encounter are any problems, and please share if you find it helpful.

References

Aziz NA, Jurgens CK, Landwehrmeyer GB, et al, et al. Normal and mutant HTT interact to affect clinical severity and progression in Huntington disease. Neurology. 2009;73(16):1280-5.

Huang B, Wei W, Wang G, et al. Mutant huntingtin downregulates myelin regulatory factor-mediated myelin gene expression and affects mature oligodendrocytes. Neuron. 2015;85(6):1212-26.

Six weeks of exercise leads to increases in myelination

An interesting article by Thomas et al. recently measured the effect of six weeks of exercise on neuroimaging measures. Contra to expectations, they found that cerebral blood volume did not significantly change, while white matter volumes did show a significant increase. This suggests that the increases in cognition and hippocampal volume that occur following exercise may be due more to myelin changes than general blood flow changes in the brain per se.

Since blood perfusion is especially poor in white matter regions, it may have been that their study wasn’t able to detect finely grained improvements in blood flow following exercise (which we would have expected from theory and previous studies). Instead, it’s possible that their study detected increased white matter volume as a key consequence of improved blood flow in the brain selectively in the poorly perfused white matter brain regions. Either way, this is interesting data and helps illuminate the mechanisms behind a healthy amount of aerobic exercise.

Reference

Thomas AG, Dennis A, Rawlings NB, et al. Multi-modal characterization of rapid anterior hippocampal volume increase associated with aerobic exercise. Neuroimage. 2015.

Notes on segmenting oligodendrocytes in electron microscopy images using Python3 and OpenCV 3.0

Attention Conservation Notice: Not much new here; mostly just notes to myself for future reference. Reading this is unlikely to be a good use of your time, unless you are trying to install OpenCV 3.0 on Python3, in which case, I tremble with sympathy. (In all seriousness, installing it took me about an hour, but I made some trivial mistakes and it could be way quicker.)


Installing OpenCV for Python3

First of all, know that downloading and installing OpenCV (the CV stands for “Computer Vision”) for Python on a MacBook Pro can be pretty time consuming; one commenter I saw online called it “a rite of passage.” After failing to successfully download it for Python 2.7 for about half hour, I eventually decide to use this opportunity to upgrade to Python3.

Installing Python3 is easy:

brew install python3

I then followed Luis González’s useful tutorial for installing OpenCV as a module for Python3. I still ran into one problem, which is that I had a different version of Python. My recommendation here is to manually cd to those directories in your terminal to make sure that the files exist as they are meant to, and then copy and paste the paths into your Cmake GUI. Here is my successful configuration:

Cmake

Specifically, if you are getting the error

fatal error: 
 'Python.h' file not found
#include <Python.h>

(perhaps at 98% completion!), make sure to check that your $PYTHON3_INCLUDE_DIR is set properly; mine had a typo.

How to identify oligodendrocytes in electron microscopy images 

Once I had OpenCV downloaded, I was able to begin actually analyzing some EM images. I’m interested in being able to distinguish oligodendrocytes on electron microscopy from other brain cell types. It turns out this is a pretty difficult problem, and as far as I know, there is no large database of images from which a substantial training set (e.g., > ~ 200 images or so) could be built.

Instead, we can go based on published features of oligodendrocytes, which have been described previously (e.g., herehere, here, here, and here). As far as my novice understanding goes, these are some key features of oligodendrocytes:

  • Smooth, round-to-oval outline
  • Centrally placed, round-to-oval nuclei, (with “nucleoli occasionally seen on the plane of section”)
  • Distinct and dark Golgi apparatus in the cytoplasm
  • Thin processes (when they are visible)

And here are some features distinguishing oligodendrocytes from other cell types:

  • Astrocytes: a) paler (cytosplasm and nuclei), b) glycogen granules, c) filament bundles (due to GFAP), and d) wider processes (if the processes can be identified)
  • Neurons: large and pale nuclei
  • Microglia: more likely to be irregularly shaped, and sometimes have dark, small inclusions
  • NG2 cells: elongated or bean-shaped nuclei, and can contain long endoplasmic reticulum

Here is a picture of an oligodendrocyte from Alan Peter’s helpful website:

Alan Peter's oligodendrocyte EM

Using OpenCV to parse tissue slices 

Here is my code. I tried a few different strategies. My goal is to parse slice out a portion of the image that is recognizable as “the oligodendrocyte,” which can be seen by the human eye as the red portion here (also from Alan Peter’s website):

Peters Colors

1) Canny edge detection. This seems to be “too much” to be useful.

Canny

2) Otsu’s reduction of a greyscale to a binary image. This is actually not bad; maybe it could be stacked with another method?

Otsu

3) Blob detection. This is somewhat promising, but unfortunately the blobs detected are pretty small (too small to be the oligodendrocyte, or even the nucleus), and when I try to make them larger, no blobs are detected.

blobs

So, this is still a work-in-progress, but I wanted to get some notes up.

Reference

The fine structure of the aging brain. Authors: Alan Peters and Claire Folger Sethares. Boston University School of Medicine, 72 East Newton Street, Boston, MA 02118. Website: www.bu.edu/agingbrain. Supported by the Institute on Aging of the National Institute of Health, grant number P 01-AG 000001.

Age-related changes in white matter are likely not due to demyelination?

That’s the conclusion of an important new paper from Billiet et al that integrated a bunch of different imaging modalities.

First, they used DTI to measure fractional anisotropy, which is a non-specific measure of white matter, measuring axon density, axon diameter, and myelin content. They also used myelin water fraction (MWF) to measure myelin content and the orientation dispersion index (ODI) to measure dendrite/axon dispersion. These were their findings:

  • Total white matter volume does not change in aging
  • Myelin content (via MWF) is not significantly altered in aging in most regions, and in the regions where there is a change, it increases
  • There is a widespread decrease in fractional anisotropy in aging that is especially strong in frontal regions
  • Changes in myelin content (MWF) do not correlate well with this decrease in fractional anisotropy
  • Changes in neurite orientation (ODI) dispersion do correlate with this decrease in fractional anisotropy

Thus, their conclusion is that age-related decreases in the “diffusibility” of white matter (or whatever fractional anisotropy is measuring) are due to changes in axons rather than to changes in myelin.

It’s all cross-sectional, n = 59, and they call this conclusion “highly speculative,” but if true it suggests that axons changes are more early/causal/fundamental to aging than changes in myelin. We need more data on this, especially from older individuals (their study went up to only 70) and from people with dementias, such as Alzheimer’s disease.


Billiet T, Vandenbulcke M, Mädler B, et al. Age-related microstructural differences quantified using myelin water imaging and advanced diffusion MRI. Neurobiol Aging. 2015