From 43f0c993957ea9e771607d7880fdf308e87f9784 Mon Sep 17 00:00:00 2001 From: tibvdm Date: Tue, 16 Apr 2024 01:22:34 +0200 Subject: [PATCH] test --- app/controllers/mpa/pept2data_controller.rb | 38 +++---------------- .../mpa/pept2data/pept2data.json.jbuilder | 2 +- 2 files changed, 6 insertions(+), 34 deletions(-) diff --git a/app/controllers/mpa/pept2data_controller.rb b/app/controllers/mpa/pept2data_controller.rb index 34f6790..3505abf 100644 --- a/app/controllers/mpa/pept2data_controller.rb +++ b/app/controllers/mpa/pept2data_controller.rb @@ -4,23 +4,26 @@ class Mpa::Pept2dataController < Mpa::MpaController def pept2data peptides = params[:peptides] || [] missed = params[:missed] || false - @equate_il = params[:equate_il].nil? ? true : params[:equate_il] == 'true' + equate_il = params[:equate_il].nil? ? true : params[:equate_il] == 'true' @response = Hash.new # Request the suffix array search service - search_results = search(peptides, @equate_il) + search_results = search(peptides, equate_il) + # Collect all lca's to look up the lineages taxa = [] search_results["result"].each do |result| taxa.append(result["lca"]) 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"], @@ -32,36 +35,5 @@ def pept2data } } end - - # proteins = Set.new - # search_results["result"].each do |result| - # proteins.merge(result['uniprot_accessions']) - # end - - # entries = UniprotEntry.where(uniprot_accession_number: proteins.to_a.uniq) - - # # Convert the retrieved entries to a hash (for easy retrieval) - # accession_to_protein = Hash.new - # entries.each do |entry| - # accession_to_protein[entry.uniprot_accession_number] = entry - # end - - # taxa = [] - # search_results["result"].each do |result| - # uniprot_entries = result["uniprot_accessions"].map { |acc| accession_to_protein[acc] } - # result["fa"] = UniprotEntry.summarize_fa(uniprot_entries) - # @response[result["sequence"]] = result - # taxa.append(result["lca"]) - # end - - # looked_up_lineages = Lineage.find(taxa) - # looked_up_lineages.each do |lineage| - # @lineages[lineage.taxon_id] = lineage.to_a_idx - # end - - # @response.each do |_, entry| - - # entry["lineage"] = @lineages[entry["lca"].to_i] - # end end end diff --git a/app/views/mpa/pept2data/pept2data.json.jbuilder b/app/views/mpa/pept2data/pept2data.json.jbuilder index 596cac5..fe6953b 100644 --- a/app/views/mpa/pept2data/pept2data.json.jbuilder +++ b/app/views/mpa/pept2data/pept2data.json.jbuilder @@ -1 +1 @@ -json.peptides(@response) +json.peptides(@response.values)