From a20deff4c75486a4b12200f870160f1e7bee0fff Mon Sep 17 00:00:00 2001 From: Pieter Verschaffelt Date: Thu, 10 Aug 2023 10:49:49 +0200 Subject: [PATCH] Add cutoff parameter for pept2filtered endpoint --- app/controllers/mpa_controller.rb | 10 +++++++++- config/database.yml | 1 + config/environments/development.rb | 3 ++- config/environments/production.rb | 3 +++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/controllers/mpa_controller.rb b/app/controllers/mpa_controller.rb index a43e2c2..1c29a9b 100644 --- a/app/controllers/mpa_controller.rb +++ b/app/controllers/mpa_controller.rb @@ -44,6 +44,7 @@ def pept2data def pept2filtered peptides = params[:peptides] || [] + cutoff = params[:cutoff] || 1000 # missed = params[:missed] || false taxa_filter_ids = (params[:taxa] || []).map(&:to_i) @@ -52,11 +53,18 @@ def pept2filtered @seq_entries = {} uniprot_ids = [] + peptides_under_cutoff = Sequence + .joins(:peptides) + .where(sequence: peptides) + .group('sequences.id') + .having('count(peptides.id) < ?', cutoff) + .pluck(:sequence) + taxa_filter_ids.each_slice(5000) do |taxa_slice| sequence_subset = Sequence .joins(peptides: [:uniprot_entry]) .includes(peptides: [:uniprot_entry]) - .where(sequence: peptides) + .where(sequence: peptides_under_cutoff) .where(uniprot_entry: { taxon_id: taxa_slice }) .uniq diff --git a/config/database.yml b/config/database.yml index 1c32715..06f9ee6 100644 --- a/config/database.yml +++ b/config/database.yml @@ -6,6 +6,7 @@ default: &default development: <<: *default + username: unipept database: unipept # setup local port forwarding for this to work host: 127.0.0.1 diff --git a/config/environments/development.rb b/config/environments/development.rb index eeb99ac..85ef47c 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -53,8 +53,9 @@ config.active_record.migration_error = :page_load # Highlight code that triggered database queries in logs. - config.active_record.verbose_query_logs = true + # config.active_record.verbose_query_logs = true + # config.log_level = :info # Raises error for missing translations. # config.i18n.raise_on_missing_translations = true diff --git a/config/environments/production.rb b/config/environments/production.rb index dbbe0ea..04dee56 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -71,6 +71,9 @@ # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new + # Do not log SQL queries in production mode (this can cause the server to go out of disk space). + config.log_level = :info + # Use a different logger for distributed setups. # require "syslog/logger" # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name")