def rbh_network(id2desc, rbh, file_name, thresholds = [False, False, False, False]):
g = nx.Graph() <EOL>filtered = {}<EOL>e_thresh, bit_thresh, length_thresh, norm_thresh = thresholds<EOL>for genome in rbh:<EOL><INDENT>filtered[genome] = {}<EOL>for other in rbh:<EOL><INDENT>if other != genome:<EOL><INDENT>filtered[genome][other] = {}<EOL><DEDENT><DEDENT><DEDENT>comparisons = []<EOL>for genome in rbh:<EOL><INDENT>for compare in rbh[genome]:<EOL><INDENT>pair = '<STR_LIT>'.join(sorted([genome, compare]))<EOL>if pair in comparisons: <EOL><INDENT>continue<EOL><DEDENT>comparisons.append(pair)<EOL>for orf in rbh[genome][compare]:<EOL><INDENT>scoresA = rbh[genome][compare][orf]<EOL>match = scoresA[<NUM_LIT:2>]<EOL>if match in rbh[compare][genome]:<EOL><INDENT>scoresB = rbh[compare][genome][match]<EOL><DEDENT>else:<EOL><INDENT>scoresB = scoresA<EOL><DEDENT>typeA, AA, BA, pidentA, lengthA, eA, bitA, norm_bitA = scoresA<EOL>typeB, AB, BB, pidentB, lengthB, eB, bitB, norm_bitB = scoresB<EOL>if norm_thresh is not False:<EOL><INDENT>if norm_bitA < norm_thresh[genome][compare]or norm_bitB < norm_thresh[compare][genome]:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>if e_thresh is not False:<EOL><INDENT>if eA > e_threshor eB > e_thresh:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>if bit_thresh is not False:<EOL><INDENT>if bitA < bit_threshor bitB < bit_thresh:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>if length_thresh is not False:<EOL><INDENT>if lengthA < length_threshor lengthB < length_thresh:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>if id2desc[orf][<NUM_LIT:2>] > id2desc[match][<NUM_LIT:2>]:<EOL><INDENT>scores = scoresA<EOL><DEDENT>elif id2desc[orf][<NUM_LIT:2>] < id2desc[match][<NUM_LIT:2>]:<EOL><INDENT>scores = scoresB<EOL><DEDENT>else:<EOL><INDENT>scores = sorted([scoresA, scoresB], key = itemgetter(-<NUM_LIT:1>), reverse = True)[<NUM_LIT:0>]<EOL><DEDENT>type, A, B, pident, length, e, bit, norm_bit = scores<EOL>g.add_edge(A, B, match_type = type, length_fraction = length,percent_id = pident, e_value = e, bit_score = bit, norm_bit = norm_bit)<EOL>filtered[genome][compare][orf] = scoresA<EOL>filtered[compare][genome][match] = scoresB<EOL><DEDENT><DEDENT><DEDENT>missing = set([i for i in id2desc]).difference(set([i for i in g]))<EOL>for orf in missing:<EOL><INDENT>g.add_edge(orf, orf, percent_id = <NUM_LIT:0>, e_value = <NUM_LIT:0>, bit_score = <NUM_LIT:0>, norm_bit = <NUM_LIT:0>,length_fraction = <NUM_LIT:0>)<EOL><DEDENT>nx.write_edgelist(g, file_name, delimiter = '<STR_LIT:\t>', data = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'])<EOL>return g, filtered<EOL>
make the network based on rbhs and score thresholds