From bd6b2e2c751ba3aa8af50c678ed6b82d35904302 Mon Sep 17 00:00:00 2001 From: sepro Date: Thu, 16 Nov 2017 10:24:01 +0100 Subject: [PATCH] hiding trees when they haven not been reconciled yet. updated names in plot --- conekt/models/expression/networks.py | 18 ++++++++++-------- conekt/static/js/planet_graph.js | 11 ++++++++++- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/conekt/models/expression/networks.py b/conekt/models/expression/networks.py index 25efdae..e69d918 100644 --- a/conekt/models/expression/networks.py +++ b/conekt/models/expression/networks.py @@ -72,7 +72,7 @@ def update_count(): @staticmethod @benchmark - def calculate_ecc(network_method_ids, gene_family_method_id): + def calculate_ecc(network_method_ids, gene_family_method_id, max_size=100): """ Function to calculate the ECC scores in and between genes of different networks @@ -94,12 +94,13 @@ def calculate_ecc(network_method_ids, gene_family_method_id): ExpressionNetwork.__table__.c.network, ExpressionNetwork.__table__.c.method_id]). where(ExpressionNetwork.__table__.c.method_id == n). - where(ExpressionNetwork.__table__.c.sequence_id is not None) + where(ExpressionNetwork.__table__.c.sequence_id.isnot(None)) ).fetchall() for sequence, network, network_method_id in current_network: - sequence_network[int(sequence)] = network - sequence_network_method[int(sequence)] = int(network_method_id) + if sequence is not None: + sequence_network[int(sequence)] = network + sequence_network_method[int(sequence)] = int(network_method_id) # Get family data and store in dictionary current_families = db.engine.execute(db.select([SequenceFamilyAssociation.__table__.c.sequence_id, @@ -141,7 +142,7 @@ def calculate_ecc(network_method_ids, gene_family_method_id): for m in network_method_ids: thresholds[n][m] = ExpressionNetworkMethod.__set_thresholds(network_families[n], network_families[m], - max_size=30) + max_size=max_size) # Data loaded start calculating ECCs new_ecc_scores = [] @@ -157,7 +158,7 @@ def calculate_ecc(network_method_ids, gene_family_method_id): sequence_family, thresholds[sequence_network_method[query]][sequence_network_method[target]], family, - max_size=30) + max_size=max_size) if significant: new_ecc_scores.append({ 'query_id': query, @@ -238,7 +239,7 @@ def __set_thresholds(families_a, families_b, max_size=30, iterations=1000): new_threshholds = [] for j in range(max_size): scores = [] - for iterations in range(iterations): + for _ in range(iterations): if i+1 < len(families_a) and j+1 < len(families_b): i_fams = random.sample(families_a, i+1) j_fams = random.sample(families_b, j+1) @@ -247,8 +248,9 @@ def __set_thresholds(families_a, families_b, max_size=30, iterations=1000): # Cannot calculate threshold with these families, add 1 scores.append(1) - scores = sorted(scores) # TODO (maybe?): cutoff is hard coded here, replace ? + print(iterations, len(scores), scores) + scores = sorted(scores) new_threshholds.append(scores[int(iterations*0.95)]) thresholds.append(new_threshholds) diff --git a/conekt/static/js/planet_graph.js b/conekt/static/js/planet_graph.js index eb5c0a3..14a2f30 100644 --- a/conekt/static/js/planet_graph.js +++ b/conekt/static/js/planet_graph.js @@ -78,6 +78,7 @@ $(function () { // on dom ready ready: function () { window.cy = this; + var has_ecc = false; initial_json = JSON.stringify(cy.json(), null, '\t'); cy.nodes('[^compound]').forEach(function (n) { @@ -186,6 +187,7 @@ $(function () { // on dom ready if (e.data('ecc_score') !== undefined) { content.push({ value: 'ECC: ' + e.data('ecc_score').toFixed(2) }); + has_ecc = true; } e.qtip({ @@ -313,7 +315,14 @@ $(function () { // on dom ready if (Object.keys(svg_spm).length > 0) { generate_legend(svg_spm, 'spm_color', 'spm'); } if (Object.keys(svg_species).length > 0) { generate_legend(svg_species, 'species_color', 'species'); } - $('.cy-node-color[attr="family_color"]').click(); + if (has_ecc) { + $('.cy-node-color[attr="species_color"]').click(); + $('.cy-edge-color[attr="ecc_type"]').click(); + } else { + $('.cy-node-color[attr="family_color"]').click(); + } + + $('#loading').addClass('loaded'); $('#legend').show();