Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tibvdm committed Jun 19, 2024
1 parent 5eecb4c commit a472840
Show file tree
Hide file tree
Showing 36 changed files with 324 additions and 546 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@

# Ignore master key for decrypting credentials and more.
/config/master.key

/coverage
.idea/
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ group :development, :test do
#Codecov for coverage processing
gem 'simplecov'
gem 'simplecov-cobertura'

# Mocking HTTP requests to third parties.
gem 'webmock'
end

group :development do
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ GEM
capistrano (~> 3.0)
sshkit (~> 1.2)
concurrent-ruby (1.2.2)
crack (0.4.5)
rexml
crass (1.0.6)
debug (1.6.2)
irb (>= 1.3.6)
Expand All @@ -98,6 +100,7 @@ GEM
faraday-net_http (3.0.0)
globalid (1.1.0)
activesupport (>= 5.0)
hashdiff (1.0.1)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
io-console (0.5.11)
Expand Down Expand Up @@ -236,6 +239,10 @@ GEM
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.3.0)
webmock (3.19.1)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
Expand Down Expand Up @@ -266,6 +273,7 @@ DEPENDENCIES
simplecov-cobertura
stathat (~> 0.1.7)
tzinfo-data
webmock

RUBY VERSION
ruby 3.1.2p20
Expand Down
10 changes: 1 addition & 9 deletions app/controllers/api/api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,10 @@ def set_query
end
end

# prepares the sequences query
def set_sequences
rel_name = @equate_il ? :peptides : :original_peptides
@sequences = Sequence.joins(rel_name => :uniprot_entry)
.where(sequence: @input)
end

# Reorders the results according to the input order
def filter_input_order
@input_order.select! do |s|
key = @equate_il ? s.tr('I', 'L') : s
@result.key? key
@result.key? s
end
end

Expand Down
9 changes: 0 additions & 9 deletions app/controllers/mpa/pept2data_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
class Mpa::Pept2dataController < Mpa::MpaController
include SuffixArrayHelper

def get_time
Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond)
end

def pept2data
start = get_time

peptides = params[:peptides] || []
missed = params[:missed].nil? ? false : params[:missed]
equate_il = params[:equate_il].nil? ? true : params[:equate_il]
Expand All @@ -32,8 +26,5 @@ def pept2data
Lineage.find(taxa).each do |lineage|
@lineages[lineage.taxon_id] = lineage.to_a_idx
end

@timings = Hash.new
@timings["total"] = get_time - start
end
end
5 changes: 2 additions & 3 deletions app/controllers/private_api/proteins_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def proteins
return
end

puts peptide

# Request the suffix array search service
search_result = search([ peptide ], equate_il).first

Expand All @@ -29,8 +31,6 @@ def proteins
return
end

puts search_result

@lca = search_result["lca"]
@proteins = UniprotEntry
.includes(:taxon)
Expand All @@ -48,7 +48,6 @@ def proteins

