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

Class barSBAParser


Generic class for translating data from ScalableBrainAtlas to CAF dataset. This class should be subclassed for each template available on SBA website and customized according to template-specific features.

Instance Methods [hide private]
 
__init__(self, **kwargs)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
barTracedSlideRenderer
parse(self, slideNumber, generateLabels=True, useIndexer=True, writeSlide=True)
Returns: Traced slide with given slideNumber.
 
_parseSingleStructure(self, structureIDbyFill, structurePathList)
Returns: None
 
_getPathID(self, structName)
Returns: (string) ID of path with given name.
 
_getStructureName(self, structureIDbyFill)
Returns: (string) name of the structure corresponding to gocen fill color.
 
_cleanStructName(self, structName)
An alias to cleanStructName(structName).
 
_saveTransformationAsMetadata(self, transformation, bregma)
 
_loadjsonfiles(self)
Returns: None
 
_calculatescaling(self)
function calculates coefficients of transformation matrix basing on config.json file provided by scalablebrainatlas template.
 
_putscalings(self, (a, b, c, d))
Returns: none

Inherited from parsers.barGenericParser: RGBToHTMLColor, getProperty, parseAll, parseRange, reindex, setProperty, writeIndex

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
list _requiredInternalData = ['outputDirectory', 'filenameTemplates...
Required instance attributtes.
Instance Variables [hide private]

Inherited from parsers.barGenericParser: filenameTemplates, outputDirectory, renderingProperties, slideRange, tracingProperties

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, **kwargs)
(Constructor)

 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Overrides: object.__init__
(inherited documentation)

parse(self, slideNumber, generateLabels=True, useIndexer=True, writeSlide=True)

 
Parameters:
  • slideNumber (Number of slide which will be parsed

    Creates svg document from JSON file for given slide number. Slide is created using following workflow:

    • Get template of empty slide
    • Get list of structures in given slide
    • Extract definitions of paths corresponding to structures, add them into slide
    • Extract metadata and put in into SVG slide
    • Generate positions of labels corresponding to created paths and append therm
    ) - int
Returns: barTracedSlideRenderer
Traced slide with given slideNumber.

Performs all operation related to creating CAF slide from souce data. Should be customized in each parser.

Overrides: parsers.barGenericParser.parse

_parseSingleStructure(self, structureIDbyFill, structurePathList)

 
Parameters:
  • structureIDbyFill (string) - color-encoded structure ID which will be processed
  • structurePathList (list) - list of path corresponding to given structure on given slide
Returns:
None

Function extracts all paths from given slide having filled with 'structureIDbyFill' color. At the end of processing, path is appended to the slide.

To Do: # TODO: Arrange code in each function to make it more reusable

_getPathID(self, structName)

 
Returns:
(string) ID of path with given name. Uniqness if ID is guaranteed by internal index.

_getStructureName(self, structureIDbyFill)

 
Parameters:
  • structureIDbyFill (string) - color-encoded structure name to be decoded
Returns:
(string) name of the structure corresponding to gocen fill color.

Function translates fill color to structure name (structure abbreviation to be precise). Fill and name are in 1:1 relation (each fill color is uniqe).

_saveTransformationAsMetadata(self, transformation, bregma)

 
Parameters:
  • transformation (4 elements array) - array holding transformation coefficients in following orader: [b,a,d,c]. x'=a*x+b, y'=c*y+d
  • bregma (string) - bregma coordinate

    Puts stereotactic coordinates matrix as SVG metadata

    Clues given by Rembrand Bakker: x'=xy[0]+xy[1]*x y'=xy[0]+xy[1]*y

_loadjsonfiles(self)

 
Returns:
None

Downloads data from ScalableBrainAtas website (precise location of the data is located in configuration files) and stores it in internal dictionary. Function assumes that all data is available and there is no connection issues.

_calculatescaling(self)

 

function calculates coefficients of transformation matrix basing on config.json file provided by scalablebrainatlas template.

folowing fomulas are used to calculate mentioned coefficients:

x' = sx/w*x +b y' =-sy/h*y +d

b = xl - l/w *sx d = yl + (1+t/h)*sy

sx - span in x plane in real coordinates; sy - span along y axis in real coordinates; l - point xl on x axis in svg coordinates t - point yl on y axis in svg coordinates

Returns:
(tuple of 4 floats) coefficients of transformation from svg drawing to real (?? stereotactic) coordinates.

_putscalings(self, (a, b, c, d))

 
Parameters:
  • coefs (tuple of four floats) - coefficients of transformation from svg to real coordinates
Returns:
none

fills constants predefined in config.py files. initial values in this file may not be defined correctly of may be outdated. after downloading json files some constants needs to be recalculated. those constants are xyscaling and alignerreferencecoords.


Class Variable Details [hide private]

_requiredInternalData

Required instance attributtes. Without prividing them parsing cannot be invoked. Meaning of each attribute is explained below.
Type:
list
Value:
['outputDirectory',
 'filenameTemplates',
 'slideRange',
 'tracingProperties',
 'renderingProperties',
 'renderingProperties',
 'templateName',
 'tracingProperties',
...