Skip to content

Commit

Permalink
to_set
Browse files Browse the repository at this point in the history
  • Loading branch information
tibvdm committed Apr 22, 2024
1 parent fb489f9 commit 6c389b2
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions app/controllers/mpa/pept2filtered_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Mpa::Pept2filteredController < Mpa::MpaController
include SuffixArrayHelper

def pept2filtered
peptides = params[:peptides] || []
peptides = (params[:peptides] || []).uniq
missed = params[:missed].nil? ? false : params[:missed]
equate_il = params[:equate_il].nil? ? true : params[:equate_il]
cutoff = params[:cutoff] || 1000
Expand All @@ -16,11 +16,18 @@ def pept2filtered
taxa_filter_ids = (params[:taxa] || []).map(&:to_i)

# Request the suffix array search service
@response = search(peptides, equate_il, cutoff).select { |result| !result["cutoff_used"] }.uniq
@response = search(peptides, equate_il, cutoff)
.select { |result| !result["cutoff_used"] }
.each { |result| result["taxa"] = result["taxa"].to_set }

# TODO: we should remove this or use a different approach
@response.each do |result|
result["taxa"] = result["taxa"].select { |taxon_id| taxa_filter_ids.include?(taxon_id) }.uniq
taxa_filter_ids.each_slice(5000) do |taxa_slice|
taxa_slice = Taxon.where(id: taxa_slice).where(valid_taxon: 1).pluck(:id).to_set

next if taxa_slice.empty?

@response.each do |result|
result["taxa"] = result["taxa"].select { |taxon_id| taxa_slice.include?(taxon_id) }.uniq
end
end
end
end

0 comments on commit 6c389b2

Please sign in to comment.