def new_draw(self): """ draw the ARN using the class attributes Args: nothing Returns: a local generated web page """ got_net = Network(height="750px", width="100%", bgcolor="#222222", font_color="white") got_net.heading = "Nucleotids" # set the physics layout of the network got_net.barnes_hut() cp = 0 for nuk in self.list_nucleotide: for tuples in nuk.tup: if tuples.relation in self.grps.keys(): relation_type = self.grps.get(tuples.relation) else: relation_type = 0 relation_type = str(nuk.paired_type) got_net.add_node(tuples.tup[0], label="(" + str(tuples.tup[0]) + ")" + " -> " + str(tuples.tup[1]) + " : " + str(relation_type), group=relation_type) got_net.add_node(tuples.tup[1], label="(" + str(tuples.tup[1]) + ")" + " -> " + str(tuples.tup[0]) + " : " + str(relation_type), group=relation_type) got_net.add_edge(tuples.tup[0], tuples.tup[1]) cp += 1 # got_net.add_node(src, src, title=src) # got_net.add_node(dst, dst, title=dst) # got_net.add_edge(src, dst, value=w) # neighbor_map = got_net.get_adj_list() # add neighbor data to node hover data '''for node in got_net.nodes: node["title"] += " Neighbors:<br>" + \ "<br>".join(neighbor_map[node["id"]]) node["value"] = len(neighbor_map[node["id"]])''' got_net.show("networkRNA.html")
def draw_list(self): """ draw the ARN using the class attributes Args: nothing Returns: a local generated web page """ got_net = Network(height="750px", width="100%", bgcolor="#222222", font_color="white") got_net.heading = "motif detected" # set the physics layout of the network got_net.barnes_hut() cp = 0 for nuk in self.list_motif: for tuples in nuk.tup: if tuples.relation in self.grps.keys(): relation_type = self.grps.get(tuples.relation) else: relation_type = 0 relation_type = str(nuk.paired_type) got_net.add_node(tuples.tup[0], label="(" + str(tuples.tup[0]) + ")" + " -> " + str(tuples.tup[1]) + " : " + str(relation_type), group=relation_type) got_net.add_node(tuples.tup[1], label="(" + str(tuples.tup[1]) + ")" + " -> " + str(tuples.tup[0]) + " : " + str(relation_type), group=relation_type) got_net.add_edge(tuples.tup[0], tuples.tup[1]) cp += 1
def draw_graph_with_pyvis(triples_df, dataset_name, cause_column, treat_column, food_column='term1', disease_column='term2', food_node_color='green', disease_node_color='darkgrey', cause_color='lightcoral', treat_color='palegreen'): nt = Network("800px", "100%") nt.heading = f'Food-disease relations identified in dataset: {dataset_name}' triples_df[food_column] = triples_df[food_column].apply( lambda x: x.lower()) triples_df[disease_column] = triples_df[disease_column].apply( lambda x: x.lower()) unique_pairs = triples_df.groupby([ food_column, disease_column, 'entity_id_y', 'foodon', 'snomedct', 'hansard', 'hansardClosest', 'hansardParent', 'synonyms' ]).mean()[[cause_column, treat_column]] unique_pairs = unique_pairs[(unique_pairs[cause_column] > 0) | (unique_pairs[treat_column] > 0)] print(unique_pairs) results = [] for index_columns in unique_pairs.index: term1, term2, doid, foodon, snomedct, hansard, hansard_closest, hansard_parent, synonyms = index_columns all_evidence = triples_df[triples_df[food_column] == term1][ triples_df[disease_column] == term2]['relation_candidates'] if len(set(all_evidence.values)) > 1: all_evidence = '______'.join(set(all_evidence.values)) label_term1 = triples_df[triples_df[food_column] == term1][ 'term1'].value_counts().idxmax() label_term2 = triples_df[triples_df[disease_column] == term2][ 'term2'].value_counts().idxmax() nt.add_node(term1, label=label_term1, color=food_node_color, size=15) nt.add_node(term2, label=label_term2, color=disease_node_color, size=15) row = unique_pairs.loc[index_columns, :] edge_color = cause_color if row[cause_column] > row[ treat_column] else treat_color if row[cause_column] < row[ treat_column] else 'purple' results.append({ 'term1': label_term1, 'term2': label_term2, 'evidence': all_evidence, 'treat': row[treat_column], 'cause': row[cause_column], 'doid': doid, 'foodon': foodon, 'snomedct': snomedct, 'hansard': hansard, 'hansardClosest': hansard_closest, 'hansardParent': hansard_parent, 'synonyms': synonyms }) edge_label = f'treat: {row[treat_column]} cause: {row[cause_column]} \n{all_evidence}' nt.add_edge(term1, term2, title=edge_label, color=edge_color, width=5) nt.show_buttons( filter_=['physics', 'nodes', 'edges', 'selection', 'layout']) pd.DataFrame(results).to_csv('visualization_triples_sum.csv') print(len(nt.edges)) # nt.enable_physics(True) nt.show("nx.html")