bio-miga/miga-web

View on GitHub
app/views/shared/_result.html.erb

Summary

Maintainability
Test Coverage
<% unless key.nil? or key == :stats %>

<%
  titles = {
    ssu: 'Ribosomal RNA (small subunit)',
    essential_genes: 'Quality (essential genes)',
    cds: 'Gene prediction',
    mytaxa_scan: 'MyTaxa Scan',
    mytaxa: 'MyTaxa',
    haai_distances: 'hAAI distances',
    aai_distances: 'AAI distances',
    ani_distances: 'ANI distances',
    ogs: 'Orthologous groups of proteins'
  }
  if obj.is_a? Project
    proj = obj
  elsif not obj.is_a? MiGA::Dataset
    proj = obj.project
  end
  r_open = [:distances, :taxonomy, :project_stats, :mytaxa].include? key
%>

<h3 role='button' data-toggle='collapse' class='result-title'
      id='result-<%= key %>' href='#result-cnt-<%= key %>'
      aria-expanded='<%= r_open ? 'true' : 'false' %>'
      aria-controls='result-cnt-<%= key %>'>
  <i class='glyphicon glyphicon-tasks'> </i>
  <%= titles[key].nil? ? key.to_s.gsub('_', ' ').capitalize : titles[key] %>
</h3>

<div class='result collapse<%= ' in' if r_open %>' id='result-cnt-<%= key %>'
      aria-expanded='<%= r_open ? 'true' : 'false' %>'>
<div class='result-body'>
  <% case key %>
  <%# Dataset results %>
  <% when :read_quality %>
    <p>FastQC reports:</p>
    <ul>
    <% Dir.new(res.file_path :fastqc).each_entry do |f| %>
      <% next unless f =~ /\.html/ %>
      <li>
      <%= link_to f, obj.is_a?(MiGA::Dataset) ?
          reference_dataset_result_path(proj.id, obj.name,
            :read_quality, :fastqc, f:f) :
          query_dataset_result_path(obj.id, :read_quality, :fastqc, f:f) %>
      </li>
    <% end %>
    </ul>
  <% when :assembly %>
    <%= plot_assembly(res[:stats][:n50][0], res[:stats][:total_length][0]
          ) unless res.data[:stats][:n50].nil? %>
  <% when :essential_genes %>
    <%= render partial: 'shared/results/essential_genes',
         locals: { res: res, job: key, project: proj } %>
  <% when :ssu %>
    <%= render partial: 'shared/results/ssu',
         locals: { res: res, job: key, project: proj, obj: obj } %>
  <% when :mytaxa_scan %>
    <%
      f_path = obj.is_a?(MiGA::Dataset) ?
        reference_dataset_result_path(proj.id, obj.name,
          :mytaxa_scan, :report) :
        query_dataset_result_path(obj.id, :mytaxa_scan, :report)
      f_path = nil if res.file_path(:report).nil?
    %>
    <p>
      MyTaxa Scan detected regions with unusual taxonomic distribution
      (<%= f_path.nil? ? 'No report available' :
            link_to('download PDF', f_path, target: '_blank') %>).
    </p>
  <% when :mytaxa %>
    <%
      f_path = obj.is_a?(MiGA::Dataset) ?
        reference_dataset_result_path(proj.id, obj.name, :mytaxa, :krona) :
        query_dataset_result_path(obj.id, :mytaxa, :krona)
    %>
    <p>MiGA classified the assembled contigs at species, genus, and phylum
    levels using MyTaxa (<%= link_to 'see distribution', f_path,
          target: '_blank' %>).</p>
  <% when :distances, :taxonomy %>
    <%= render partial: 'shared/results/distances',
         locals: { res: res, job: key, project: proj, dataset: obj } %>
  <%# Project-wide results %>
  <% when :project_stats %>
    <%= render partial: 'shared/results/project_stats',
         locals: { res: res, job: key, project: proj } %>
  <% when :haai_distances %>
    <p>Average Identity between sets of conserved proteins in Bacteria and
      Archaea, as a heuristic approximation to AAI.</p>
    <%= plot_distances(res.file_path(:hist), {},
        {height:300, title:'Distribution of hAAI values'}) unless
        res.data[:files][:hist].nil? %>
  <% when :aai_distances %>
    <p>Average Amino acid Identity between genomes.</p>
    <%= plot_distances(res.file_path(:hist), {},
        {height:300, title:'Distribution of AAI values'}) unless
        res.data[:files][:hist].nil? %>
  <% when :ani_distances %>
    <p>Average Nucleotide Identity between genomes with AAI &ge; 90%.</p>
    <%= plot_distances(res.file_path(:hist), {},
        {height:300, title:'Distribution of ANI values'}) unless
        res.data[:files][:hist].nil? %>
  <% when :clade_finding %>
    <p>
      <%= render partial: 'shared/results/clade_tree',
           locals: { res: res, job: key, project: proj } %>
      <%= render partial: 'shared/results/proposed_clades',
           locals: { res: res, job: key, project: proj } %>
    </p>
  <% when :subclades %>
    <p>
      <%= render partial: 'shared/results/clade_tree',
           locals: { res: res, job: key, project: proj } %>
    </p>
  <% when :ogs %>
    <p>
      <%= render partial: 'shared/results/ogs',
           locals: { res: res, job: key, project: proj } %>
    </p>
  <% end %>
  <% unless res[:stats].nil? or res[:stats].empty? %>
    <p>
    <% res[:stats].each do |k,v| %>
      <% v = v.is_a?(Array) ? [v[0], " #{v[1]}"] : [v, ''] %>
      <b><%= k.to_s.unmiga_name
            .sub(/^a[an]i$/, &:upcase).sub(/^./, &:upcase) %>:</b>
      <%= number_with_precision(v[0],
            precision: 4, strip_insignificant_zeros: true, delimiter: ',')
            %><%= v[1] %>
      <br/>
    <% end %>
    </p>
  <% end %>
</div>

<div class='result-footer'>
  <i class='glyphicon glyphicon-download' title='downloads'> </i>
  <%=
    res.data[:files].keys.map do |k|
      f = res.file_path(k)
      next unless File.size? f
      link_to(k.to_s.unmiga_name, obj.is_a?(Project) ?
        project_result_path(obj.id, key, k) :
        obj.is_a?(MiGA::Dataset) ?
        reference_dataset_result_path(proj.id, obj.name, key, k) :
        query_dataset_result_path(obj.id, key, k),
        { rel: 'tooltip', target: '_blank',
          title: Dir.exist?(f) ? 'Folder' : number_to_human_size(File.size f)})
    end.compact.
      to_sentence(two_words_connector: ' or ', last_word_connector: ', or ').
      html_safe
  %>
  <br/>
  <i class='glyphicon glyphicon-info-sign' title='downloads'> </i>
  <%= link_to 'Learn more',
    'http://manual.microbial-genomes.org/part5/workflow.html#' +
      key.to_s.tr('_','-') %>
  <div class='timestamp'><%= time_ago_in_words res.data[:created] %> ago</div>
</div>
</div>
<%= info_msg_content %>
<% end %>