Skip to content

Commit e647828

Browse files
committed
Validate fasta sequence ID before checking for its inclusion in the DB
1 parent 7139798 commit e647828

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/sequenceserver/database.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ def retrieve(accession, coords = nil)
5252
# Returns true if the database contains the given sequence id.
5353
# Returns false otherwise.
5454
def include?(id)
55+
raise ArgumentError, "Invalid sequence id: #{id}" unless id =~ SequenceServer::BLAST::VALID_SEQUENCE_ID
56+
5557
cmd = "blastdbcmd -entry '#{id}' -db #{name}"
5658
sys(cmd, path: config[:bin]) rescue false
5759
end

spec/database_spec.rb

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,24 @@ module SequenceServer
2727
Database[id].first
2828
end
2929

30-
it 'knows if a given accession is in the database or not' do
31-
solenopsis_protein_database.include?('SI2.2.0_06267').should be_truthy
30+
describe '#include?' do
31+
it 'knows if a given accession is present in the database' do
32+
expect(solenopsis_protein_database).to include('SI2.2.0_06267')
33+
end
34+
35+
it 'knows if a given accession is absent in the database' do
36+
expect(solenopsis_protein_database).not_to include('LOL.2.0_404')
37+
end
38+
39+
it 'validates the id' do
40+
expect do
41+
solenopsis_protein_database.include?("';hi")
42+
end.to raise_error(ArgumentError, "Invalid sequence id: ';hi")
43+
end
44+
end
45+
46+
describe '#retrieve' do
47+
3248
end
3349
end
3450
end

0 commit comments

Comments
 (0)