Class-wise averaged metrics

        Returns
        -------
        dict
            results in a dictionary format
337989
def results_class_wise_average_metrics(self):
        

        class_wise_results = self.results_class_wise_metrics()

        class_wise_eer = []
        class_wise_fmeasure = []
        class_wise_precision = []
        class_wise_recall = []

        for class_label in class_wise_results:
            if class_wise_results[class_label]['eer']['eer'] is not None:
                class_wise_eer.append(class_wise_results[class_label]['eer']['eer'])

            if class_wise_results[class_label]['f_measure']['f_measure'] is not None:
                class_wise_fmeasure.append(class_wise_results[class_label]['f_measure']['f_measure'])
                class_wise_precision.append(class_wise_results[class_label]['f_measure']['precision'])
                class_wise_recall.append(class_wise_results[class_label]['f_measure']['recall'])

        if class_wise_eer:
            eer = float(numpy.nanmean(class_wise_eer))

        else:
            eer = None

        if class_wise_fmeasure:
            f_measure = float(numpy.nanmean(class_wise_fmeasure))

        else:
            f_measure = None

        if class_wise_precision:
            precision = float(numpy.nanmean(class_wise_precision))

        else:
            precision = None

        if class_wise_recall:
            recall = float(numpy.nanmean(class_wise_recall))

        else:
            recall = None

        return {
            'eer': {
                'eer': eer
            },
            'f_measure': {
                'f_measure': f_measure,
                'precision': precision,
                'recall': recall,
            }
        }
279548
def results_class_wise_metrics(self):
        

        results = {}
        for tag_id, tag_label in enumerate(self.tag_label_list):
            if tag_label not in results:
                results[tag_label] = {}

            # Counts
            results[tag_label]['count'] = {
                'Nref': self.tag_wise[tag_label]['Nref'],
                'Nsys': self.tag_wise[tag_label]['Nsys'],
                'Ntp': self.tag_wise[tag_label]['Ntp'],
                'Ntn': self.tag_wise[tag_label]['Ntn'],
                'Nfp': self.tag_wise[tag_label]['Nfp'],
                'Nfn': self.tag_wise[tag_label]['Nfn'],
            }

            # Equal error rate
            if self.y_pred_score[tag_label]:
                results[tag_label]['eer'] = {
                    'eer': metric.equal_error_rate(
                        y_true=self.y_true[tag_label],
                        y_score=self.y_pred_score[tag_label]
                    )
                }

            else:
                results[tag_label]['eer'] = {
                    'eer': None
                }

            # F-measure
            if self.tag_wise[tag_label]['Nref'] > 0:

                precision = metric.precision(
                    Ntp=self.tag_wise[tag_label]['Ntp'],
                    Nsys=self.tag_wise[tag_label]['Nsys']
                )

                recall = metric.recall(
                    Ntp=self.tag_wise[tag_label]['Ntp'],
                    Nref=self.tag_wise[tag_label]['Nref']
                )

                f_measure = metric.f_measure(precision=precision, recall=recall)

            else:
                precision = None
                recall = None
                f_measure = None

            results[tag_label]['f_measure'] = {
                'f_measure': f_measure,
                'precision': precision,
                'recall': recall,
            }

        return results
651907
def to_dict(self):
        
        final_res = {
            "param": self._param,
            "unused_param": self.unused_param,
            "execution_time": self._exec_time,
            "output": {"accuracy": self.get_accuracy(),
                       "weights": self.get_weights(),
                       "splines": self._splines
                       }
        }
        return final_res
574453
def as_dict(self):
        
        return {"@module": self.__class__.__module__,
                "@class": self.__class__.__name__,
                "frequencies": list(self.frequencies),
                "densities": list(self.densities)}
865251
def statistics(cls, function, group=None):
        
        benchmark = cls.results(function, group)
        results = {}
        for name, stat in {'avg': numpy.average, 'max': numpy.amax, 'med': numpy.median, 'min': numpy.amin, 'sum': numpy.sum}.items():
            results[name] = stat(benchmark, axis=0)
        return results
330707
def as_dict(self, verbosity: int = 0) -> Dict:
        ""

        d = {
            "@module": self.__class__.__module__,
            "@class": self.__class__.__name__,
            "matrix": self._matrix.tolist(),
        }
        (a, b, c), (alpha, beta, gamma) = self.lengths_and_angles
        if verbosity > 0:
            d.update(
                {
                    "a": a,
                    "b": b,
                    "c": c,
                    "alpha": alpha,
                    "beta": beta,
                    "gamma": gamma,
                    "volume": self.volume,
                }
            )

        return d
