Skip to content

Commit

Permalink
test version of multi ecc network
Browse files Browse the repository at this point in the history
  • Loading branch information
proost committed Nov 30, 2017
1 parent 29dc9d9 commit de84b01
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 10 deletions.
14 changes: 14 additions & 0 deletions conekt/controllers/ecc.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ def ecc_graph(sequence, network, family):
family_method_id=family)


@ecc.route('/graph_multi/')
def ecc_graph_multi():
"""
Returns a page rendering the ECC graph for a specific pair of sequences
:param ecc_id: internal ID of the sequence to sequence ECC relationship
:return: Response with html page that shows the pairwise ECC network
"""

return render_template("expression_graph.html",
ecc_multi=True)


@ecc.route('/graph_pair/<int:ecc_id>')
def ecc_graph_pair(ecc_id):
"""
Expand Down Expand Up @@ -107,5 +120,6 @@ def ecc_graph_multi_json():
network_cytoscape = CytoscapeHelper.add_family_data_nodes(network_cytoscape, family)
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)

return json.dumps(network_cytoscape)
58 changes: 54 additions & 4 deletions conekt/models/relationships/sequence_sequence_ecc.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ def get_ecc_pair_network(ecc_id):
query_network_data = json.loads(query_network)
target_network_data = json.loads(target_network)

# print(query_network_data)

sequences = [association.query_sequence.id, association.target_sequence.id]

for n in query_network_data:
Expand Down Expand Up @@ -211,11 +209,32 @@ def get_ecc_multi_network(gf_method_id, sequence_ids):
SequenceSequenceECCAssociation.target_id.in_(sequence_ids))).\
all()

nodes = []
edges = []
nodes, edges = [], []
node_sequence_ids = []

networks = []

for a in associations:
query_network = a.query_sequence.network_nodes.filter_by(
method_id=a.query_network_method_id).first_or_404().network
target_network = a.target_sequence.network_nodes.filter_by(
method_id=a.target_network_method_id).first_or_404().network

if query_network not in networks:
networks.append((a.query_id,
a.query_sequence.name,
a.query_sequence.species_id,
a.query_sequence.species.name,
a.query_network_method_id,
query_network))
if target_network not in networks:
networks.append((a.target_id,
a.target_sequence.name,
a.target_sequence.species_id,
a.target_sequence.species.name,
a.target_network_method_id,
target_network))

if a.query_id not in node_sequence_ids:
node_sequence_ids.append(a.query_id)
nodes.append({"id": a.query_sequence.name,
Expand Down Expand Up @@ -244,4 +263,35 @@ def get_ecc_multi_network(gf_method_id, sequence_ids):
'ecc_pair_color': "#D33",
"edge_type": "ecc"})

new_edges = []

for sequence_id, sequence_name, species_id, species_name, network_method_id, n in networks:
network_data = json.loads(n)
for node in network_data:
gene_id = node['gene_id'] if 'gene_id' in node.keys() else None
gene_name = node['gene_name'] if 'gene_name' in node.keys() else None

if gene_id not in node_sequence_ids:
node_sequence_ids.append(gene_id)
nodes.append({
"id": gene_name,
"name": gene_name,
"species_id": species_id,
"species_name": species_name,
"gene_id": gene_id,
"gene_name": gene_name,
"network_method_id": network_method_id,
"node_type": "target"
})

if (sequence_name, gene_name) not in new_edges:
new_edges.append((sequence_name, gene_name))
new_edges.append((gene_name, sequence_name))

edges.append({"source": sequence_name,
"target": gene_name,
"link_score": node['link_score'] if 'link_score' in node else 0,
"edge_type": "expression",
'ecc_pair_color': "#3D3"})

return {"nodes": nodes, "edges": edges}, gf_method_id
18 changes: 12 additions & 6 deletions conekt/templates/expression_graph.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
Custom network graph
{% elif ecc_pair %}
ECC Pair graph
{% elif ecc_multi %}
ECC Network
{% endif %}
{% endblock %}

Expand All @@ -34,6 +36,8 @@ <h1><abbr title="Click to show help" href="{{ url_for('help.help_topic', topic='
<h1>Custom network</h1>
{% elif ecc_pair %}
<h1>ECC pair</h1>
{% elif ecc_multi %}
<h1>ECC multi</h1>
{% endif %}
</div>
<div class="clearfix">
Expand Down Expand Up @@ -63,7 +67,7 @@ <h1>ECC pair</h1>
{% if cluster or cluster_one %}
<li><a href="#" class="cy-node-color" attr="neighbors">Neighbors</a></li>
{% endif %}
{% if sequence or ecc_pair %}
{% if sequence or ecc_pair or ecc_multi %}
<li><a href="#" class="cy-node-color" attr="species_color">Species</a></li>
{% endif %}
{% if graph_data %}
Expand Down Expand Up @@ -92,7 +96,7 @@ <h1>ECC pair</h1>
<li><a href="#" class="cy-edge-color" attr="depth_color">Depth</a></li>
<li><a href="#" class="cy-edge-color" attr="link_pcc">PCC</a></li>
<li><a href="#" class="cy-edge-color" attr="hrr">HRR</a></li>
{% elif ecc_pair %}
{% elif ecc_pair or ecc_multi %}
<li><a href="#" class="cy-edge-color" attr="ecc_pair_color">Type</a></li>
{% elif not sequence %}
<li><a href="#" class="cy-edge-color" attr="link_score">Score</a></li>
Expand All @@ -111,7 +115,7 @@ <h1>ECC pair</h1>
{% if sequence %}
<li><a href="#" class="cy-edge-width" attr="ecc_width">ECC</a></li>
{% endif %}
{% if not sequence and not ecc_pair %}
{% if not sequence and not ecc_pair and not ecc_multi %}
<li><hr /></li>
<li class="dropdown-header"><abbr title="Click to show help" href="{{ url_for('help.help_topic', topic='hrr') }}" data-target="#helpModal">HRR</abbr> Filter</li>
<li><p><strong>Cutoff:</strong> <span id="cy-edge-score-value" class="text-muted">{{cutoff}}</span></p></li>
Expand Down Expand Up @@ -206,12 +210,14 @@ <h1>ECC pair</h1>
<div id="cy" json="{{ url_for('expression_cluster.expression_cluster_json', cluster_id=cluster.id, family_method_id=family_method_id) }}" cycss="{{ url_for('static', filename='js/cytoscape.cycss') }}"></div>
{% elif cluster_one %}
<div id="cy" json="{{ url_for('graph_comparison.graph_comparison_cluster_json', one=cluster_one.id, two=cluster_two.id, family_method_id=family_method_id) }}" cycss="{{ url_for('static', filename='js/cytoscape.cycss') }}"></div>
{% elif sequence %}
{% elif sequence %}
<div id="cy" json="{{ url_for('ecc.ecc_graph_json', sequence=sequence.id, network=network_method_id, family=family_method_id) }}" cycss="{{ url_for('static', filename='js/cytoscape.cycss') }}"></div>
{% elif graph_data %}
{% elif graph_data %}
<div id="cy" cycss="{{ url_for('static', filename='js/cytoscape.cycss') }}"></div>
{% elif ecc_pair %}
{% elif ecc_pair %}
<div id="cy" json="{{ url_for('ecc.ecc_graph_pair_json', ecc_id = ecc_pair.id) }}" cycss="{{ url_for('static', filename='js/cytoscape.cycss') }}"></div>
{% elif ecc_multi %}
<div id="cy" json="{{ url_for('ecc.ecc_graph_multi_json') }}" cycss="{{ url_for('static', filename='js/cytoscape.cycss') }}"></div>
{% endif %}


Expand Down

0 comments on commit de84b01

Please sign in to comment.