Skip to content

Commit db803cd

Browse files
authored
Merge pull request #740 from tadast/tt/readability
Code readability improvements
2 parents 00db003 + fce0c44 commit db803cd

12 files changed

Lines changed: 140 additions & 139 deletions

File tree

lib/sequenceserver/report.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ module SequenceServer
66
# Report is a generic superclass. Programs, like BLAST, must implement their
77
# own report subclass.
88
class Report
9-
class << self
10-
def generate(job)
11-
BLAST::Report.new(job)
12-
end
13-
end
14-
159
# Provide access to global `config` & `logger` services to the report
1610
# objects.
1711
extend Forwardable

lib/sequenceserver/routes.rb

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,24 +116,11 @@ class Routes < Sinatra::Base
116116
halt 404, { error: 'Job not found' }.to_json if job.nil?
117117
halt 202 unless job.done?
118118

119-
report = Report.generate(job)
119+
report = BLAST::Report.new(job)
120120
halt 202 unless report.done?
121121

122-
display_large_result_warning =
123-
SequenceServer.config[:large_result_warning_threshold].to_i.positive? &&
124-
params[:bypass_file_size_warning] != 'true' &&
125-
report.xml_file_size > SequenceServer.config[:large_result_warning_threshold]
126-
127-
if display_large_result_warning
128-
halt 200,
129-
{
130-
user_warning: 'LARGE_RESULT',
131-
download_links: [
132-
{ name: 'Standard Tabular Report', url: "download/#{jid}.std_tsv" },
133-
{ name: 'Full Tabular Report', url: "/download/#{jid}.full_tsv" },
134-
{ name: 'Results in XML', url: "/download/#{jid}.xml" }
135-
]
136-
}.to_json
122+
if display_large_result_warning?(report.xml_file_size)
123+
halt 200, large_result_warning_payload(jid).to_json
137124
end
138125

139126
report.to_json
@@ -315,6 +302,26 @@ def update_searchdata_from_job(searchdata)
315302
end
316303
end
317304

305+
def display_large_result_warning?(xml_file_size)
306+
threshold = SequenceServer.config[:large_result_warning_threshold].to_i
307+
return false unless threshold.positive?
308+
309+
return false if params[:bypass_file_size_warning] == 'true'
310+
311+
xml_file_size > threshold
312+
end
313+
314+
def large_result_warning_payload(jid)
315+
{
316+
user_warning: 'LARGE_RESULT',
317+
download_links: [
318+
{ name: 'Standard Tabular Report', url: "download/#{jid}.std_tsv" },
319+
{ name: 'Full Tabular Report', url: "/download/#{jid}.full_tsv" },
320+
{ name: 'Results in XML', url: "/download/#{jid}.xml" }
321+
]
322+
}
323+
end
324+
318325
helpers do
319326
def root_path_prefix
320327
settings.root_path_prefix.to_s

spec/blast_versions/blast_2.2.30/blast_2.2.30_spec.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ module SequenceServer
88
init
99

1010
describe 'Report' do
11-
hits_report = Report.generate(with_hits)
12-
no_hits_report = Report.generate(no_hits)
11+
hits_report = BLAST::Report.new(with_hits)
12+
no_hits_report = BLAST::Report.new(no_hits)
1313

1414
it 'will return an Array of queries' do
1515
hits_report.queries.should be_a Array
@@ -28,8 +28,8 @@ module SequenceServer
2828
end
2929

3030
describe 'Query' do
31-
hits_report = Report.generate(with_hits)
32-
no_hits_report = Report.generate(no_hits)
31+
hits_report = BLAST::Report.new(with_hits)
32+
no_hits_report = BLAST::Report.new(no_hits)
3333

3434
it 'will return queries with valid length' do
3535
hits_report.queries.first.length.should be_a Integer
@@ -45,8 +45,8 @@ module SequenceServer
4545
end
4646

4747
describe 'Hits' do
48-
hits_report = Report.generate(with_hits)
49-
no_hits_report = Report.generate(no_hits)
48+
hits_report = BLAST::Report.new(with_hits)
49+
no_hits_report = BLAST::Report.new(no_hits)
5050

5151
it 'will have non zero length' do
5252
hits_report.queries.last.hits.first.length.should satisfy { |n| n > 0 }
@@ -68,7 +68,7 @@ module SequenceServer
6868
# Test general features of HSPs. Algorithm specific customizations are
6969
# tested separetly.
7070
describe 'HSPs' do
71-
hits_report = Report.generate(with_hits)
71+
hits_report = BLAST::Report.new(with_hits)
7272

