项目作者: oganm

项目描述 :
:mouse: Acquiring images from allen brain atlas, mouse ISH experiments in R.
高级语言: R
项目地址: git://github.com/oganm/allenBrain.git
创建时间: 2016-04-29T00:04:09Z
项目社区:https://github.com/oganm/allenBrain

开源协议:MIT License

下载


Table of Contents

allenBrain

This R package acquires pictures from Allen Brain Atlas.

Install allenBrain to R

  1. devtools::install_github('oganm/allenBrain')

Example usage

Image acquisition

You can use downloadImage and downloadAtlas functions to get images.
Output of these functions are magick-image objects

  1. library(dplyr)
  2. # get a list of structure names and ids
  3. IDs = getStructureIDs()
  4. IDs %>% head
  1. ## id name acronyms parent
  2. ## 1 997 root root <NA>
  3. ## 2 8 Basic cell groups and regions grey 997
  4. ## 3 567 Cerebrum CH 8
  5. ## 4 688 Cerebral cortex CTX 567
  6. ## 5 695 Cortical plate CTXpl 688
  7. ## 6 315 Isocortex Isocortex 695
  1. # get the id of the desired region
  2. granuleID = IDs['Dentate gyrus, granule cell layer' == IDs$name,]$id
  3. # get the dataset for the desired gene (the first saggital experiment that did not fail)
  4. datasetID = getGeneDatasets(gene = 'Prox1',
  5. planeOfSection = 'sagittal',
  6. probeOrientation = 'antisense')[1]
  7. # get the slide that has the desired brain region and coordinates of the center of the region
  8. imageID = structureToImage(datasetID = datasetID, regionIDs = granuleID)
  9. # get the closest atlas image.
  10. atlasID = imageToAtlas(imageID$section.image.id,imageID$x,imageID$y,planeOfSection ='sagittal')
  11. # decide how much to you wish to downsample
  12. downsample = 2
  13. # download the slide
  14. downloadImage(imageID = imageID$section.image.id,
  15. view = 'projection',
  16. outputFile = 'README_files/image.jpg',
  17. downsample = downsample)

  1. # download the atlas
  2. downloadAtlas(imageID = atlasID$section.image.id,
  3. outputFile = 'README_files/atlas.jpg',
  4. downsample = downsample)

Images can be centered by providing center coordinates of a brain
region. Input is either a file path or a magick-image object

  1. # crop the slide so that the desired brain region is in the center
  2. centerImage(image = 'README_files/image.jpg',
  3. x = imageID$x,
  4. y= imageID$y,
  5. xProportions = c(.1,.1),
  6. yProportions =c(.1,.1),
  7. outputFile = 'README_files/cropped.jpg',
  8. downsample = downsample)

  1. centerImage(image = 'README_files/atlas.jpg',
  2. x = atlasID['x'],
  3. y= atlasID['y'],
  4. xProportions = c(.1,.1),
  5. yProportions =c(.1,.1),
  6. outputFile = 'README_files/croppedAtlas.jpg',
  7. downsample = downsample)

Adding a scale to the image

getSectionImage function returns all available information about an
image. We can use this to access the resolution information which lists
micron/pixel ratio in a given image.

  1. (image_res = getSectionImage(imageID$section.image.id)$resolution)
  1. ## [1] "1.049"

We can then use the add_scale function to add a scale

  1. downloadImage(imageID = imageID$section.image.id,
  2. view = 'projection',
  3. downsample = downsample) %>%
  4. centerImage(x = imageID$x,
  5. y= imageID$y,
  6. xProportions = c(.1,.1),
  7. yProportions =c(.1,.1),
  8. outputFile = 'README_files/cropped.jpg',
  9. downsample = downsample) %>%
  10. add_scale(image_res,downsample)

Image syncronization

You can get closest points of other slides from the same dataset to get
other slides depicting the region

  1. # gel all images for Prox1 experiment
  2. allImages = listImages(datasetID) %>% arrange(as.numeric(`section.number`))
  3. # get coordinates that are closest to the center of the brain region
  4. closeSections = imageToImage2D(imageID$section.image.id,imageID$x,imageID$y,allImages$id)
  5. # download and crop them all
  6. croppedImage = closeSections %>% apply(1,function(x){
  7. # download and crop the images
  8. image = downloadImage(imageID = x['section.image.id'],
  9. view = 'projection',
  10. # outputFile = file.path('README_files/allProx1',x['section.image.id']),
  11. downsample = downsample)
  12. centerImage(image = image,
  13. x = x['x'],
  14. y= x['y'],
  15. xProportions = c(.1,.1),
  16. yProportions =c(.1,.1),
  17. # outputFile = file.path('README_files/allProx1',x['section.image.id']),
  18. downsample = downsample)
  19. }) %>% do.call(c,.)
  20. # some magick
  21. animation = magick::image_animate(croppedImage, fps = 1)
  22. magick::image_write(animation, "README_files/Prox1.gif")

