jacquard/utils/summarize_zscore_transform.py
def _init_population_stats(self, vcf_reader, dependent_tag_id):
        '''Derive mean and stdev.

        Adapted from online variance algorithm from Knuth, The Art of Computer 
        Programming, volume 2

        Returns: mean and stdev when len(values) > 1, otherwise (None, None)
            Values rounded to _MAX_PRECISION to ameliorate discrepancies between
            python versions.'''
        #pylint: disable=invalid-name
        n = 0
        mean = 0
        M2 = 0
        try:
            vcf_reader.open()
            for vcf_record in vcf_reader.vcf_records():
                for tag_values in vcf_record.sample_tag_values.values():
                    value = self._get_dependent_value(tag_values,
                                                      dependent_tag_id)
                    if value is not None:
                        n += 1
                        delta = value - mean
                        mean += delta / n
                        M2 += delta * (value - mean)
        finally:
            vcf_reader.close()

        mean = round(mean, self._MAX_PRECISION)

        stdev = 0
        if n == 0:
            mean = None
            stdev = None
        elif n >= 2:
            variance = M2/n
            stdev = round(math.sqrt(variance), self._MAX_PRECISION)

        return mean, stdev
def _init_population_stats(self, vcf_reader, dependent_tag_id):
        '''Derive mean and stdev.

        Adapted from online variance algorithm from Knuth, The Art of Computer 
        Programming, volume 2

        Returns: mean and stdev when len(values) > 1, otherwise (None, None)
            Values rounded to _MAX_PRECISION to ameliorate discrepancies between
            python versions.'''
        #pylint: disable=invalid-name
        n = 0
        mean = 0
        M2 = 0
        try:
            vcf_reader.open()
            for vcf_record in vcf_reader.vcf_records():
                for tag_values in vcf_record.sample_tag_values.values():
                    value = self._get_dependent_value(tag_values,
                                                      dependent_tag_id)
                    if value is not None:
                        n += 1
                        delta = value - mean
                        mean += delta / n
                        M2 += delta * (value - mean)
        finally:
            vcf_reader.close()

        mean = round(mean, self._MAX_PRECISION)

        stdev = 0
        if n == 0:
            mean = None
            stdev = None
        elif n >= 2:
            variance = M2/n
            stdev = round(math.sqrt(variance), self._MAX_PRECISION)

        return mean, stdev
def _init_population_stats ( self , vcf_reader , dependent_tag_id ) : #pylint: disable=invalid-name n = 0 mean = 0 M2 = 0 try : vcf_reader . open ( ) for vcf_record in vcf_reader . vcf_records ( ) : for tag_values in vcf_record . sample_tag_values . values ( ) : value = self . _get_dependent_value ( tag_values , dependent_tag_id ) if value is not None : n += 1 delta = value - mean mean += delta / n M2 += delta * ( value - mean ) finally : vcf_reader . close ( ) mean = round ( mean , self . _MAX_PRECISION ) stdev = 0 if n == 0 : mean = None stdev = None elif n >= 2 : variance = M2 / n stdev = round ( math . sqrt ( variance ) , self . _MAX_PRECISION ) return mean , stdev
Derive mean and stdev.

        Adapted from online variance algorithm from Knuth, The Art of Computer 
        Programming, volume 2

        Returns: mean and stdev when len(values) > 1, otherwise (None, None)
            Values rounded to _MAX_PRECISION to ameliorate discrepancies between
            python versions.
Derive mean and stdev .