writes contents of stats to outname_stats.csv
    :param stats: {'num_of_queries' : [(auc, auclow, auchigh),(fpf, ef, eflow, efhigh),(fpf, ef, eflow, efhigh),...,]}
    if fw_type is not None, stats has the form given below
    {'num_of_queries' : [(auc, auclow, auchigh), (fpf, ef, eflow, efhigh), (fpf, acd), ...,], }
    :param options: postanalyze.SplitInput object

def write_summary(stats, options, fw_type = None):
    """
    writes contents of stats to outname_stats.csv
    :param stats: {'num_of_queries' : [(auc, auclow, auchigh),(fpf, ef, eflow, efhigh),(fpf, ef, eflow, efhigh),...,]}
    if fw_type is not None, stats has the form given below
    {'num_of_queries' : [(auc, auclow, auchigh), (fpf, ef, eflow, efhigh), (fpf, acd), ...,], }
    :param options: postanalyze.SplitInput object
    """

    # set output file name
    out_name = '%s_stats.csv' % options.outname
    filename = os.path.join(os.getcwd(), out_name)

    # open file & create csv writer object
    f = open(filename, 'w')
    stats_writer = csv.writer(f)

    # sort the stats keys using the "decorate, sort, un decorate method"
    decorated = [(x, int(re.search(r'_([0-9]|[0-9][0-9]|[0-9][0-9][0-9])_queries.csv$', x, re.M).group().split('_')[1]))
                 for x in stats.keys() if '_queries.csv' in x]
    decorated.sort(key=lambda element: element[1])
    sorted_stats_keys = [x[0] for x in decorated]

    for leftovers in [x for x in stats.keys() if '_queries.csv' not in x]:
        sorted_stats_keys.append(leftovers)

    for ensemble in sorted_stats_keys:
        # write header & first line
        if f.tell() == 0:
            header = ['Ensemble name', 'AUC', '95% CI']
            line = ['%s' % ensemble]
            for metric_tup in stats[ensemble]:
                if len(metric_tup) == 3:
                    line.append('%0.4f' % metric_tup[0])
                    line.append('[%0.2f, %0.2f]' % (metric_tup[1], metric_tup[2]))
                if len(metric_tup) == 4:
                    header.append('E%s' % metric_tup[0])
                    header.append('95% CI')
                    line.append('%0.2f' % metric_tup[1])
                    line.append('[%0.2f, %0.2f]' % (metric_tup[2], metric_tup[3]))
            stats_writer.writerow(header)
            stats_writer.writerow(line)
        # write remaining lines
        else:
            line = ['%s' % ensemble]
            for metric_tup in stats[ensemble]:
                if len(metric_tup) == 3:
                    line.append('%0.4f' % metric_tup[0])
                    line.append('[%0.2f, %0.2f]' % (metric_tup[1], metric_tup[2]))
                if len(metric_tup) == 4:
                    line.append('%0.4f' % metric_tup[1])
                    line.append('[%0.2f, %0.2f]' % (metric_tup[2], metric_tup[3]))
            stats_writer.writerow(line)

    # write maximum values
    line = ['max values:']
    for metric_tup in stats[list(stats.keys())[0]]:
        if len(metric_tup) == 3:
            line.append('1.00') # auc
            line.append(' ') # CI space
        if len(metric_tup) == 4:
            line.append('%0.2f' % (1 / metric_tup[0])) # max ef
            line.append(' ') # CI space
    stats_writer.writerow(line)

    # close file
    f.close()