766090
def parse_qcmetrics(metrics: dict) -> dict:
    
    data = {
        'versions': {
            'freebayes': metrics['program']['freebayes']['version'],
            'gatk': metrics['program']['gatk']['version'],
            'manta': metrics['program'].get('manta', {}).get('version'),
            'bcftools': metrics['program']['bcftools']['version'],
            'vep': metrics['program']['varianteffectpredictor']['version'],
        },
        'samples': [],
    }

    plink_samples = {}
    plink_sexcheck = metrics['program'].get('plink_sexcheck', {}).get('sample_sexcheck')
    if isinstance(plink_sexcheck, str):
        sample_id, sex_number = plink_sexcheck.strip().split(':', 1)
        plink_samples[sample_id] = PED_SEX_MAP.get(int(sex_number))
    elif isinstance(plink_sexcheck, list):
        for sample_raw in plink_sexcheck:
            sample_id, sex_number = sample_raw.split(':', 1)
            plink_samples[sample_id] = PED_SEX_MAP.get(int(sex_number))

    for sample_id, sample_metrics in metrics['sample'].items():

        ## Bam stats metrics
        bam_stats = [values['bamstats'] for key, values in sample_metrics.items()
                     if key[:-1].endswith('.lane')]
        total_reads = sum(int(bam_stat['raw_total_sequences']) for bam_stat in bam_stats)
        total_mapped = sum(int(bam_stat['reads_mapped']) for bam_stat in bam_stats)

        ## Picard metrics
        main_key = [key for key in sample_metrics.keys() if '_lanes_' in key][0]

        hs_metrics = sample_metrics[main_key]['collecthsmetrics']['header']['data']
        multiple_inst_metrics = sample_metrics[main_key]['collectmultiplemetricsinsertsize']['header']['data']
        multiple_metrics = sample_metrics[main_key]['collectmultiplemetrics']['header']['pair']

        sample_data = {
            'at_dropout': hs_metrics['AT_DROPOUT'],
            'completeness_target': {
                10: hs_metrics['PCT_TARGET_BASES_10X'],
                20: hs_metrics['PCT_TARGET_BASES_20X'],
                50: hs_metrics['PCT_TARGET_BASES_50X'],
                100: hs_metrics['PCT_TARGET_BASES_100X'],
            },
            'duplicates': float(sample_metrics[main_key]['markduplicates']['fraction_duplicates']),
            'gc_dropout': hs_metrics['GC_DROPOUT'],
            'id': sample_id,
            'median_insert_size':  multiple_inst_metrics['MEDIAN_INSERT_SIZE'],
            'mapped': total_mapped / total_reads,
            'plink_sex': plink_samples.get(sample_id),
            'predicted_sex': sample_metrics[main_key]['chanjo_sexcheck']['gender'],
            'reads': total_reads,
            'insert_size_standard_deviation': float(multiple_inst_metrics['STANDARD_DEVIATION']),
            'strand_balance': float(multiple_metrics['STRAND_BALANCE']),
            'target_coverage': float(hs_metrics['MEAN_TARGET_COVERAGE']),
        }
        data['samples'].append(sample_data)
    return data
1114420
def generate_flattened_dict(headers, results):
    ''''''
    for name, values in results.items():
        row = []
        for header in headers:
            if header == 'name':
                row.append(name)
            elif ':' in header:
                neurite_type, metric = header.split(':')
                row.append(values[neurite_type][metric])
            else:
                row.append(values[header])
        yield row
828103
def dict(self):
        
        return {k: getattr(self, k) for k in self.__class__.defaults}
977248
def _metric_alarm_to_dict(alarm):
    '''
    
    '''
    d = odict.OrderedDict()
    fields = ['name', 'metric', 'namespace', 'statistic', 'comparison',
              'threshold', 'period', 'evaluation_periods', 'unit',
              'description', 'dimensions', 'alarm_actions',
              'insufficient_data_actions', 'ok_actions']
    for f in fields:
        if hasattr(alarm, f):
            d[f] = getattr(alarm, f)
    return d
1299649
def _score_macro_average(self, n_classes):
        
        # Gather all FPRs
        all_fpr = np.unique(np.concatenate([self.fpr[i] for i in range(n_classes)]))
        avg_tpr = np.zeros_like(all_fpr)

        # Compute the averages per class
        for i in range(n_classes):
            avg_tpr += interp(all_fpr, self.fpr[i], self.tpr[i])

        # Finalize the average
        avg_tpr /= n_classes

        # Store the macro averages
        self.fpr[MACRO] = all_fpr
        self.tpr[MACRO] = avg_tpr
        self.roc_auc[MACRO] = auc(self.fpr[MACRO], self.tpr[MACRO])
946965
def _to_dict(self):
        """"""
        _dict = {}
        if hasattr(self, 'feedback') and self.feedback is not None:
            _dict['feedback'] = [x._to_dict() for x in self.feedback]
        return _dict
263958
def get_average(self, name=None):
        '''
        '''
        return self.get_client(name=name, class_=statsd.Average)
26650
def _to_dict(self):
        """"""
        _dict = {}
        if hasattr(self, 'confidence') and self.confidence is not None:
            _dict['confidence'] = self.confidence
        if hasattr(self, 'class_name') and self.class_name is not None:
            _dict['class_name'] = self.class_name
        return _dict
194566
def to_dict(self):
        
        return {
            'mean': self.mean,
            'var': self.var,
            'min': self.min,
            'max': self.max,
            'num': self.num
        }
1179284
def as_dict(self):
        
        return {"@module": self.__class__.__module__,
                "@class": self.__class__.__name__,
                "coord_geoms": jsanitize(self.coord_geoms)}
1296557
def _iostats_dict(header, stats):
    '''
    
    '''
    stats = [float((sum(stat) / len(stat)).quantize(decimal.Decimal('.01'))) for stat in zip(*stats)]
    stats = dict(zip(header, stats))
    return stats