7373
# Currently using all 17 HSP parameters in BLAST Report + 1 to refer to the
7474
# hit object it belongs to.
@@ -138,7 +138,7 @@ module SequenceServer
138138
#
139139
describe 'BLASTN' do
140140
let 'hsp' do
141-
report = Report.generate(Job.fetch('blast_2.2.30/blastn'))
141+
report = BLAST::Report.new(Job.fetch('blast_2.2.30/blastn'))
142142
report.queries.first.hits.last.hsps.first
143143
end
144144

@@ -158,7 +158,7 @@ module SequenceServer
158158

159159
describe 'BLASTP' do
160160
let 'hsp' do
161-
report = Report.generate(Job.fetch('blast_2.2.30/blastp'))
161+
report = BLAST::Report.new(Job.fetch('blast_2.2.30/blastp'))
162162
report.queries.first.hits.last.hsps.first
163163
end
164164

@@ -176,7 +176,7 @@ module SequenceServer
176176

177177
describe 'BLASTX' do
178178
let 'hsp' do
179-
report = Report.generate(Job.fetch('blast_2.2.30/blastx'))
179+
report = BLAST::Report.new(Job.fetch('blast_2.2.30/blastx'))
180180

181181
report.queries.first.hits.last.hsps.first
182182
end
@@ -194,7 +194,7 @@ module SequenceServer
194194

195195
describe 'TBLASTX' do
196196
let 'hsp' do
197-
report = Report.generate(Job.fetch('blast_2.2.30/tblastx'))
197+
report = BLAST::Report.new(Job.fetch('blast_2.2.30/tblastx'))
198198
report.queries.first.hits.last.hsps.first
199199
end
200200

@@ -211,7 +211,7 @@ module SequenceServer
211211

212212
describe 'TBLASTN' do
213213
let 'hsp' do
214-
report = Report.generate(Job.fetch('blast_2.2.30/tblastn'))
214+
report = BLAST::Report.new(Job.fetch('blast_2.2.30/tblastn'))
215215
report.queries.first.hits.last.hsps.first
216216
end
217217

spec/blast_versions/blast_2.2.31/blast_2.2.31_spec.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ module SequenceServer
88
init
99

1010
describe 'Report' do
11-
hits_report = Report.generate(with_hits)
12-
no_hits_report = Report.generate(no_hits)
11+
hits_report = BLAST::Report.new(with_hits)
12+
no_hits_report = BLAST::Report.new(no_hits)
1313

1414
it 'will return an Array of queries' do
1515
hits_report.queries.should be_a Array
@@ -28,8 +28,8 @@ module SequenceServer
2828
end
2929

3030
describe 'Query' do
31-
hits_report = Report.generate(with_hits)
32-
no_hits_report = Report.generate(no_hits)
31+
hits_report = BLAST::Report.new(with_hits)
32+
no_hits_report = BLAST::Report.new(no_hits)
3333

3434
it 'will return queries with valid length' do
3535
hits_report.queries.first.length.should be_a Integer
@@ -45,8 +45,8 @@ module SequenceServer
4545
end
4646

4747
describe 'Hits' do
48-
hits_report = Report.generate(with_hits)
49-
no_hits_report = Report.generate(no_hits)
48+
hits_report = BLAST::Report.new(with_hits)
49+
no_hits_report = BLAST::Report.new(no_hits)
5050

5151
it 'will have non zero length' do
5252
hits_report.queries.last.hits.first.length.should satisfy { |n| n > 0 }
@@ -68,7 +68,7 @@ module SequenceServer
6868
# Test general features of HSPs. Algorithm specific customizations are
6969
# tested separetly.
7070
describe 'HSPs' do
71-
hits_report = Report.generate(with_hits)
71+
hits_report = BLAST::Report.new(with_hits)
7272

7373
# Currently using all 17 HSP parameters in BLAST Report + 1 to refer to the
7474
# hit object it belongs to.
@@ -138,7 +138,7 @@ module SequenceServer
138138
#
139139
describe 'BLASTN' do
140140
let 'hsp' do
141-
report = Report.generate(Job.fetch('blast_2.2.31/blastn'))
141+
report = BLAST::Report.new(Job.fetch('blast_2.2.31/blastn'))
142142
report.queries.first.hits.last.hsps.first
143143
end
144144

@@ -158,7 +158,7 @@ module SequenceServer
158158

159159
describe 'BLASTP' do
160160
let 'hsp' do
161-
report = Report.generate(Job.fetch('blast_2.2.31/blastp'))
161+
report = BLAST::Report.new(Job.fetch('blast_2.2.31/blastp'))
162162
report.queries.first.hits.last.hsps.first
163163
end
164164

@@ -176,7 +176,7 @@ module SequenceServer
176176

177177
describe 'BLASTX' do
178178
let 'hsp' do
179-
report = Report.generate(Job.fetch('blast_2.2.31/blastx'))
179+
report = BLAST::Report.new(Job.fetch('blast_2.2.31/blastx'))
180180

