Skip to content

Commit

Permalink
download tree info and studies
Browse files Browse the repository at this point in the history
  • Loading branch information
ndvan committed Oct 2, 2019
1 parent bd0e662 commit 297ce59
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 75 deletions.
5 changes: 5 additions & 0 deletions app/assets/stylesheets/trees.scss
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,8 @@
display: inline-block;
float: left;
}

#download-tree-info-link {
margin-top: 20px !important;
margin-bottom: 10px !important;
}
7 changes: 5 additions & 2 deletions app/controllers/trees_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class TreesController < ApplicationController
include TreesHelper
include ListsHelper

before_action :find_tree, only: [:destroy, :edit, :update, :show, :download, :metadata]
before_action :find_tree, only: [:destroy, :edit, :update, :show, :download, :metadata, :download_tree_info]

def show
@x = params[:x]
Expand Down Expand Up @@ -237,7 +237,10 @@ def download_studies
respond_to do |format|
format.js
end

end

def download_tree_info
send_data @tree.info.to_json, :filename => @tree.name + "_info.json"
end

private
Expand Down
20 changes: 19 additions & 1 deletion app/models/tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,25 @@ def ot_scaled
end
end

def metadata
def info
begin
n = JSON.parse(self.tree)["tree_metadata"]
return n.nil? ? "" : n
rescue
""
end
end

def data
begin
n = JSON.parse(self.tree)["meta_data"]
return n.nil? ? "" : n
rescue
""
end
end

def supporting_studies
begin
n = JSON.parse(self.studies)
return n.nil? ? "" : n
Expand Down
52 changes: 0 additions & 52 deletions app/views/trees/_info.html.erb

This file was deleted.

84 changes: 72 additions & 12 deletions app/views/trees/_metadata.html.erb
Original file line number Diff line number Diff line change
@@ -1,27 +1,87 @@
<% tree_metadata = tree.metadata %>

<div class="container">
<div class="row min-page-height">
<div class="col-md-4">
<h3>Tree info</h3>

<div id="info-wrapper">
<% if tree_metadata.empty? %>
<div class='center loading w-100'><i class="fa fa-spin fa-4x fa-spinner" aria-hidden="true"></i></div>
<% else %>
<%= render partial: "info", locals: { tree_metadata: tree_metadata } %>
<% end %>
<div class="row">
<div class="col-md-8">
<h3>Tree info</h3>
</div>
<div class="col-md-4">
<div id="download-tree-info-link">
<%= link_to "Save", download_tree_info_tree_path(tree, format: :txt), class: "btn btn-primary" %>
</div>
</div>
</div>

<% tree_info = tree.info %>
<% tree_data = tree.data %>

<table class="table table-hover">
<tbody>
<tr>
<th>Topology ID</th>
<td><%= tree_info["topology_id"] rescue "NA" %></td>
</tr>
<tr>
<th>Gene or species</th>
<td><%= tree_info["gene_or_species"] rescue "NA" %></td>
</tr>
<tr>
<th>Rooted</th>
<td><%= tree_info["rooted"] rescue "NA" %></td>
</tr>
<tr>
<th>Anastomosing</th>
<td><%= tree_info["anastomosing"] rescue "NA" %></td>
</tr>
<tr>
<th>Consensus type</th>
<td><%= tree_info["consensus_type"] rescue "NA" %></td>
</tr>
<tr>
<th>Branch length type</th>
<td><%= tree_info["branch_length_type"] rescue "NA" %></td>
</tr>
<tr>
<th>Branch support type</th>
<td><%= tree_info["branch_support_type"] rescue "NA" %></td>
</tr>
<tr>
<th>Character matrix</th>
<td><%= tree_info["character_matrix"] rescue "NA" %></td>
</tr>
<tr>
<th>Alignment method</th>
<td><%= tree_info["alignment_method"] rescue "NA" %></td>
</tr>
<tr>
<th>Inference method</th>
<td><%= tree_info["inference_method"] rescue "NA" %></td>
</tr>
<tr>
<th>Number of tips</th>
<td><%= tree_info["num_tips"] rescue "NA" %></td>
</tr>
<tr>
<th>Creation time</th>
<td><%= tree_data["creation_time"] rescue "NA" %></td>
</tr>
<tr>
<th>Execution time (second)</th>
<td><%= tree_data["execution_time"] rescue "NA" %></td>
</tr>
</tbody>
</table>
</div>

<div class="col-md-8">
<h3>Supporting studies <a href="#" data-toggle="tooltip" title="Published studies with trees relevant to deriving your Phylotastic tree (trees from OpenTree may lack supporting studies if they are based solely on taxonomy)."><i class="fa fa-question-circle" aria-hidden="true"></i></a></h3>

<div id="studies-wrapper">
<% if tree_metadata.empty? %>
<% tree_studies = tree.supporting_studies %>
<% if tree_studies.empty? %>
<div class='center loading w-100'><i class="fa fa-spin fa-4x fa-spinner" aria-hidden="true"></i></div>
<% else %>
<%= render partial: "support_studies", locals: { tree_metadata: tree_metadata } %>
<%= render partial: "support_studies", locals: { tree_studies: tree_studies } %>
<% end %>
</div>
</div>
Expand Down
19 changes: 13 additions & 6 deletions app/views/trees/_support_studies.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% if tree_metadata.empty? || tree_metadata["studies"].empty? %>
<% if tree_studies.empty? || tree_studies["studies"].empty? %>
<p>No supporting studies were found. This typically happens when a tree is derived from the OpenTree taxonomy without phylogenetic refinement.</p>
<% else %>

Expand All @@ -9,11 +9,15 @@
<hr>

<%= form_tag trees_download_studies_path, method: :post, remote: true do %>
<% tree_metadata["studies"].each_with_index do |s, i| %>
<% tree_studies["studies"].each_with_index do |s, i| %>
<div class="study">
<div class="study-title">
<div class="checkbox-wrapper">
<%= check_box_tag("p[#{s["PublicationDOI"]}]", 1, checked = false, class: "select_pub") %>
<div class="checkbox-wrapper">
<% if s["PublicationDOI"].include? "dx.doi.org" %>
<%= check_box_tag("p[#{s["PublicationDOI"]}]", 1, checked = false, class: "select_pub") %>
<% else %>
<i class='fa fa-exclamation-triangle ' data-toggle='tooltip' title='Bibtex entry not found'></i>
<% end %>
</div>
<%= s["Publication"] %>
</div>
Expand Down Expand Up @@ -51,7 +55,7 @@
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<a type="button" class="btn btn-primary" download="citation.txt" id="citation-download">Save</a>
<a type="button" class="btn btn-primary" download="citation.bib" id="citation-download">Save</a>
</div>
</div>
</div>
Expand All @@ -72,7 +76,10 @@
});

$("#citation-download").click(function() {
console.log("aaa");
this.href = "data:text/plain;charset=UTF-8," + $('#citation-modal-content').text();
});

$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
</script>
4 changes: 2 additions & 2 deletions app/views/trees/metadata.js.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
$("#info-wrapper").html("<%=j render partial: 'info', locals: { tree_metadata: @tree_metadata } %>");
$("#studies-wrapper").html("<%=j render partial: 'support_studies', locals: { tree_metadata: @tree_metadata } %>");
<% tree_studies = @tree.supporting_studies %>
$("#studies-wrapper").html("<%=j render partial: 'support_studies', locals: { tree_studies: tree_studies } %>");
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
get 'wf'
post "wf_update"
get 'metadata'
get 'download_tree_info'
end
end

Expand Down

0 comments on commit 297ce59

Please sign in to comment.