From de84b015bdb76af23b333beb3469b3a7f9a8f352 Mon Sep 17 00:00:00 2001 From: sepro Date: Thu, 30 Nov 2017 14:18:22 +0100 Subject: [PATCH] test version of multi ecc network --- conekt/controllers/ecc.py | 14 +++++ .../relationships/sequence_sequence_ecc.py | 58 +++++++++++++++++-- conekt/templates/expression_graph.html | 18 ++++-- 3 files changed, 80 insertions(+), 10 deletions(-) diff --git a/conekt/controllers/ecc.py b/conekt/controllers/ecc.py index e248820..798eebc 100644 --- a/conekt/controllers/ecc.py +++ b/conekt/controllers/ecc.py @@ -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/') def ecc_graph_pair(ecc_id): """ @@ -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) diff --git a/conekt/models/relationships/sequence_sequence_ecc.py b/conekt/models/relationships/sequence_sequence_ecc.py index c1bf778..cb89793 100644 --- a/conekt/models/relationships/sequence_sequence_ecc.py +++ b/conekt/models/relationships/sequence_sequence_ecc.py @@ -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: @@ -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, @@ -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 diff --git a/conekt/templates/expression_graph.html b/conekt/templates/expression_graph.html index ea5d569..b65f7bf 100644 --- a/conekt/templates/expression_graph.html +++ b/conekt/templates/expression_graph.html @@ -13,6 +13,8 @@ Custom network graph {% elif ecc_pair %} ECC Pair graph + {% elif ecc_multi %} + ECC Network {% endif %} {% endblock %} @@ -34,6 +36,8 @@

@@ -63,7 +67,7 @@

ECC pair

{% if cluster or cluster_one %}
  • Neighbors
  • {% endif %} - {% if sequence or ecc_pair %} + {% if sequence or ecc_pair or ecc_multi %}
  • Species
  • {% endif %} {% if graph_data %} @@ -92,7 +96,7 @@

    ECC pair

  • Depth
  • PCC
  • HRR
  • - {% elif ecc_pair %} + {% elif ecc_pair or ecc_multi %}
  • Type
  • {% elif not sequence %}
  • Score
  • @@ -111,7 +115,7 @@

    ECC pair

    {% if sequence %}
  • ECC
  • {% endif %} - {% if not sequence and not ecc_pair %} + {% if not sequence and not ecc_pair and not ecc_multi %}

  • Cutoff: {{cutoff}}

  • @@ -206,12 +210,14 @@

    ECC pair

    {% elif cluster_one %}
    - {% elif sequence %} + {% elif sequence %}
    - {% elif graph_data %} + {% elif graph_data %}
    - {% elif ecc_pair %} + {% elif ecc_pair %}
    + {% elif ecc_multi %} +
    {% endif %}