Package bar :: Module barAllenApiAtlasPreprocessor :: Class barAllenApiAtlasPreprocessor
[hide private]
[frames] | no frames]

Class barAllenApiAtlasPreprocessor

Class barAllenApiAtlasPreprocessor

Purpose of the script below is to prepare input data for the Allen Brain Atlas 2011 volumetric dataset. Two partial datasets are processed. The first one is the labelled volume containing volume element to structure's name assignment. This volume is provided by Allen Institute in form of raw binary file and one needs to figure out what are the voxel dimensions and volume origin. Volume is processed by preprocessVolume function.

Instance Methods [hide private]
 
__init__(self, outputDirectory=None)
{str : barAllenApiAtlas, ... }
_updateAvailableAtlases(self)
This method downloads and parses summary of atlases available trought Allen Brain Institute API.
None
_downloadAtlas(self)
Download source data for currently processed atlas.
 
_loadAtlasSpaces(self)
Extract all available atlas spaces from the atlas.
None
processAtlas(self, atlasId, spaceName, fetchSourceData=True)
Returns: None
 
_setCurrentAtlasSpace(self, spaceName)
Returns: None
 
_getSourceDatasetZipfileName(self)
 
_getZipOutputZipfilename(self)
 
_getAnnotationsFilename(self)
 
_getInfoFilename(self)
 
_getOntologyFilename(self)
str
_getOutputLabeledVolumeFilename(self)
Generate filename for NIfTII volume generated from raw annotation volume.
 
_getHierarchyFilename(self)
 
_getMappingsFilename(self)
 
processVolume(self, applyPermutation=(0, 1, 2), reverseAxes=(False, False, False), dataType=<type 'numpy.uint16'>, reshapePermutation=(0, 1, 2), headerUpdate={}, qfac=1)
@type applyPermutation: (int, int, int) @param applyPermutation: Permutation of the axis' order.
numpy volume
_loadRawAnnotationFile(self, dataType=<type 'numpy.uint16'>, reshapePermutation=(0, 1, 2))
Returns: NumPy volume created ba parsing raw annotation file.
None
_assignHeaderInformation(self, niftiImage, applyPermutation=(0, 1, 2), reshapePermutation=(0, 1, 2), headerDict={}, qfac=1)
Returns: None
 
_processOntology(self)
Extract and process structure ontology information from source dataset.
(str, str)
_processSingleOntologyFileLine(self, ontologyLine)
Helper function for processing sungle ontology file line.
 
cleanup(self)
Remove atals package and extracted files of currently processed atlas.
Method Details [hide private]

__init__(self, outputDirectory=None)
(Constructor)

 
Parameters:
  • outputDirectory (str) - Working directory for the atals preprocessor. Usually this directory should be 'src' directory of a given atlas. For tesing purposes it may be changed. Default working directory is the current working dir.

_updateAvailableAtlases(self)

 

This method downloads and parses summary of atlases available trought Allen Brain Institute API.

Returns: {str : barAllenApiAtlas, ... }
A dictionary mapping id of a given atlas to the atlas object.

_downloadAtlas(self)

 

Download source data for currently processed atlas.

Returns: None
None

_loadAtlasSpaces(self)

 

Extract all available atlas spaces from the atlas.

Returns:
None

processAtlas(self, atlasId, spaceName, fetchSourceData=True)

 
Parameters:
  • atlasId (str or int) - Identifier of the atlas according to Allen Brain Institute identifiers of atlases :)
  • spaceName (str) - Name of atlas space from given atlas. Atlas space is kind of subatlas - a sigle atlas can have multiple spaces ie. taken in different time points ot for different specimens, etc. By this parameter you define a particular atlas space to process. The atlas space name has to be known in advance.
  • fetchSourceData (Bool) - Force source data downloading. True by default. Use when you want to download and extract the source data. Set to False when you already have the source data and there is no need to download it again.
Returns: None
None

Fundamental function of the whole class :) Function performs all steps of processing: 3) Downloading and extracting package with the atlas. 2) Reading information about atlas spaces available in given atlas. 4) Processing ontology from given atlas to form acceptable by 3dBAR's parsers. 5) Processing other mappings (as hierarchy or color mappings) to form acceptable by 3dBAR's parser.