181181
report.queries.first.hits.last.hsps.first
182182
end
@@ -194,7 +194,7 @@ module SequenceServer
194194

195195
describe 'TBLASTX' do
196196
let 'hsp' do
197-
report = Report.generate(Job.fetch('blast_2.2.31/tblastx'))
197+
report = BLAST::Report.new(Job.fetch('blast_2.2.31/tblastx'))
198198
report.queries.first.hits.last.hsps.first
199199
end
200200

@@ -211,7 +211,7 @@ module SequenceServer
211211

212212
describe 'TBLASTN' do
213213
let 'hsp' do
214-
report = Report.generate(Job.fetch('blast_2.2.31/tblastn'))
214+
report = BLAST::Report.new(Job.fetch('blast_2.2.31/tblastn'))
215215
report.queries.first.hits.last.hsps.first
216216
end
217217

spec/blast_versions/blast_2.3.0/blast_2.3.0_spec.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ module SequenceServer
99
init
1010

1111
describe 'Report' do
12-
hits_report = Report.generate(with_hits)
13-
no_hits_report = Report.generate(no_hits)
12+
hits_report = BLAST::Report.new(with_hits)
13+
no_hits_report = BLAST::Report.new(no_hits)
1414

1515
it 'will return an Array of queries' do
1616
hits_report.queries.should be_a Array
@@ -29,8 +29,8 @@ module SequenceServer
2929
end
3030

3131
describe 'Query' do
32-
hits_report = Report.generate(with_hits)
33-
no_hits_report = Report.generate(no_hits)
32+
hits_report = BLAST::Report.new(with_hits)
33+
no_hits_report = BLAST::Report.new(no_hits)
3434

3535
it 'will return queries with valid length' do
3636
hits_report.queries.first.length.should be_a Integer
@@ -46,8 +46,8 @@ module SequenceServer
4646
end
4747

4848
describe 'Hits' do
49-
hits_report = Report.generate(with_hits)
50-
no_hits_report = Report.generate(no_hits)
49+
hits_report = BLAST::Report.new(with_hits)
50+
no_hits_report = BLAST::Report.new(no_hits)
5151

5252
it 'will have non zero length' do
5353
hits_report.queries.last.hits.first.length.should satisfy { |n| n > 0 }
@@ -69,7 +69,7 @@ module SequenceServer
6969
# Test general features of HSPs. Algorithm specific customizations are
7070
# tested separetly.
7171
describe 'HSPs' do
72-
hits_report = Report.generate(with_hits)
72+
hits_report = BLAST::Report.new(with_hits)
7373

7474
# Currently using all 17 HSP parameters in BLAST Report + 1 to refer to the
7575
# hit object it belongs to.
@@ -139,7 +139,7 @@ module SequenceServer
139139
#
140140
describe 'BLASTN' do
141141
let 'hsp' do
142-
report = Report.generate(Job.fetch('blast_2.3.0/blastn'))
142+
report = BLAST::Report.new(Job.fetch('blast_2.3.0/blastn'))
143143
report.queries.first.hits.last.hsps.first
144144
end
145145

@@ -159,7 +159,7 @@ module SequenceServer
159159

160160
describe 'BLASTP' do
161161
let 'hsp' do
162-
report = Report.generate(Job.fetch('blast_2.3.0/blastp'))
162+
report = BLAST::Report.new(Job.fetch('blast_2.3.0/blastp'))
163163
report.queries.first.hits.last.hsps.first
164164
end
165165

@@ -177,7 +177,7 @@ module SequenceServer
177177

178178
describe 'BLASTX' do
179179
let 'hsp' do
180-
report = Report.generate(Job.fetch('blast_2.3.0/blastx'))
180+
report = BLAST::Report.new(Job.fetch('blast_2.3.0/blastx'))
181181

182182
report.queries.first.hits.last.hsps.first
183183
end
@@ -195,7 +195,7 @@ module SequenceServer
195195

196196
describe 'TBLASTX' do
197197
let 'hsp' do
198-
report = Report.generate(Job.fetch('blast_2.3.0/tblastx'))
198+
report = BLAST::Report.new(Job.fetch('blast_2.3.0/tblastx'))
199199
report.queries.first.hits.last.hsps.first
200200
end
201201

@@ -212,7 +212,7 @@ module SequenceServer
212212

213213
describe 'TBLASTN' do
214214
let 'hsp' do
215-
report = Report.generate(Job.fetch('blast_2.3.0/tblastn'))
215+
report = BLAST::Report.new(Job.fetch('blast_2.3.0/tblastn'))
216216
report.queries.first.hits.last.hsps.first
217217
end
218218

0 commit comments

Comments
 (0)