diff --git a/app/controllers/mpa/pept2data_controller.rb b/app/controllers/mpa/pept2data_controller.rb index ebbe39d..07b464c 100644 --- a/app/controllers/mpa/pept2data_controller.rb +++ b/app/controllers/mpa/pept2data_controller.rb @@ -7,6 +7,7 @@ def pept2data equate_il = params[:equate_il].nil? ? true : params[:equate_il] == 'true' @response = Hash.new + @lineages = Hash.new if peptides.empty? return @@ -22,22 +23,10 @@ def pept2data end # Retrieve all lineages at once - @lineages = Hash.new Lineage.find(taxa).each do |lineage| @lineages[lineage.taxon_id] = lineage.to_a_idx end - # Fill the response hash with the search results - search_results["result"].each do |result| - @response[result["sequence"]] = { - sequence: result["sequence"], - lca: result["lca"], - lineage: @lineages[result["lca"].to_i], - fa: { - counts: result["fa"]["counts"], - data: result["fa"]["data"] - } - } - end + @response = search_results["result"] end end diff --git a/app/views/mpa/pept2data/pept2data.json.jbuilder b/app/views/mpa/pept2data/pept2data.json.jbuilder index fe6953b..123fdea 100644 --- a/app/views/mpa/pept2data/pept2data.json.jbuilder +++ b/app/views/mpa/pept2data/pept2data.json.jbuilder @@ -1 +1,9 @@ -json.peptides(@response.values) +json.peptides @response do |peptide| + json.sequence peptide[:sequence] + json.lca peptide[:lca] + json.lineage @lineages[peptide[:lca].to_i] + json.fa do + json.counts peptide[:fa][:counts] + json.data peptide[:fa][:data] + end +end