import networkx


def BuildGraph(aligned, cutoff, coverage_req=0):
    """Takes the BLAST output and represents it as a graph using the following rules:
        Each sequence is represented as a node.
        Each alignment between sequences is represented as an unweighted,
        undirected edge."""
    #hold=set()
    #hold2=set()
    graph=networkx.Graph()
    for pair in aligned.keys():
        query,subject=pair
        if graph.has_node(subject)==False:
            graph.add_node(subject)
        if graph.has_node(query)==False:
            graph.add_node(query)
        if aligned[pair].identity>=cutoff and aligned[pair].covs>coverage_req: #aligned[pair].length>100:
            graph.add_edge(subject, query)

    return graph