Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Neighborhood comparisons are now better. Show intersection only is po…
…ssible.
  • Loading branch information
proost committed Jan 24, 2018
1 parent a122ad5 commit 20fce0d
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -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
-----------------
Expand Down Expand Up @@ -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 )

1 change: 1 addition & 0 deletions conekt/controllers/ecc.py
Expand Up @@ -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)

Expand Down
59 changes: 59 additions & 0 deletions conekt/helpers/cytoscape.py
Expand Up @@ -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):
"""
Expand Down
8 changes: 8 additions & 0 deletions conekt/static/js/cytoscape.cycss
Expand Up @@ -35,6 +35,10 @@ node:selected {
line-color: black;
}

node.hidden {
visibility: hidden;
}

node.found {
width: 50px;
height: 60px;
Expand Down Expand Up @@ -177,4 +181,8 @@ edge.default_width {

edge.depth {
width: mapData(depth, 0, 2, 3, 1);
}

edge.hidden {
visibility: hidden;
}
14 changes: 14 additions & 0 deletions conekt/static/js/planet_graph.js
Expand Up @@ -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 () {
Expand Down
9 changes: 7 additions & 2 deletions conekt/templates/expression_graph.html
Expand Up @@ -62,13 +62,13 @@ <h1>ECC multi</h1>
{% if node %}
<li><a href="#" class="cy-node-color" attr="depth_color">Depth</a></li>
{% endif %}
<li><a href="#" class="cy-node-color" attr="family_color">Family <span class="text-muted">(default)</span></a></li>
<li><a href="#" class="cy-node-color" attr="family_color">Family {%- if not (ecc_pair or ecc_multi) -%} <span class="text-muted">(default)</span>{%- endif -%}</a></li>
<li><a href="#" class="cy-node-color" attr="lc_color">Label Co-occ.</a></li>
{% if cluster or cluster_one %}
<li><a href="#" class="cy-node-color" attr="neighbors">Neighbors</a></li>
{% endif %}
{% if sequence or ecc_pair or ecc_multi %}
<li><a href="#" class="cy-node-color" attr="species_color">Species</a></li>
<li><a href="#" class="cy-node-color" attr="species_color">Species {%- if ecc_pair or ecc_multi -%} <span class="text-muted">(default)</span>{%- endif -%}</a></li>
{% endif %}
{% if graph_data %}
<li><a href="#" class="cy-node-color" attr="spm_color">Specificity</a></li>
Expand All @@ -85,6 +85,11 @@ <h1>ECC multi</h1>
<li><a href="#" class="cy-node-shape" attr="spm_shape">Specificity</a></li>
{% endif %}
</div>
{% if ecc_pair %}
<li><hr /></li>
<li class="dropdown-header">Neighborhood comparison</li>
<li><a href="#" class="cy-node-hide">Show Only Intersection</a><a href="#" class="cy-node-show" style="display:none">Show All</a></li>
{% endif %}
</ul>
</div>
<div class="dropdown btn-group" role="group">
Expand Down

0 comments on commit 20fce0d

Please sign in to comment.