Visualization

All methods used to perform the visualizations.

Network visualization

Utils to generate the Cytoscape.js network.

compath.visualization.cytoscape.filter_network_by_similarity(graph, min_similarity)[source]

Remove edges with similarity less than the minimum given.

Parameters
  • graph (networkx.Graph) – graph

  • min_similarity (float) – minimum similarity required to keep an edge

compath.visualization.cytoscape.pathways_to_similarity_network(manager_dict, pathways)[source]

Create a graph with the given pathways related by their similarity

Parameters
Return type

networkx.Graph

compath.visualization.cytoscape.enrich_graph_with_mappings(graph, mappings)[source]

Enrich a graph with the mapping information.

Parameters
  • networkx.Graph (graph) –

  • mappings (iter) –

compath.visualization.cytoscape.networkx_to_cytoscape_js(graph)[source]

Convert a networkx graph to the cytoscape json format.

Parameters

graph (iter[PathwayMapping]) –

Return type

dict

Dendrogram visualization

Utils to generate the D3.js dendrogram. This module is adapted from https://gist.github.com/mdml/7537455.

compath.visualization.d3_dendrogram.create_similarity_matrix(gene_sets)[source]

Create a similarity matrix for a given pathway-geneset dataset.

Parameters

gene_sets (dict) – pathway gene set dictionary

Return type

pandas.DataFrame

Returns

similarity matrix

compath.visualization.d3_dendrogram.add_node(node, parent)[source]

Create a nested dictionary from the ClusterNode’s returned by SciPy.

Parameters
  • node

  • parent (dict) –

compath.visualization.d3_dendrogram.label_tree(id_name_dict, name_manager_dict, cluster_to_x, tree)[source]

Label the tree in a recursive way with names, resource and cluster information.

Parameters
  • id_name_dict (dict[str,str]) – node_id to name dictionary

  • name_manager_dict (dict[str,str]) – node name to resource ditionary

  • cluster_to_x (dict[tuple[int,int],float]) – node_id tuple of the cluster to distance

  • tree (dict) – tree like structure

Return type

list

compath.visualization.d3_dendrogram.get_dendrogram_tree(gene_sets, pathway_manager_dict)[source]

Return ready to plot json data.

Parameters
  • gene_sets (dict[str,set[str]]) – pathway gene sets dict

  • pathway_manager_dict (dict[str,str]) – pathway name to manager dictionary

Return type

tuple[dict,int]

Returns

json tree like structure

compath.visualization.d3_dendrogram.get_descendants(manager, resource, pathway_id, pathway_name)[source]

Generate d3 dendrogram structure by using BFS starting from the starting from a parent (root) node to the last descendants.

Parameters
  • manager – ComPath manager

  • resource (str) – resource name

  • pathway_id (str) – pathway identifier in the resource

  • pathway_name (str) – pathway name

Returns

parent-children data structure

Return type

list[dict]

compath.visualization.d3_dendrogram.get_mapping_dendrogram(manager, resource, pathway_id, pathway_name)[source]

Generate d3 dendrogram structure by using BFS starting from the queried node in both directions of the hierarchy.

Parameters
  • manager – ComPath manager

  • resource (str) – resource name

  • pathway_id (str) – pathway identifier in the resource

  • pathway_name (str) – pathway name

Returns

parent-children data structure

Return type

list[dict]

compath.visualization.d3_dendrogram.add_mapping_node(id_name_dict, name_manager_dict, cluster_to_x, tree)[source]

Label the tree in a recursive way with names, resource and cluster information.

Parameters
  • id_name_dict (dict[str,str]) – node_id to name dictionary

  • name_manager_dict (dict[str,str]) – node name to resource ditionary

  • cluster_to_x (dict[tuple[int,int],float]) – node_id tuple of the cluster to distance

  • tree (dict) – tree like structure

Return type

list

Venn Diagram visualization

Utils to generate the Venn Diagram.

compath.visualization.venn_diagram.process_overlap_for_venn_diagram(gene_sets, skip_gene_set_info=False)[source]

Calculate gene sets overlaps and process the structure to render venn diagram -> https://github.com/benfred/venn.js/.

Parameters
  • gene_sets (dict[str,set]) – pathway to gene sets dictionary

  • skip_gene_set_info (bool) – include gene set overlap data

Returns

list[dict]