From bfe8e243002ab6ba8a4658f2a5eaef73de16c8a8 Mon Sep 17 00:00:00 2001 From: sepro Date: Thu, 9 Nov 2017 16:22:22 +0100 Subject: [PATCH] hiding trees when they haven not been reconciled yet. updated names in plot --- conekt/helpers/cytoscape.py | 9 ++++++++- conekt/models/xrefs.py | 11 ++++++++++- conekt/static/js/cytoscape.cycss | 2 +- conekt/templates/expression_graph.html | 8 ++++---- conekt/templates/tree.html | 11 ++++++++++- 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/conekt/helpers/cytoscape.py b/conekt/helpers/cytoscape.py index 85556a8..eeff254 100644 --- a/conekt/helpers/cytoscape.py +++ b/conekt/helpers/cytoscape.py @@ -188,7 +188,8 @@ def add_lc_data_nodes(network): @staticmethod def add_descriptions_nodes(network): """ - Adds the description to nodes (if available) and alternative names (aka gene tokens) to a cytoscape.js network + Adds the description to nodes (if available), the best name to display and alternative names (aka gene tokens) + to a cytoscape.js network :param network: Cytoscape.js compatible network object :return: Network with descriptions and tokens added @@ -203,6 +204,7 @@ def add_descriptions_nodes(network): sequences = Sequence.query.filter(Sequence.id.in_(sequence_ids)).all() descriptions = {s.id: s.description for s in sequences} + best_names = {s.id: s.best_name for s in sequences} tokens = {s.id: ", ".join([x.name for x in s.xrefs if x.platform == 'token']) for s in sequences} # Set empty tokens to None @@ -217,6 +219,11 @@ def add_descriptions_nodes(network): else: node["data"]["description"] = None + if node["data"]["gene_id"] in best_names.keys(): + node["data"]["best_name"] = best_names[node["data"]["gene_id"]] + else: + node["data"]["best_name"] = node["data"]["gene_name"] + if node["data"]["gene_id"] in tokens.keys(): node["data"]["tokens"] = tokens[node["data"]["gene_id"]] else: diff --git a/conekt/models/xrefs.py b/conekt/models/xrefs.py index bda6ed4..8290731 100644 --- a/conekt/models/xrefs.py +++ b/conekt/models/xrefs.py @@ -62,7 +62,7 @@ def add_xref_genes_from_file(species_id, filename): seq_dict = {s.name.upper(): s for s in sequences} with open(filename, "r") as f: - for line in f: + for i, line in enumerate(f): sequence, name, platform, url = line.split('\t') xref = XRef() @@ -73,11 +73,20 @@ def add_xref_genes_from_file(species_id, filename): if sequence.upper() in seq_dict.keys(): s = seq_dict[sequence.upper()] s.xrefs.append(xref) + + if i % 400 == 0: + # Update every 400 lines try: db.session.commit() except Exception as e: db.session.rollback() + # Commit final changes + try: + db.session.commit() + except Exception as e: + db.session.rollback() + @staticmethod def add_xref_families_from_file(gene_family_method_id, filename): gf_method = GeneFamilyMethod.query.get(gene_family_method_id) diff --git a/conekt/static/js/cytoscape.cycss b/conekt/static/js/cytoscape.cycss index 2e2674f..18b927b 100644 --- a/conekt/static/js/cytoscape.cycss +++ b/conekt/static/js/cytoscape.cycss @@ -1,5 +1,5 @@ node { - content: data(gene_name); + content: data(best_name); text-valign: center; color: black; background-color: data(color); diff --git a/conekt/templates/expression_graph.html b/conekt/templates/expression_graph.html index 9a7b6d4..e8f930c 100644 --- a/conekt/templates/expression_graph.html +++ b/conekt/templates/expression_graph.html @@ -227,10 +227,10 @@

ECC pair

-