Skip to content

Commit

Permalink
Added support for detecting and reporting errors in input Newick files.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurav committed Apr 9, 2018
1 parent af884f4 commit d205300
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 40 deletions.
87 changes: 49 additions & 38 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -187,48 +187,59 @@
</template>
</div>
<div class="panel-body">
<svg v-if="phylogeny_annotations_mode_for !== phylogeny" :id="'phylogeny-svg-' + phylogeny_index" :alt="get_phylogeny_as_newick('#phylogeny-svg-' + phylogeny_index, phylogeny)"></svg>
<div v-if="phylogeny_annotations_mode_for === phylogeny">
<p>This table displays all labeled nodes in this phylogeny and all known annotations
applied to any of those nodes. A feature to change node labels is currently in development.
</p>

<table class="table table-bordered table-hover table-striped table-fixed-height" style="width: 100%">
<tbody>
<tr>
<th>Label</th>
<th>Property</th>
<th>Value</th>
</tr>
<template v-if="get_node_labels_in_phylogeny(phylogeny).length == 0">
<tr><td style="text-align: center"><em>No labeled nodes in this phylogeny.</em></td></tr>
</template>
<template
v-else
v-for="(node_label, node_label_index) of get_node_labels_in_phylogeny(phylogeny)"
>
<template v-if="errors_parsing_phylogenies.hasOwnProperty(phylogeny) && errors_parsing_phylogenies[phylogeny].length > 0">
<p>The following errors occurred while parsing this phylogeny:</p>

<ul>
<li v-for="err of errors_parsing_phylogenies[phylogeny]">{{err}}</li>
</ul>

<p>Please edit the Newick corresponding to this phylogeny by clicking the "Edit as Newick" button below.</p>
</template>
<template v-else>
<svg v-if="phylogeny_annotations_mode_for !== phylogeny" :id="'phylogeny-svg-' + phylogeny_index" :alt="get_phylogeny_as_newick('#phylogeny-svg-' + phylogeny_index, phylogeny)"></svg>
<div v-if="phylogeny_annotations_mode_for === phylogeny">
<p>This table displays all labeled nodes in this phylogeny and all known annotations
applied to any of those nodes. A feature to change node labels is currently in development.
</p>

<table class="table table-bordered table-hover table-striped table-fixed-height" style="width: 100%">
<tbody>
<tr>
<th>Label</th>
<th>Property</th>
<th>Value</th>
</tr>
<template v-if="get_node_labels_in_phylogeny(phylogeny).length == 0">
<tr><td style="text-align: center"><em>No labeled nodes in this phylogeny.</em></td></tr>
</template>
<template
v-if="phylogeny.hasOwnProperty('additionalNodeProperties') && phylogeny.additionalNodeProperties.hasOwnProperty(node_label)"
v-else
v-for="(node_label, node_label_index) of get_node_labels_in_phylogeny(phylogeny)"
>
<tr v-for="prop_name of Object.keys(phylogeny.additionalNodeProperties[node_label])">
<td>{{node_label}}</td>
<td>{{prop_name}}</td>
<td><textarea readonly rows="4" style="width: 100%">{{JSON.stringify(phylogeny.additionalNodeProperties[node_label][prop_name])}}</textarea></td>
</tr>
<template
v-if="phylogeny.hasOwnProperty('additionalNodeProperties') && phylogeny.additionalNodeProperties.hasOwnProperty(node_label)"
>
<tr v-for="prop_name of Object.keys(phylogeny.additionalNodeProperties[node_label])">
<td>{{node_label}}</td>
<td>{{prop_name}}</td>
<td><textarea readonly rows="4" style="width: 100%">{{JSON.stringify(phylogeny.additionalNodeProperties[node_label][prop_name])}}</textarea></td>
</tr>
</template>

<template v-else>
<tr>
<td>{{node_label}}</td>
<td colspan="2"><em>No node properties.</em></td>
</tr>
</template>
</template>
</tbody>
</table>

<template v-else>
<tr>
<td>{{node_label}}</td>
<td colspan="2"><em>No node properties.</em></td>
</tr>
</template>
</template>
</tbody>
</table>

<p>This table contains {{get_node_labels_in_phylogeny(phylogeny).length}} nodes.</p>
</div>
<p>This table contains {{get_node_labels_in_phylogeny(phylogeny).length}} nodes.</p>
</div>
</template>
</div>
<div class="panel-footer">
<textarea
Expand Down
26 changes: 24 additions & 2 deletions js/curation-tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ var vm = new Vue({
specifier_dropdown_target: 'none',

// Example PHYX URLs to display
example_phyx_urls: example_phyx_urls
example_phyx_urls: example_phyx_urls,

// Which phylogenies had errors in processing?
errors_parsing_phylogenies: {}
},

// Filters to be used in the template.
Expand Down Expand Up @@ -1052,7 +1055,26 @@ function render_tree(node_expr, phylogeny) {
"transitions": false
})
.style_nodes(nodeStyler);
tree(d3.layout.newick_parser(newick));

vm.errors_parsing_phylogenies[phylogeny] = [];
try {
tree(d3.layout.newick_parser(newick));
} catch(e) {
console.log("Error occurred while reading phylogeny: ", e);

// TODO: try to diagnose why the Newick string could not be parsed.

// If we can't figure out any specific type of error, maybe it's a
// TypeError with the message "node is undefined", which is currently
// how Phylotree.js indicates "the Newick string is malformed".
if(e instanceof TypeError && e.message == 'node is undefined') {
vm.errors_parsing_phylogenies[phylogeny].push("The Newick string is malformed.");
} else {
vm.errors_parsing_phylogenies[phylogeny].push("Unknown error: " + JSON.stringify(e));
}

return undefined;
}

tree.get_nodes().forEach(function(node) {
// All nodes (including named nodes) can be renamed.
Expand Down

0 comments on commit d205300

Please sign in to comment.