text stringlengths 1 93.6k |
|---|
[sorted(G.out_edges(y[0])) == sorted([(y[0],x) for x in y[1]])
|
for y in parentage_tuple_list])
|
return explicit_child_condition
|
def create_no_direct_arrows_condition(node_pair_list):
|
def no_direct_arrows_condition(G):
|
return not(any([y in G.edges() for y in node_pair_list]))
|
return no_direct_arrows_condition
|
def create_no_output_node_condition(node_list):
|
def no_output_node_condition(G):
|
return all([G.out_degree(y)==0 for y in node_list])
|
return no_output_node_condition
|
def extract_remove_self_loops_filter():
|
def remove_self_loops_filter(G):
|
graph = G.copy()
|
graph.remove_edges_from(graph.selfloop_edges()) #this is a networkX method that allows you to automatically grab edges that are self-loops.
|
return graph
|
return remove_self_loops_filter
|
def extract_remove_inward_edges_filter(exceptions_from_removal):
|
"""
|
This covers both orphans and explicit_child_parentage.
|
"""
|
def remove_inward_edges_filter(G):
|
graph = G.copy()
|
list_of_children = [x[0] for x in exceptions_from_removal if len(x[1]) > 0]
|
list_of_orphans = [x[0] for x in exceptions_from_removal if len(x[1]) == 0]
|
for orphan in list_of_orphans:
|
graph.remove_edges_from([edge for edge in graph.edges() if edge[1] == orphan])
|
for child in list_of_children:
|
current_edges = graph.in_edges(child)
|
valid_edges = [(y,x[0]) for x in exceptions_from_removal if x[0] == child for y in x[1]]
|
graph.remove_edges_from([edge for edge in current_edges if edge not in valid_edges])
|
return graph
|
return remove_inward_edges_filter
|
def extract_remove_outward_edges_filter(exceptions_from_removal):
|
"""
|
This creates a closure that goes through the list of tuples to explicitly state which edges are leaving from the first argument of each tuple.
|
Each tuple that is passed in has two members. The first member is a string representing a single node from which the children will be explicitly stated. The second member is the list of nodes that are in its child set.
|
If the
|
This covers both barren_nodes and explicit_parent_offspring.
|
"""
|
def remove_outward_edges_filter(G):
|
graph = G.copy()
|
list_of_parents = [x[0] for x in exceptions_from_removal if len(x[1]) > 0]
|
list_of_barrens = [x[0] for x in exceptions_from_removal if len(x[1]) == 0]
|
for barren in list_of_barrens:
|
graph.remove_edges_from([edge for edge in graph.edges() if edge[0] == barren])
|
for parent in list_of_parents:
|
current_edges = graph.out_edges(parent)
|
valid_edges = [(x[0],y) for x in exceptions_from_removal if x[0] == parent for y in x[1]]
|
graph.remove_edges_from([edge for edge in current_edges if edge not in valid_edges])
|
return graph
|
return remove_outward_edges_filter
|
def barren_nodes_filter(list_of_barren_nodes):
|
"""
|
This allows for a nicer syntax for specifying that nodes are barren (that they have no children).
|
"""
|
new_list = [(node,[]) for node in list_of_barren_nodes]
|
return extract_remove_outward_edges_filter(new_list)
|
def orphan_nodes_filter(list_of_orphan_nodes):
|
"""
|
This allows for a nicer syntax for specifying that nodes are orphans (that they have no parents).
|
"""
|
new_list = [(node,[]) for node in list_of_orphan_nodes]
|
return extract_remove_inward_edges_filter(new_list)
|
def new_conditional_graph_set(graph_set,condition_list):
|
"""
|
This returns a copy of the old graph_set and a new graph generator which has
|
the conditions in condition_list applied to it.
|
Warning: This function will devour the iterator that you include as the graph_set input,
|
you need to redeclare the variable as one of the return values of the function.
|
Thus a correct use would be:
|
a,b = new_conditional_graph_set(a,c)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.