def compare_genomes(fastas, id2desc, algorithm):
    """
    make all pairwise genome comparisons to get rbhs
    rbh = {genome: {other_genome: {rbh_id: [rbh_match, pident, e, bit, norm_bit]]}}
    """
    hits = {}
    for pair in itertools.permutations(fastas, 2):
        if pair[0] not in hits:
            hits[pair[0]] = {}
        hits[pair[0]][pair[1]] = {}
    for pair in itertools.combinations(fastas, 2):
        A, B = pair
        blastF = open(search(A, B, method = algorithm, alignment = 'local'))
        blastR = open(search(B, A, method = algorithm, alignment = 'local'))
        for compare in [A, B, blastF], [B, A, blastR]:
            query, ref, blast = compare
            for hit in best_blast(blast, 1):
                a, b, pident, qstart, qend, e, bit = \
                        hit[0].split()[0], hit[1].split()[0], float(hit[2]), float(hit[6]), float(hit[7]), float(hit[-2]), float(hit[-1])
                alignment_length = abs(qstart - qend + 1)
                norm_bit = normalize_bit(a, b, bit, id2desc)
                length_fraction = float((alignment_length) / id2desc[a][2])
                hits[query][ref][a] = ['fbh', a, b, pident, length_fraction, e, bit, norm_bit]
    return hits
def compare_genomes ( fastas , id2desc , algorithm ) : hits = { } for pair in itertools . permutations ( fastas , 2 ) : if pair [ 0 ] not in hits : hits [ pair [ 0 ] ] = { } hits [ pair [ 0 ] ] [ pair [ 1 ] ] = { } for pair in itertools . combinations ( fastas , 2 ) : A , B = pair blastF = open ( search ( A , B , method = algorithm , alignment = 'local' ) ) blastR = open ( search ( B , A , method = algorithm , alignment = 'local' ) ) for compare in [ A , B , blastF ] , [ B , A , blastR ] : query , ref , blast = compare for hit in best_blast ( blast , 1 ) : a , b , pident , qstart , qend , e , bit = hit [ 0 ] . split ( ) [ 0 ] , hit [ 1 ] . split ( ) [ 0 ] , float ( hit [ 2 ] ) , float ( hit [ 6 ] ) , float ( hit [ 7 ] ) , float ( hit [ - 2 ] ) , float ( hit [ - 1 ] ) alignment_length = abs ( qstart - qend + 1 ) norm_bit = normalize_bit ( a , b , bit , id2desc ) length_fraction = float ( ( alignment_length ) / id2desc [ a ] [ 2 ] ) hits [ query ] [ ref ] [ a ] = [ 'fbh' , a , b , pident , length_fraction , e , bit , norm_bit ] return hits
make all pairwise genome comparisons to get rbhs
    rbh = {genome: {other_genome: {rbh_id: [rbh_match, pident, e, bit, norm_bit]]}}