From 20fce0df6e6258a1c73440f197091191a30f0fa6 Mon Sep 17 00:00:00 2001 From: Sebastian Proost Date: Wed, 24 Jan 2018 07:00:39 +0100 Subject: [PATCH] Neighborhood comparisons are now better. Show intersection only is possible. --- README.md | 4 +- conekt/controllers/ecc.py | 1 + conekt/helpers/cytoscape.py | 59 ++++++++++++++++++++++++++ conekt/static/js/cytoscape.cycss | 8 ++++ conekt/static/js/planet_graph.js | 14 ++++++ conekt/templates/expression_graph.html | 9 +++- 6 files changed, 91 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b17b270..14a0f6b 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Tutorials * [Coexpression Networks and Clusters](docs/tutorials/005_coexpression_networks_clusters.md) -Anything missing ? Further questions ? Don't hesitate to [contact](mailto:proost@mpimp-golm.mpg.de) us. +Anything missing ? Further questions ? Don't hesitate to [contact](mailto:sebastian.proost@gmail.com) us. Setting up CoNekT ----------------- @@ -56,5 +56,5 @@ Contact ------- * [Marek Mutwil](mailto:mutwil@mpmpi-golm.mpg.de) ( mutwil@mpmpi-golm.mpg.de ) - * [Sebastian Proost](mailto:proost@mpimp-golm.mpg.de) ( proost@mpimp-golm.mpg.de ) + * [Sebastian Proost](mailto:sebastian.proost@gmail.com) ( sebastian.proost@gmail.com ) diff --git a/conekt/controllers/ecc.py b/conekt/controllers/ecc.py index 732515c..495263e 100644 --- a/conekt/controllers/ecc.py +++ b/conekt/controllers/ecc.py @@ -101,6 +101,7 @@ def ecc_graph_pair_json(ecc_id): network_cytoscape = CytoscapeHelper.add_lc_data_nodes(network_cytoscape) network_cytoscape = CytoscapeHelper.add_species_data_nodes(network_cytoscape) network_cytoscape = CytoscapeHelper.connect_homologs(network_cytoscape) + network_cytoscape = CytoscapeHelper.tag_ecc_singles(network_cytoscape) return json.dumps(network_cytoscape) diff --git a/conekt/helpers/cytoscape.py b/conekt/helpers/cytoscape.py index 769ed45..c418aa8 100644 --- a/conekt/helpers/cytoscape.py +++ b/conekt/helpers/cytoscape.py @@ -455,6 +455,65 @@ def prune_unique_lc(network): return pruned_network + @staticmethod + def tag_ecc_singles(network): + """ + When comparing ECC pairs, genes without a homolog in the graph could be hidden, to this end these genes need + to be tagged so javascript can handle this. + + :param network: input network + :return: network with singles tagged + """ + output_network = deepcopy(network) + + # Find Query genes, add hideable tag to everything except queries + queries = [] + for n in output_network['nodes']: + if n['data']['node_type'] == 'query' and n['data']['name'] not in queries: + queries.append(n['data']['name']) + n['data']['tag'] = 'always_show' + else: + n['data']['tag'] = 'hideable' + + # Store neighborhoods + neighborhoods = {q: [] for q in queries} + + for e in output_network['edges']: + if e['data']['source'] in queries: + if e['data']['target'] not in queries: + neighborhoods[e['data']['source']].append(e['data']['target']) + elif e['data']['target'] in queries: + if e['data']['source'] not in queries: + neighborhoods[e['data']['target']].append(e['data']['source']) + + # adjust tags on genes that should be shown (shared neighborhood) + # Check for genes present in both neighborhoods (intra species comparisons) + for n in output_network['nodes']: + counter = 0 + for k in queries: + if n['data']['name'] in neighborhoods[k]: + counter += 1 + if counter > 1: + n['data']['tag'] = 'always_show' + + # Check homology edges + genes_to_show = [] + for e in output_network['edges']: + if 'homology' in e['data'].keys() and e['data']['homology']: + counter = 0 + for k in queries: + if e['data']['source'] in neighborhoods[k] or e['data']['target'] in neighborhoods[k]: + counter += 1 + if counter > 1: + genes_to_show.append(e['data']['source']) + genes_to_show.append(e['data']['target']) + + for n in output_network['nodes']: + if n['data']['name'] in genes_to_show: + n['data']['tag'] = 'always_show' + + return output_network + @staticmethod def merge_networks(network_one, network_two): """ diff --git a/conekt/static/js/cytoscape.cycss b/conekt/static/js/cytoscape.cycss index 18b927b..5071477 100644 --- a/conekt/static/js/cytoscape.cycss +++ b/conekt/static/js/cytoscape.cycss @@ -35,6 +35,10 @@ node:selected { line-color: black; } +node.hidden { + visibility: hidden; +} + node.found { width: 50px; height: 60px; @@ -177,4 +181,8 @@ edge.default_width { edge.depth { width: mapData(depth, 0, 2, 3, 1); +} + +edge.hidden { + visibility: hidden; } \ No newline at end of file diff --git a/conekt/static/js/planet_graph.js b/conekt/static/js/planet_graph.js index f6b10bb..2ca1c15 100644 --- a/conekt/static/js/planet_graph.js +++ b/conekt/static/js/planet_graph.js @@ -390,6 +390,20 @@ $(function () { // on dom ready cy.nodes('[^compound]').addClass($(this).attr('attr')); }); + $('.cy-node-hide').click(function (ev) { + ev.preventDefault(); + cy.nodes('[tag="hideable"]').addClass('hidden'); + $(this).hide(); + $('.cy-node-show').show(); + }); + + $('.cy-node-show').click(function (ev) { + ev.preventDefault(); + cy.nodes('[tag="hideable"]').removeClass('hidden'); + $(this).hide(); + $('.cy-node-hide').show(); + }); + $('.cy-edge-color').click(function (ev) { ev.preventDefault(); $(this).closest('.cy-option-menu').find('.cy-edge-color').each(function () { diff --git a/conekt/templates/expression_graph.html b/conekt/templates/expression_graph.html index b65f7bf..4e2c33a 100644 --- a/conekt/templates/expression_graph.html +++ b/conekt/templates/expression_graph.html @@ -62,13 +62,13 @@

ECC multi

{% if node %}
  • Depth
  • {% endif %} -
  • Family (default)
  • +
  • Family {%- if not (ecc_pair or ecc_multi) -%} (default){%- endif -%}
  • Label Co-occ.
  • {% if cluster or cluster_one %}
  • Neighbors
  • {% endif %} {% if sequence or ecc_pair or ecc_multi %} -
  • Species
  • +
  • Species {%- if ecc_pair or ecc_multi -%} (default){%- endif -%}
  • {% endif %} {% if graph_data %}
  • Specificity
  • @@ -85,6 +85,11 @@

    ECC multi

  • Specificity
  • {% endif %} + {% if ecc_pair %} +

  • + +
  • Show Only Intersection
  • + {% endif %}