_setCurrentAtlasSpace(self, spaceName)

 
Parameters:
  • spaceName (str) - Atlas Space identifier. Determines subpart of atlas for which volume is defined.
Returns:
None

Fix atlas space identifier so it can be used in further calculations. Method used internally. Better noy use it for your own.

_getOutputLabeledVolumeFilename(self)

 

Generate filename for NIfTII volume generated from raw annotation volume.

Returns: str
name of the output NiFTII volume

processVolume(self, applyPermutation=(0, 1, 2), reverseAxes=(False, False, False), dataType=<type 'numpy.uint16'>, reshapePermutation=(0, 1, 2), headerUpdate={}, qfac=1)

 

@type  applyPermutation: (int, int, int)
@param applyPermutation: Permutation of the axis' order. Use to adjust
                         image orientation. When the volume doesn't look
                         like a correct volume (I'll notice that). 

@type  reverseAxes: (Bool, Bool, Bool)
@param reverseAxes: Directives for reversing particular axis of the
                    volume. Use to change orientation within given axis
                    (iie. to change left to right side)

@type  dataType: NumPy array type
@param dataType: Data type to which values from initial volume will be
                 converted. This is a very important parameter. Be
                 carefull about that.

@type  reshapePermutation: (int, int, int)
@param reshapePermutation: Permutation of the axis' order. Use to adjust
                           image orientation

@type  headerUpdate: dict
@param headerUpdate: Custom header values that will be assigned to the
                   header. Use this dictionary to override default NiFTI
                   header fields.

@type  qfac: -1 or 1
@param qfac: Additional parameter for manipulating image orientation.
             See NiFTIi specification for details

Function for processing raw anntotation volume (raw labelled volume)
into niftii file that can be parsed in the further steps of processing.
The exac way in which the raw volume will be processed by applying
permutations, selecting particular data type or overriding default
niftii header entries.

@type: None
@return: None

_loadRawAnnotationFile(self, dataType=<type 'numpy.uint16'>, reshapePermutation=(0, 1, 2))

 
Parameters:
  • dataType (NumPy array type) - Data type to which values from initial volume will be converted. This is a very important parameter. Be carefull about that.
  • reshapePermutation ((int, int, int)) - Permutation of the axis' order. Use to adjust image orientation
Returns: numpy volume
NumPy volume created ba parsing raw annotation file.

_assignHeaderInformation(self, niftiImage, applyPermutation=(0, 1, 2), reshapePermutation=(0, 1, 2), headerDict={}, qfac=1)

 
Parameters:
  • niftiImage (NiftiImage) - Image for which header information will be assigned
  • applyPermutation ((int, int, int)) - Axis permitation with regard to default axes order. Parameter used to compute final order of axes and corresponding origin and pixel dimensions.
  • reshapePermutation ((int, int, int)) - Permutation applied to the raw binary data, just afte rreshaping. Parameter used to compute final order of axes and corresponding origin and pixel dimensions.
  • headerDict (dict) - Custom header values that will be assigned to the header.
  • qfac (-1 or 1) - Additional parameter for manipulating image orientation. See NiFTIi specification for details
Returns: None
None

_processOntology(self)

 

Extract and process structure ontology information from source dataset. 

Ontology file contains a number of lines. Each of the line consists of:
    1) Structure's abbreviated name
    2) Strucutre's parent abbreviated name
    3) Full name of the structure
    4) Ontlogy id (I don't know where the full ontology is provided)
    5) Structure's index as provided in the labelled volume
    6) RGB color arrigned to the particular structure (note the colour may be no uniqe)

@return: None

_processSingleOntologyFileLine(self, ontologyLine)

 

Helper function for processing sungle ontology file line. A single line with ontology records contains following elements:

  • Fullname, abbreviation, parent, assigned color, volume index, ontologyID
Parameters:
  • ontologyLine (str) - tab separatd line containing data with single ontology record.
Returns: (str, str)
Strings that could be appended to ontology and hierarchy string.

cleanup(self)

 

Remove atals package and extracted files of currently processed atlas. This functions is not executed automatically and has to be invoked manually.