Parameters
        ----------

        interval : object
            Object with chrom (str), start (int) and stop (int) attributes.

        bins : int or None
            Number of bins; if None, bins will be the length of the interval

        method : summarize | ucsc_summarize | get_as_array
            "summarize" and "get_as_array" use bx-python; "ucsc_summarize" uses
            bigWigSummarize. See other notes in docstring for
            metaseq.array_helpers._local_coverage. If None, defaults to
            "summarize".

        function : mean | min | max | std | coverage
            Determines the nature of the summarized values. Ignored if
            `method="get_as_array"`; "coverage" is only valid if method is
            "ucsc_summarize".

        zero_inf, zero_nan : bool
            If `zero_inf` is True, set any inf or -inf to zero before
            returning. If `zero_nan` is True, set any nan values to zero before
            returning.

def summarize(self, interval, bins=None, method='summarize',
                  function='mean', zero_inf=True, zero_nan=True):
        """
        Parameters
        ----------

        interval : object
            Object with chrom (str), start (int) and stop (int) attributes.

        bins : int or None
            Number of bins; if None, bins will be the length of the interval

        method : summarize | ucsc_summarize | get_as_array
            "summarize" and "get_as_array" use bx-python; "ucsc_summarize" uses
            bigWigSummarize. See other notes in docstring for
            metaseq.array_helpers._local_coverage. If None, defaults to
            "summarize".

        function : mean | min | max | std | coverage
            Determines the nature of the summarized values. Ignored if
            `method="get_as_array"`; "coverage" is only valid if method is
            "ucsc_summarize".

        zero_inf, zero_nan : bool
            If `zero_inf` is True, set any inf or -inf to zero before
            returning. If `zero_nan` is True, set any nan values to zero before
            returning.
        """

        if method is None:
            method = 'summarize'

        # We may be dividing by zero in some cases, which raises a warning in
        # NumPy based on the IEEE 754 standard (see
        # http://docs.scipy.org/doc/numpy/reference/generated/
        #       numpy.seterr.html)
        #
        # That's OK -- we're expecting that to happen sometimes. So temporarily
        # disable this error reporting for the duration of this method.
        orig = np.geterr()['invalid']
        np.seterr(invalid='ignore')

        if (bins is None) or (method == 'get_as_array'):
            bw = BigWigFile(open(self.fn))
            s = bw.get_as_array(
                interval.chrom,
                interval.start,
                interval.stop,)
            if s is None:
                s = np.zeros((interval.stop - interval.start,))
            else:
                if zero_nan:
                    s[np.isnan(s)] = 0
                if zero_inf:
                    s[np.isinf(s)] = 0

        elif method == 'ucsc_summarize':
            if function in ['mean', 'min', 'max', 'std', 'coverage']:
                return self.ucsc_summarize(interval, bins, function=function)
            else:
                raise ValueError('function "%s" not supported by UCSC\'s'
                                 'bigWigSummary')

        elif method == 'summarize':
            bw = BigWigFile(open(self.fn))
            s = bw.summarize(
                interval.chrom,
                interval.start,
                interval.stop, bins)
            if s is None:
                s = np.zeros((bins,))
            else:
                if function == 'sum':
                    s = s.sum_data
                elif function == 'mean':
                    s = s.sum_data / s.valid_count
                    if zero_nan:
                        s[np.isnan(s)] = 0
                elif function == 'min':
                    s = s.min_val
                    if zero_inf:
                        s[np.isinf(s)] = 0
                elif function == 'max':
                    s = s.max_val
                    if zero_inf:
                        s[np.isinf(s)] = 0
                elif function == 'std':
                    s = (s.sum_squares / s.valid_count)
                    if zero_nan:
                        s[np.isnan(s)] = 0
                else:
                    raise ValueError(
                            'function "%s" not supported by bx-python'
                            % function
                    )
        else:
            raise ValueError("method '%s' not in [summarize, ucsc_summarize, get_as_array]" % method)

        # Reset NumPy error reporting
        np.seterr(divide=orig)
        return s