{"componentChunkName":"component---src-templates-blog-post-js","path":"/allensdk_for_training_skeletonizers/","result":{"data":{"site":{"siteMetadata":{"title":"tigue.com"}},"markdownRemark":{"id":"023d3423-1dab-5d64-88b4-a73d7dab1814","excerpt":"651806289 MinIP The Cell Types Database is one of the major data products of The Allen Institute for Brain Science. In the Cell Types\nproject, the Allen is…","html":"<p><img src=\"http://reconstrue.com/projects/brightfield_neurons/demo_images/651806289_minip_cubehelix_wide.png\" alt=\"651806289 MinIP\"></p>\n<p><a href=\"http://celltypes.brain-map.org/\">The Cell Types Database</a> is one of the major data products of The Allen Institute for Brain Science. In the Cell Types\nproject, the Allen is constructing an altas of all type of cells found in brains of mice and humans. </p>\n<p>There are multiple ways different cells are represented in the Database: electrophysiology spike train recordings, simulation models (GLIF or perisomatic), etc. Of particular interest for <a href=\"http://reconstrue.com\">the Reconstrue project</a> is the morphology data – the skeletons in the <code class=\"language-text\">*.swc</code> files.</p>\n<p>The Allen has created <a href=\"http://celltypes.brain-map.org/data?donor__species=Mus%20musculus&#x26;nr__reconstruction_type=%5Bfull,dendrite-only%5D\">about 500 SWC files for mouse neurons</a>. In the following Venn diagram of all The Allen’s mouse cells, those ~500 SWC files are grouped inside the red circle.</p>\n<p><img src=\"http://reconstrue.com/projects/brightfield_neurons/demo_images/brain_map_venn.png\"></p>\n<p>The main problem from The Allen’s perspective is that they would like to have the red circle be as big as the main outer circle. Each SWC files represents many hours of manual labor by trained specialists reviewing and editing the SWC file. The Allen processes hundreds of such cells a year. Creating skeleton reconstructions is currently a serious manual labor bottleneck.</p>\n<p>The header image of this post is an example brightfield imaged neuron from The Cell Types Database. This would seem like the sort of object recognition that CNNs and friends (RNNs, FFNs, U-Net, etc.) could automate. This is proving to be nontrivial. </p>\n<h2>Model training data</h2>\n<p>The image stack is the input to the machine to be built, and the SWC file is the output. </p>\n<p>From a model training perspective, the skeleton in an SWC file can be seen as the “labels” (labeling each voxel in a volume as either inside or outside the cell) for “the training data” (read: the brightfield image stacks). As such, for the purpose of training reconstruction models, we’re only interested in the subset of cells in the atlas Cell Types Database that have skeletons and a microscopy image stack. </p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">!pip install <span class=\"token operator\">-</span><span class=\"token operator\">-</span>quiet allensdk</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token comment\"># Query the Cell Types DB for files with skeletons a.k.a. reconstructions</span>\n\n<span class=\"token comment\"># via https://allensdk.readthedocs.io/en/latest/cell_types.html#cell-types-cache</span>\n<span class=\"token keyword\">from</span> allensdk<span class=\"token punctuation\">.</span>core<span class=\"token punctuation\">.</span>cell_types_cache <span class=\"token keyword\">import</span> CellTypesCache\n\nctc <span class=\"token operator\">=</span> CellTypesCache<span class=\"token punctuation\">(</span>manifest_file<span class=\"token operator\">=</span><span class=\"token string\">'cell_types/manifest.json'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\"># a list of cell metadata for cells with reconstructions, download if necessary</span>\ncells <span class=\"token operator\">=</span> ctc<span class=\"token punctuation\">.</span>get_cells<span class=\"token punctuation\">(</span>require_reconstruction<span class=\"token operator\">=</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Number of cells with SWC files: %i'</span> <span class=\"token operator\">%</span> <span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>cells<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Number of cells with SWC files: 637</code></pre></div>\n<p>Some of those are human cells, atop the roughly 500 mouse cells. Humans brains are much bigger than mouse brains. Training should focus on one species. The Allen has many more mouse neurons than human neurons. So, train on mouse neurons only.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> allensdk<span class=\"token punctuation\">.</span>api<span class=\"token punctuation\">.</span>queries<span class=\"token punctuation\">.</span>cell_types_api <span class=\"token keyword\">import</span> CellTypesApi\n\n<span class=\"token comment\"># We want mouse cells that have images and skeletons, both.</span>\n<span class=\"token comment\"># Former is data; latter is training labels a.k.a. gold standards.</span>\ncells <span class=\"token operator\">=</span> ctc<span class=\"token punctuation\">.</span>get_cells<span class=\"token punctuation\">(</span>require_reconstruction<span class=\"token operator\">=</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span> require_morphology<span class=\"token operator\">=</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span> species<span class=\"token operator\">=</span><span class=\"token punctuation\">[</span>CellTypesApi<span class=\"token punctuation\">.</span>MOUSE<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Number of mouse cells with images and SWC files: %i'</span> <span class=\"token operator\">%</span> <span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>cells<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Number of mouse cells with images and SWC files: 485</code></pre></div>\n<p>So, for brightfield reconstructor training, The Allen’s Cell Types Database can be used as a labeled training dataset consisting of about 500 samples. That’s somewhere on the order of\nten petabytes of training data.</p>\n<h2>References</h2>\n<p><a href=\"http://help.brain-map.org/display/celltypes/Physiology+and+Morphology\">Cell Types DB Physiology and Morphology whitepaper</a></p>\n<p><a href=\"https://allensdk.readthedocs.io/en/latest/allensdk.core.cell_types_cache.html#allensdk.core.cell_types_cache.CellTypesCache.get_cells\">cell types cache docs</a>.</p>","frontmatter":{"title":"Traing Data for Neuron Reconstructors","date":"January 27, 2020","description":null}}},"pageContext":{"isCreatedByStatefulCreatePages":false,"slug":"/allensdk_for_training_skeletonizers/","previous":{"fields":{"slug":"/colormapping/"},"frontmatter":{"title":"Brightfield colormapping"}},"next":{"fields":{"slug":"/monocle3_on_colab/"},"frontmatter":{"title":"Monocle3 on Colab"}}}}}