Skip to content

Commit

Permalink
hiding trees when they haven not been reconciled yet. updated names i…
Browse files Browse the repository at this point in the history
…n plot
  • Loading branch information
proost committed Nov 9, 2017
1 parent fc23444 commit bfe8e24
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
9 changes: 8 additions & 1 deletion conekt/helpers/cytoscape.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down
11 changes: 10 additions & 1 deletion conekt/models/xrefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion conekt/static/js/cytoscape.cycss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
node {
content: data(gene_name);
content: data(best_name);
text-valign: center;
color: black;
background-color: data(color);
Expand Down
8 changes: 4 additions & 4 deletions conekt/templates/expression_graph.html
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,10 @@ <h1>ECC pair</h1>
<div class="modal-header">
<h4 class="modal-title" id="dataModalLabel"><strong>Export Data</strong></h4>
</div>
<div class="modal-body" syle="width:700px;height:200px">
<button class="btn btn-primary" id="cy-download-xgmml">XGMML</button> <span class="text-muted">(compatible with Cytoscape)</span>
<div class="modal-body" syle="width:700px;min-height:200px">
<button class="btn btn-primary" id="cy-download-xgmml">XGMML</button> <span class="text-muted">(compatible with <a href="http://www.cytoscape.org/">Cytoscape</a>)</span>
<hr />
<h3>Other formats</h3>
<h3>Other formats, compatible with <a href="http://js.cytoscape.org/">Cytoscape.js</a></h3>
<button class="btn btn-default" id="cy-download-json">JSON</button> <span class="text-muted">(network only)</span> <br/><br/>
<button class="btn btn-default" id="cy-download-jsoncy">JSON</button> <span class="text-muted">(network + colors/shapes)</span> <br/><br/>
</div>
Expand All @@ -247,7 +247,7 @@ <h3>Other formats</h3>
<div class="modal-header">
<h4 class="modal-title" id="imageModalLabel"><strong>Export Image</strong></h4>
</div>
<div class="modal-body" syle="width:700px;height:200px">
<div class="modal-body" style="width:700px;min-height:200px">
<table>
<tbody>
<tr>
Expand Down
11 changes: 10 additions & 1 deletion conekt/templates/tree.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ <h1><strong><em>Tree Methods</em></strong></h1>
</ol>
<h1>{{ tree.label }}: <strong>{{ tree.method.description }}</strong></h1>
<p>Tree for gene family <a href="{{ url_for('family.family_view', family_id=tree.family.id) }}">{{ tree.family.name }}</a></p>
{% if tree.phyloxml %}
<div class="row">
<div class="col-lg-12">
<div id="phyd3" style="height:600px">
Expand Down Expand Up @@ -96,6 +97,14 @@ <h1>{{ tree.label }}: <strong>{{ tree.method.description }}</strong></h1>
</div>
</div>
</div>
{% else %}

<div class="alert alert-warning">
<strong>PhyloXML data empty. Cannot draw tree!</strong> This indicates trees included in the database haven't been
reconciled yet.
</div>

{% endif %}
<br /><br />
{{ macro.pagination('Sequences',
url_for('tree.tree_sequences', tree_id=tree.id),
Expand All @@ -119,7 +128,7 @@ <h1>{{ tree.label }}: <strong>{{ tree.method.description }}</strong></h1>
$("#methods_table").stupidtable();
});
</script>
{% else %}
{% elif tree and tree.phyloxml %}
<script src="{{ url_for('static', filename='js/d3.v3.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/phyd3.min.js') }}"></script>
<script>
Expand Down

0 comments on commit bfe8e24

Please sign in to comment.