From 677d26e9beb8aade214d7ec918dffc5195b059a4 Mon Sep 17 00:00:00 2001 From: Pieter Verschaffelt Date: Wed, 28 Sep 2022 10:29:44 +0200 Subject: [PATCH 1/8] Add new pept2filtered endpoint --- app/controllers/api/api_controller.rb | 2 -- app/controllers/mpa_controller.rb | 33 ++++++++++++++--------- app/models/lineage.rb | 5 ++++ app/views/mpa/pept2filtered.json.jbuilder | 4 +++ config/routes.rb | 7 +++++ 5 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 app/views/mpa/pept2filtered.json.jbuilder diff --git a/app/controllers/api/api_controller.rb b/app/controllers/api/api_controller.rb index 36020c5..c60ede5 100644 --- a/app/controllers/api/api_controller.rb +++ b/app/controllers/api/api_controller.rb @@ -264,9 +264,7 @@ def taxa2tree # param[names]: "true" or "false", Include the lineage names def taxonomy @result = @query.where(id: @input) - puts @result.inspect @result = Hash[@result.map { |t| [t.id, t] }] - puts @result.inspect @input_order = @input.select { |i| @result.key? i.to_i } @result = @input_order.map { |i| @result[i.to_i] } respond_with(@result) diff --git a/app/controllers/mpa_controller.rb b/app/controllers/mpa_controller.rb index 2f2e797..c283025 100644 --- a/app/controllers/mpa_controller.rb +++ b/app/controllers/mpa_controller.rb @@ -1,17 +1,7 @@ class MpaController < HandleOptionsController - before_action :set_headers, only: %i[pept2data] - before_action :default_format_json, except: ['analyze'] - skip_before_action :verify_authenticity_token - - def analyze - @header_class = 'MPA' - @title = 'Metaproteomics analysis result' - @peptides = (params[:qs] || '') - @name = params[:search_name] - @il = params[:il].present? - @dupes = params[:dupes].present? - @missed = params[:missed].present? - end + before_action :set_headers, only: %i[pept2data, pept2gm] + before_action :default_format_json + skip_before_action :verify_authenticity_token, :raise => false def pept2data peptides = params[:peptides] || [] @@ -34,6 +24,23 @@ def pept2data end end + def pept2filtered + peptides = params[:peptides] || [] + missed = params[:missed] || false + taxa_filter_ids = (params[:taxa] || []).map(&:to_i) + + @equate_il = params[:equate_il].nil? ? true : params[:equate_il] + + @sequences = Sequence + .joins(peptides: [:uniprot_entry]) + .includes(peptides: [:uniprot_entry]) + .where(sequence: peptides) + .where(uniprot_entry: { taxon_id: taxa_filter_ids }) + .uniq + + @seq_entries = @sequences.map { |s| [s, s.peptides.map { |p| p.uniprot_entry }.select { |e| taxa_filter_ids.include? e.taxon_id }] } + end + private def default_format_json diff --git a/app/models/lineage.rb b/app/models/lineage.rb index 0957576..ce173e8 100644 --- a/app/models/lineage.rb +++ b/app/models/lineage.rb @@ -139,6 +139,11 @@ def to_a array.map { |x| x.nil? ? '' : x.name } end + def to_a_idx + array = ORDER_T.map { |rank| send(rank) } + array.map { |x| x.nil? ? nil : x.id } + end + def self.ranks ORDER end diff --git a/app/views/mpa/pept2filtered.json.jbuilder b/app/views/mpa/pept2filtered.json.jbuilder new file mode 100644 index 0000000..a17459d --- /dev/null +++ b/app/views/mpa/pept2filtered.json.jbuilder @@ -0,0 +1,4 @@ +json.peptides @seq_entries do |seq_entry| + json.sequence seq_entry[0].sequence + json.taxa seq_entry[1].map { |e| e.taxon_id } +end diff --git a/config/routes.rb b/config/routes.rb index 5c0507a..2da3e05 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,6 +10,12 @@ match "metadata", via: [:get, :post], :to => "private_api#metadata" end + scope :mpa, as: 'mpa' do + match '/*path', via: [:options], to: 'handle_options#handle_options_request' + match 'pept2data', via: %i[get post], to: 'mpa#pept2data' + match 'pept2filtered', via: %i[get post], to: 'mpa#pept2filtered' + end + namespace :api, path: 'api/v1' do match 'pept2taxa' => "api#pept2taxa", via: %i[get post] match 'pept2lca' => "api#pept2lca", via: %i[get post] @@ -34,6 +40,7 @@ match 'pept2ec' => 'api#pept2ec', via: %i[get post] match 'pept2go' => 'api#pept2go', via: %i[get post] match 'pept2interpro' => 'api#pept2interpro', via: %i[get post] + match 'pept2gm' => 'api#pept2gm', via: %i[get post] match 'taxa2tree' => 'api#taxa2tree', via: %i[get post] match 'peptinfo' => 'api#peptinfo', via: %i[get post] match 'taxonomy' => 'api#taxonomy', via: %i[get post] From e35d26c8a464f22fd60a3b79da0f058dcfe58ee7 Mon Sep 17 00:00:00 2001 From: Pieter Verschaffelt Date: Fri, 30 Sep 2022 15:07:59 +0200 Subject: [PATCH 2/8] Fix rubocop linter errors --- app/controllers/mpa_controller.rb | 14 +++++++------- app/views/mpa/pept2filtered.json.jbuilder | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/controllers/mpa_controller.rb b/app/controllers/mpa_controller.rb index 2a41fc7..df67e81 100644 --- a/app/controllers/mpa_controller.rb +++ b/app/controllers/mpa_controller.rb @@ -26,19 +26,19 @@ def pept2data def pept2filtered peptides = params[:peptides] || [] - missed = params[:missed] || false + # missed = params[:missed] || false taxa_filter_ids = (params[:taxa] || []).map(&:to_i) @equate_il = params[:equate_il].nil? ? true : params[:equate_il] @sequences = Sequence - .joins(peptides: [:uniprot_entry]) - .includes(peptides: [:uniprot_entry]) - .where(sequence: peptides) - .where(uniprot_entry: { taxon_id: taxa_filter_ids }) - .uniq + .joins(peptides: [:uniprot_entry]) + .includes(peptides: [:uniprot_entry]) + .where(sequence: peptides) + .where(uniprot_entry: { taxon_id: taxa_filter_ids }) + .uniq - @seq_entries = @sequences.map { |s| [s, s.peptides.map { |p| p.uniprot_entry }.select { |e| taxa_filter_ids.include? e.taxon_id }] } + @seq_entries = @sequences.map { |s| [s, s.peptides.map(&:uniprot_entry).select { |e| taxa_filter_ids.include? e.taxon_id }] } end private diff --git a/app/views/mpa/pept2filtered.json.jbuilder b/app/views/mpa/pept2filtered.json.jbuilder index a17459d..58adec0 100644 --- a/app/views/mpa/pept2filtered.json.jbuilder +++ b/app/views/mpa/pept2filtered.json.jbuilder @@ -1,4 +1,4 @@ json.peptides @seq_entries do |seq_entry| json.sequence seq_entry[0].sequence - json.taxa seq_entry[1].map { |e| e.taxon_id } + json.taxa seq_entry[1].map(&:taxon_id) end From 8199b57b3fbceea262744bbb4d9f32f73f22f102 Mon Sep 17 00:00:00 2001 From: Pieter Verschaffelt Date: Fri, 30 Sep 2022 15:18:31 +0200 Subject: [PATCH 3/8] Cleanup routes --- config/routes.rb | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 81b8857..314c552 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,6 +16,10 @@ match 'pept2filtered', via: %i[get post], to: 'mpa#pept2filtered' end + scope :datasets, as: 'datasets' do + match 'sampledata', via: [:post], to: 'datasets#sampledata' + end + namespace :api, path: 'api/v1' do match 'pept2taxa' => "api#pept2taxa", via: %i[get post] match 'pept2lca' => "api#pept2lca", via: %i[get post] @@ -46,13 +50,4 @@ match 'taxonomy' => 'api#taxonomy', via: %i[get post] match 'messages' => 'api#messages', via: %i[get post] end - - scope :mpa, as: 'mpa' do - match '/*path', via: [:options], to: 'handle_options#handle_options_request' - match 'pept2data', via: %i[get post], to: 'mpa#pept2data' - end - - scope :datasets, as: 'datasets' do - match 'sampledata', via: [:post], to: 'datasets#sampledata' - end end From b29ce23bd34b5f8e1204d9f6e5dde9fcc8948007 Mon Sep 17 00:00:00 2001 From: Pieter Verschaffelt Date: Fri, 30 Sep 2022 15:49:19 +0200 Subject: [PATCH 4/8] Add functional annotations to pept2filtered --- app/controllers/mpa_controller.rb | 11 +++++++++++ app/views/mpa/pept2filtered.json.jbuilder | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/app/controllers/mpa_controller.rb b/app/controllers/mpa_controller.rb index df67e81..b5911b6 100644 --- a/app/controllers/mpa_controller.rb +++ b/app/controllers/mpa_controller.rb @@ -38,6 +38,17 @@ def pept2filtered .where(uniprot_entry: { taxon_id: taxa_filter_ids }) .uniq + uniprot_ids = @sequences.map { |s| s.peptides.map(&:uniprot_entry_id) }.flatten.uniq + + @go_terms = GoCrossReference + .where(uniprot_entry_id: uniprot_ids) + + @ec_numbers = EcCrossReference + .where(uniprot_entry_id: uniprot_ids) + + @ipr_entries = InterproCrossReference + .where(uniprot_entry_id: uniprot_ids) + @seq_entries = @sequences.map { |s| [s, s.peptides.map(&:uniprot_entry).select { |e| taxa_filter_ids.include? e.taxon_id }] } end diff --git a/app/views/mpa/pept2filtered.json.jbuilder b/app/views/mpa/pept2filtered.json.jbuilder index 58adec0..6a472d7 100644 --- a/app/views/mpa/pept2filtered.json.jbuilder +++ b/app/views/mpa/pept2filtered.json.jbuilder @@ -1,4 +1,9 @@ json.peptides @seq_entries do |seq_entry| json.sequence seq_entry[0].sequence json.taxa seq_entry[1].map(&:taxon_id) + json.fa do + json.go_terms @go_terms.map(&:go_term_code).uniq + json.ec_numbers(@ec_numbers.map(&:ec_number_code).uniq.map { |ec| "EC:#{ec}" }) + json.interpro_entries @ipr_entries.map(&:interpro_entry_code).uniq + end end From a53c3d47c71298401012c4638672a21e5f1a9483 Mon Sep 17 00:00:00 2001 From: Pieter Verschaffelt Date: Fri, 30 Sep 2022 15:54:27 +0200 Subject: [PATCH 5/8] Add colon after IPR --- app/views/mpa/pept2filtered.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/mpa/pept2filtered.json.jbuilder b/app/views/mpa/pept2filtered.json.jbuilder index 6a472d7..8bdfae4 100644 --- a/app/views/mpa/pept2filtered.json.jbuilder +++ b/app/views/mpa/pept2filtered.json.jbuilder @@ -4,6 +4,6 @@ json.peptides @seq_entries do |seq_entry| json.fa do json.go_terms @go_terms.map(&:go_term_code).uniq json.ec_numbers(@ec_numbers.map(&:ec_number_code).uniq.map { |ec| "EC:#{ec}" }) - json.interpro_entries @ipr_entries.map(&:interpro_entry_code).uniq + json.interpro_entries(@ipr_entries.map(&:interpro_entry_code).uniq.map { |ipr| ipr.sub("IPR", "IPR:") }) end end From 8b24b71f386204b8a5f0acf4e15049287987ba36 Mon Sep 17 00:00:00 2001 From: Pieter Verschaffelt Date: Fri, 30 Sep 2022 15:56:20 +0200 Subject: [PATCH 6/8] Fix linting errors --- app/views/mpa/pept2filtered.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/mpa/pept2filtered.json.jbuilder b/app/views/mpa/pept2filtered.json.jbuilder index 8bdfae4..84b01f9 100644 --- a/app/views/mpa/pept2filtered.json.jbuilder +++ b/app/views/mpa/pept2filtered.json.jbuilder @@ -4,6 +4,6 @@ json.peptides @seq_entries do |seq_entry| json.fa do json.go_terms @go_terms.map(&:go_term_code).uniq json.ec_numbers(@ec_numbers.map(&:ec_number_code).uniq.map { |ec| "EC:#{ec}" }) - json.interpro_entries(@ipr_entries.map(&:interpro_entry_code).uniq.map { |ipr| ipr.sub("IPR", "IPR:") }) + json.interpro_entries(@ipr_entries.map(&:interpro_entry_code).uniq.map { |ipr| ipr.sub('IPR', 'IPR:') }) end end From 14bf77e085a2f498575583749021e36ff0c76682 Mon Sep 17 00:00:00 2001 From: Pieter Verschaffelt Date: Wed, 5 Oct 2022 16:07:24 +0200 Subject: [PATCH 7/8] filter out and remove blanks and uniq the taxa --- app/views/mpa/pept2filtered.json.jbuilder | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/mpa/pept2filtered.json.jbuilder b/app/views/mpa/pept2filtered.json.jbuilder index 84b01f9..40ae871 100644 --- a/app/views/mpa/pept2filtered.json.jbuilder +++ b/app/views/mpa/pept2filtered.json.jbuilder @@ -1,9 +1,9 @@ json.peptides @seq_entries do |seq_entry| json.sequence seq_entry[0].sequence - json.taxa seq_entry[1].map(&:taxon_id) + json.taxa seq_entry[1].map(&:taxon_id).uniq json.fa do json.go_terms @go_terms.map(&:go_term_code).uniq - json.ec_numbers(@ec_numbers.map(&:ec_number_code).uniq.map { |ec| "EC:#{ec}" }) + json.ec_numbers(@ec_numbers.map(&:ec_number_code).reject { |ec| ec.empty? }.uniq.map { |ec| "EC:#{ec}" }) json.interpro_entries(@ipr_entries.map(&:interpro_entry_code).uniq.map { |ipr| ipr.sub('IPR', 'IPR:') }) end end From 3c6fd4e835c8e404ffc857d1ecbf19aa54d533cd Mon Sep 17 00:00:00 2001 From: Pieter Verschaffelt Date: Wed, 16 Nov 2022 10:07:30 +0100 Subject: [PATCH 8/8] Fix linter errors --- app/views/mpa/pept2filtered.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/mpa/pept2filtered.json.jbuilder b/app/views/mpa/pept2filtered.json.jbuilder index 40ae871..b8b3427 100644 --- a/app/views/mpa/pept2filtered.json.jbuilder +++ b/app/views/mpa/pept2filtered.json.jbuilder @@ -3,7 +3,7 @@ json.peptides @seq_entries do |seq_entry| json.taxa seq_entry[1].map(&:taxon_id).uniq json.fa do json.go_terms @go_terms.map(&:go_term_code).uniq - json.ec_numbers(@ec_numbers.map(&:ec_number_code).reject { |ec| ec.empty? }.uniq.map { |ec| "EC:#{ec}" }) + json.ec_numbers(@ec_numbers.map(&:ec_number_code).reject(&:empty?).uniq.map { |ec| "EC:#{ec}" }) json.interpro_entries(@ipr_entries.map(&:interpro_entry_code).uniq.map { |ipr| ipr.sub('IPR', 'IPR:') }) end end