Ejemplo n.º 1
0
 def _calcStatisticsInExtraPass(self):
     if not self._hasCalculatedStats:
         prevPrintWarnings = self._geSource.getPrintWarnings()
         self._geSource.setPrintWarnings(False)
         
         for el in self._geSource:
             chr = el.chr
             self._numElements[chr] += 1
             
             if el.isBlankElement:
                 continue
             
             if self._areValsCategorical:
                 self._valCategories.add(el.val)
                 
             if self._areEdgeWeightsCategorical:
                 self._edgeWeightCategories |= set(el.weights)
         
             for prefix in self._maxStrLens[chr]:
                 content = getattr(el, prefix, None)
                 
                 if content is not None:
                     self._maxStrLens[chr][prefix] = \
                             max( self._maxStrLens[chr][prefix], \
                                  max(1, len(content)) if isinstance(content, basestring) else \
                                     max([1] + [len(x) for x in flatten(content)]) )
                     
                     if prefix == 'edges':
                         self._maxNumEdges[chr] = max(self._maxNumEdges[chr], len(el.edges))
                     
         self._geSource.setPrintWarnings(prevPrintWarnings)
         self._hasCalculatedStats = True
Ejemplo n.º 2
0
    def _calcStatisticsInExtraPass(self):
        if not self._hasCalculatedStats:
            prevPrintWarnings = self._geSource.getPrintWarnings()
            self._geSource.setPrintWarnings(False)

            if self._geSource.isSliceSource():
                if len(self._getMaxStrLensKeys()):
                    raise NotImplementedError('Dimension calculation not yet implemented for slice-based GenomeElementSources.')

                prefixList = self._geSource.getPrefixList()
                for el in self._geSource:
                    chr = el.chr
                    self._numElements[chr] += len(getattr(el, prefixList[0]))
            else:
                for el in self._geSource:
                    chr = el.chr
                    self._numElements[chr] += 1

                    if el.isBlankElement:
                        continue

                    if self._areValsCategorical:
                        self._valCategories.add(el.val)

                    if self._areEdgeWeightsCategorical:
                        self._edgeWeightCategories |= set(el.weights)

                    for prefix in self._maxStrLens[chr]:
                        content = getattr(el, prefix, None)

                        if content is not None:
                            self._maxStrLens[chr][prefix] = \
                                    max( self._maxStrLens[chr][prefix], \
                                         max(1, len(content)) if isinstance(content, basestring) else \
                                            max([1] + [len(x) for x in flatten(content)]) )

                            if prefix == 'edges':
                                self._maxNumEdges[chr] = max(self._maxNumEdges[chr], len(el.edges))

            self._geSource.setPrintWarnings(prevPrintWarnings)
            self._hasCalculatedStats = True