# Lineage van de lca ophalen
lca_lineage = Lineage.find(@lca)
puts lca_lineage.inspect
finished = (@lca == 1)
while !finished && lca_lineage.has_next?
next_rank = lca_lineage.next_t
Expand Down
7 changes: 3 additions & 4 deletions app/views/api/pept2ec/pept2ec.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
json.array! @input_order do |peptide|
seq_index = @equate_il ? peptide.tr('I', 'L') : peptide
if @result.key? seq_index
if @result.key? peptide
json.peptide peptide
json.total_protein_count @result[seq_index][:total]
json.ec(@result[seq_index][:ec].sort_by { |v| -v[:protein_count] })
json.total_protein_count @result[peptide][:total]
json.ec(@result[peptide][:ec].sort_by { |v| -v[:protein_count] })
end
end
11 changes: 5 additions & 6 deletions app/views/api/pept2funct/pept2funct.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
json.array! @input_order do |peptide|
seq_index = @equate_il ? peptide.tr('I', 'L') : peptide
if @result.key? seq_index
if @result.key? peptide
json.peptide peptide
json.total_protein_count @result[seq_index][:total]
json.ec(@result[seq_index][:ec].sort_by { |value| -value[:protein_count] })
json.partial! partial: 'api/pept2go', locals: { data: @result[seq_index][:go] }
json.partial! partial: 'api/pept2interpro', locals: { data: @result[seq_index][:ipr] }
json.total_protein_count @result[peptide][:total]
json.ec(@result[peptide][:ec].sort_by { |value| -value[:protein_count] })
json.partial! partial: 'api/pept2go', locals: { data: @result[peptide][:go] }
json.partial! partial: 'api/pept2interpro', locals: { data: @result[peptide][:ipr] }
end
end
7 changes: 3 additions & 4 deletions app/views/api/pept2go/pept2go.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
json.array! @input_order do |peptide|
seq_index = @equate_il ? peptide.tr('I', 'L') : peptide
if @result.key? seq_index
if @result.key? peptide
json.peptide peptide
json.total_protein_count @result[seq_index][:total]
json.partial! partial: 'api/pept2go', locals: { data: @result[seq_index][:go] }
json.total_protein_count @result[peptide][:total]
json.partial! partial: 'api/pept2go', locals: { data: @result[peptide][:go] }
end
end
7 changes: 3 additions & 4 deletions app/views/api/pept2interpro/pept2interpro.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
json.array! @input_order do |peptide|
seq_index = @equate_il ? peptide.tr('I', 'L') : peptide
if @result.key? seq_index
if @result.key? peptide
json.peptide peptide
json.total_protein_count @result[seq_index][:total]
json.partial! partial: 'api/pept2interpro', locals: { data: @result[seq_index][:ipr] }
json.total_protein_count @result[peptide][:total]
json.partial! partial: 'api/pept2interpro', locals: { data: @result[peptide][:ipr] }
end
end
5 changes: 2 additions & 3 deletions app/views/api/pept2lca/pept2lca.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
json.array! @input_order do |peptide|
seq_index = @equate_il ? peptide.tr('I', 'L') : peptide
if @result.key? seq_index
if @result.key? peptide
json.peptide peptide
json.partial! partial: 'api/pept2lca', locals: { data: @result[seq_index] }
json.partial! partial: 'api/pept2lca', locals: { data: @result[peptide] }
end
end
7 changes: 3 additions & 4 deletions app/views/api/pept2taxa/pept2taxa.json.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<%=
Oj.dump(
@input_order.map do |k|
seq_index = @equate_il ? k.gsub(/I/,'L') : k
v = @result[seq_index]
@input_order.map do |peptide|
v = @result[peptide]
v.map do |p|
res = { "peptide" => k,
res = { "peptide" => peptide,
"taxon_id" => p.id,
"taxon_name" => p.name,
"taxon_rank" => p.rank,
Expand Down
13 changes: 6 additions & 7 deletions app/views/api/peptinfo/peptinfo.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
json.array! @input_order do |peptide|
seq_index = @equate_il ? peptide.tr('I', 'L') : peptide
if @result.key? seq_index
if @result.key? peptide
json.peptide peptide
json.total_protein_count @result[seq_index][:total]
json.ec(@result[seq_index][:ec].sort_by { |value| -value[:protein_count] })
json.partial! partial: 'api/pept2go', locals: { data: @result[seq_index][:go] }
json.partial! partial: 'api/pept2interpro', locals: { data: @result[seq_index][:ipr] }
json.partial! partial: 'api/pept2lca', locals: { data: @result[seq_index][:lca] }
json.total_protein_count @result[peptide][:total]
json.ec(@result[peptide][:ec].sort_by { |value| -value[:protein_count] })
json.partial! partial: 'api/pept2go', locals: { data: @result[peptide][:go] }
json.partial! partial: 'api/pept2interpro', locals: { data: @result[peptide][:ipr] }
json.partial! partial: 'api/pept2lca', locals: { data: @result[peptide][:lca] }
end
end
1 change: 0 additions & 1 deletion app/views/mpa/pept2data/pept2data.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ json.peptides @response do |peptide|
json.data peptide["fa"]["data"]
end
end
json.timings @timings
1 change: 1 addition & 0 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ development:
# Do not set this db to the same as development or production.
test:
<<: *default
username: unipept
database: unipept_test
url: <%= ENV['TEST_DATABASE_URL'] || ENV['DATABASE_URL'] %>

Expand Down
16 changes: 15 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions test/controllers/api/pept2ec_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class Api::Pept2ecControllerTest < ActionController::TestCase
teardown :assert_success

test 'should get pept2ec' do
stub_http_request! 'test/fixtures/index/response.json'

@expected = '[
{"peptide":"AAIER","total_protein_count":3,"ec":[]},
{"peptide":"AAILER","total_protein_count":1,"ec":[{"ec_number":"4.2.1.11","protein_count":1}]}
Expand All @@ -13,6 +15,8 @@ class Api::Pept2ecControllerTest < ActionController::TestCase
end

test 'should get pept2ec with il' do
stub_http_request! 'test/fixtures/index/response_equate.json'

@expected = '[
{"peptide":"AAIER","total_protein_count":22,"ec":[{"ec_number":"2.7.11.1","protein_count":4}]},
{"peptide":"AAILER","total_protein_count":0,"ec":[]}
Expand All @@ -22,6 +26,8 @@ class Api::Pept2ecControllerTest < ActionController::TestCase
end

test 'should get pept2ec with extra' do
stub_http_request! 'test/fixtures/index/response.json'

@expected = '[
{"peptide":"AAIER","total_protein_count":3,"ec":[]},
{"peptide":"AAILER","total_protein_count":1,"ec":[{"ec_number":"4.2.1.11","protein_count":1,"name":"Some Enzyme3"}]}
Expand All @@ -31,6 +37,8 @@ class Api::Pept2ecControllerTest < ActionController::TestCase
end

test 'should get pept2ec with extra and il' do
stub_http_request! 'test/fixtures/index/response_equate.json'

@expected = '[
{"peptide":"AAIER","total_protein_count":22,"ec":[{"ec_number":"2.7.11.1","protein_count":4,"name":"Some Enzyme2"}]},
{"peptide":"AAILER","total_protein_count":0,"ec":[]}
Expand Down
12 changes: 12 additions & 0 deletions test/controllers/api/pept2funct_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class Api::Pept2functControllerTest < ActionController::TestCase
teardown :assert_success

test 'should get pept2funct' do
stub_http_request! 'test/fixtures/index/response.json'

@expected = '[
{"peptide":"AAIER","total_protein_count":3,"ec":[],"go":[{"go_term":"GO:0051301","protein_count":3},{"go_term":"GO:0005525","protein_count":3},{"go_term":"GO:0046872","protein_count":3},{"go_term":"GO:0007049","protein_count":3}],"ipr":[]},
{"peptide":"AAILER","total_protein_count":1,"ec":[{"ec_number":"4.2.1.11","protein_count":1}],"go":[{"go_term":"GO:0005576","protein_count":1},{"go_term":"GO:0000287","protein_count":1},{"go_term":"GO:0004634","protein_count":1},{"go_term":"GO:0000015","protein_count":1},{"go_term":"GO:0006096","protein_count":1},{"go_term":"GO:0009986","protein_count":1}],"ipr":[{"code":"IPR000169","protein_count":1}]}
Expand All @@ -13,6 +15,8 @@ class Api::Pept2functControllerTest < ActionController::TestCase
end

test 'should get pept2funct with il' do
stub_http_request! 'test/fixtures/index/response_equate.json'

@expected = '[
{"peptide":"AAIER","total_protein_count":22,"ec":[{"ec_number":"2.7.11.1","protein_count":4}],"go":[{"go_term":"GO:0004674","protein_count":1},{"go_term":"GO:0005634","protein_count":1},{"go_term":"GO:0005524","protein_count":1},{"go_term":"GO:0016301","protein_count":1}],"ipr":[{"code":"IPR000169","protein_count":1}]},
{"peptide":"AAILER","total_protein_count":0,"ec":[],"go":[],"ipr":[]}
Expand All @@ -22,6 +26,8 @@ class Api::Pept2functControllerTest < ActionController::TestCase
end

test 'should get pept2funct with extra' do
stub_http_request! 'test/fixtures/index/response.json'

@expected = '[
{"peptide":"AAIER","total_protein_count":3,"ec":[],"go":[{"go_term":"GO:0051301","protein_count":3,"name":"some function 9"},{"go_term":"GO:0005525","protein_count":3,"name":"some function 10"},{"go_term":"GO:0046872","protein_count":3,"name":"some function 11"},{"go_term":"GO:0007049","protein_count":3,"name":"some function 12"}],"ipr":[]},
{"peptide":"AAILER","total_protein_count":1,"ec":[{"ec_number":"4.2.1.11","protein_count":1,"name":"Some Enzyme3"}],"go":[{"go_term":"GO:0005576","protein_count":1,"name":"some function 16"},{"go_term":"GO:0000287","protein_count":1,"name":"some function 17"},{"go_term":"GO:0004634","protein_count":1,"name":"some function 18"},{"go_term":"GO:0000015","protein_count":1,"name":"some function 19"},{"go_term":"GO:0006096","protein_count":1,"name":"some function 20"},{"go_term":"GO:0009986","protein_count":1,"name":"some function 21"}],"ipr":[{"code":"IPR000169","protein_count":1,"name":"Cysteine peptidase, cysteine active site","type":"Active_site"}]}
Expand All @@ -31,6 +37,8 @@ class Api::Pept2functControllerTest < ActionController::TestCase
end

test 'should get pept2funct with domains' do
stub_http_request! 'test/fixtures/index/response.json'

@expected = '[
{"peptide":"AAIER","total_protein_count":3,"ec":[],"go":[{"molecular function":[{"go_term":"GO:0051301","protein_count":3},{"go_term":"GO:0007049","protein_count":3}]},{"cellular component":[{"go_term":"GO:0005525","protein_count":3}]},{"biological process":[{"go_term":"GO:0046872","protein_count":3}]}],"ipr":[]},
{"peptide":"AAILER","total_protein_count":1,"ec":[{"ec_number":"4.2.1.11","protein_count":1}],"go":[{"cellular component":[{"go_term":"GO:0005576","protein_count":1},{"go_term":"GO:0009986","protein_count":1}]},{"molecular function":[{"go_term":"GO:0000287","protein_count":1},{"go_term":"GO:0000015","protein_count":1}]},{"biological process":[{"go_term":"GO:0004634","protein_count":1},{"go_term":"GO:0006096","protein_count":1}]}],"ipr":[{"Active_site":[{"code":"IPR000169","protein_count":1}]}]}
Expand All @@ -40,6 +48,8 @@ class Api::Pept2functControllerTest < ActionController::TestCase
end

test 'should get pept2funct with extra and domains' do
stub_http_request! 'test/fixtures/index/response.json'

@expected = '[
{"peptide":"AAIER","total_protein_count":3,"ec":[],"go":[{"molecular function":[{"go_term":"GO:0051301","protein_count":3,"name":"some function 9"},{"go_term":"GO:0007049","protein_count":3,"name":"some function 12"}]},{"cellular component":[{"go_term":"GO:0005525","protein_count":3,"name":"some function 10"}]},{"biological process":[{"go_term":"GO:0046872","protein_count":3,"name":"some function 11"}]}],"ipr":[]},
{"peptide":"AAILER","total_protein_count":1,"ec":[{"ec_number":"4.2.1.11","protein_count":1,"name":"Some Enzyme3"}],"go":[{"cellular component":[{"go_term":"GO:0005576","protein_count":1,"name":"some function 16"},{"go_term":"GO:0009986","protein_count":1,"name":"some function 21"}]},{"molecular function":[{"go_term":"GO:0000287","protein_count":1,"name":"some function 17"},{"go_term":"GO:0000015","protein_count":1,"name":"some function 19"}]},{"biological process":[{"go_term":"GO:0004634","protein_count":1,"name":"some function 18"},{"go_term":"GO:0006096","protein_count":1,"name":"some function 20"}]}],"ipr":[{"Active_site":[{"code":"IPR000169","protein_count":1,"name":"Cysteine peptidase, cysteine active site"}]}]}
Expand All @@ -49,6 +59,8 @@ class Api::Pept2functControllerTest < ActionController::TestCase
end

test 'should get pept2funct with extra and domains and il' do
stub_http_request! 'test/fixtures/index/response_equate.json'

@expected = '[
{"peptide":"AAIER","total_protein_count":22,"ec":[{"ec_number":"2.7.11.1","protein_count":4,"name":"Some Enzyme2"}],"go":[{"biological process":[{"go_term":"GO:0004674","protein_count":1,"name":"some function 5"},{"go_term":"GO:0016301","protein_count":1,"name":"some function 8"}]},{"molecular function":[{"go_term":"GO:0005634","protein_count":1,"name":"some function 6"}]},{"cellular component":[{"go_term":"GO:0005524","protein_count":1,"name":"some function 7"}]}],"ipr":[{"Active_site":[{"code":"IPR000169","protein_count":1,"name":"Cysteine peptidase, cysteine active site"}]}]},
{"peptide":"AAILER","total_protein_count":0,"ec":[],"go":[],"ipr":[]}
Expand Down
Loading

0 comments on commit a472840

Please sign in to comment.