Region expression data

Region expression can be acquired by datasetID. Data displayed in ABA
web portals is expression.energy.

  1. head(getStructureExpressions(datasetID))
  1. ## expression.density expression.energy id section.data.set.id
  2. ## 1 0.00877632 1.256040 417549802 69289763
  3. ## 2 0.00877632 1.256040 417549811 69289763
  4. ## 3 0.00977504 1.435310 417549818 69289763
  5. ## 4 0.00829527 1.240160 417549825 69289763
  6. ## 5 0.00490790 0.625739 417549832 69289763
  7. ## 6 0.00435703 0.550791 417549837 69289763
  8. ## structure.id sum.expressing.pixel.intensity sum.expressing.pixels
  9. ## 1 15564 990364000 6919940.0
  10. ## 2 15565 990364000 6919940.0
  11. ## 3 15566 788831000 5372270.0
  12. ## 4 15567 612042000 4093880.0
  13. ## 5 15568 9924780 77843.7
  14. ## 6 15569 2830360 22389.6
  15. ## sum.pixel.intensity sum.pixels voxel.energy.cv voxel.energy.mean
  16. ## 1 38839100000 788478000 2.29688 1.247900
  17. ## 2 38839100000 788478000 2.29688 1.247900
  18. ## 3 27367800000 549591000 2.34411 1.429890
  19. ## 4 24459100000 493519000 2.66998 1.231220
  20. ## 5 682957000 15860900 1.23383 0.633086
  21. ## 6 235064000 5138730 1.48268 0.558472
  22. ## structure.acronym structure.color.hex.triplet structure.graph.order
  23. ## 1 mouse C86A39 0
  24. ## 2 NP C86A39 1
  25. ## 3 F C86A39 2
  26. ## 4 SP A84D10 3
  27. ## 5 RSP A84D10 4
  28. ## 6 POTel A84D10 5
  29. ## structure.hemisphere.id structure.id.1 structure.name
  30. ## 1 3 15564 Mus musculus
  31. ## 2 3 15565 neural plate
  32. ## 3 3 15566 forebrain
  33. ## 4 3 15567 secondary prosencephalon
  34. ## 5 3 15568 rostral secondary prosencephalon
  35. ## 6 3 15569 preoptic telencephalon
  36. ## structure.ontology.id structure.safe.name structure.st.level
  37. ## 1 12 Mus musculus -1
  38. ## 2 12 neural plate 0
  39. ## 3 12 forebrain 1
  40. ## 4 12 secondary prosencephalon 2
  41. ## 5 12 rostral secondary prosencephalon 3
  42. ## 6 12 preoptic telencephalon 4
  43. ## structure.structure.id.path structure.structure.name.facet
  44. ## 1 /15564/ 3843147059
  45. ## 2 /15564/15565/ 3041346888
  46. ## 3 /15564/15565/15566/ 2526114016
  47. ## 4 /15564/15565/15566/15567/ 333870831
  48. ## 5 /15564/15565/15566/15567/15568/ 2675393843
  49. ## 6 /15564/15565/15566/15567/15568/15569/ 2617066679
  50. ## structure.weight
  51. ## 1 8390
  52. ## 2 8390
  53. ## 3 8390
  54. ## 4 8390
  55. ## 5 8390
  56. ## 6 8390

If you want to get all genes, use listGenes to get all available genes
for the species. Then do getGeneDatasets.

  1. genes = listGenes()
  2. geneDatasets = genes$acronym[1:10] %>% lapply(getGeneDatasets)

You may want to limit your search space as getting the data for all
genes is a slow process.

Incomplete stuff

Grid data of a dataset can be downloaded by gridData function

  1. gridData(datasetID = datasetID,
  2. outputFile ='README_files/Prox1_data.zip',
  3. include = c('energy','density','intensity'))
  4. unzip(zipfile = 'README_files/Prox1_data.zip',exdir = "README_files")