def calc_thresholds(rbh, file_name, thresholds = [False, False, False, False], stdevs = 2):
    calc_threshold = thresholds[-1]
    norm_threshold = {}
    for pair in itertools.permutations([i for i in rbh], 2):
        if pair[0] not in norm_threshold:
            norm_threshold[pair[0]] = {}
        norm_threshold[pair[0]][pair[1]] = {}
    out = open(file_name, 'w')
    print('
    comparisons = []
    for genome in rbh:
        for compare in rbh[genome]:
            pair = ''.join(sorted([genome, compare]))
            if pair in comparisons:
                continue
            comparisons.append(pair)
            scores = {'percent identity': [], 'e-value': [], 'bit score': [], 'normalized bit score': [], 'alignment length fraction': []}
            print('
            for id in rbh[genome][compare]:
                pident, length_fraction, e, bit, norm_bit = rbh[genome][compare][id][3:]
                scores['percent identity'].append(pident)
                scores['alignment length fraction'].append(length_fraction)
                scores['e-value'].append(e)
                scores['bit score'].append(bit)
                scores['normalized bit score'].append(norm_bit)
            if calc_threshold is True:
                norms = scores['normalized bit score']
                average = numpy.average(norms) 
                std = numpy.std(norms)
                normal_thresh = average - (std * stdevs)
                print('
                print('
                print('
                norm_threshold[genome][compare], norm_threshold[compare][genome] = normal_thresh, normal_thresh
            for score in scores:
                print('
                if len(scores[score]) > 0:
                    print('
                print('', file=out)
    out.close()
    if calc_threshold is True:
        return thresholds[0:-1] + [norm_threshold]
    else:
        return thresholds