Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log when makeblastdb is provided a dir without fastas #690

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions bin/sequenceserver
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,9 @@ begin
end

if make_blast_databases?
if SequenceServer.makeblastdb.any_to_format_or_reformat?
if SequenceServer.makeblastdb.no_fastas?
puts "Couldn't find any FASTA files in #{SequenceServer.config[:database_dir]}."
elsif SequenceServer.makeblastdb.any_to_format_or_reformat?
puts
puts <<~MSG
SequenceServer has scanned your databases directory and will now offer
Expand All @@ -380,7 +382,7 @@ begin
print '>> '
response = STDIN.gets.to_s.strip
SequenceServer.makeblastdb.run unless response =~ /^[n]$/i
else
else
puts "All FASTA files in #{SequenceServer.config[:database_dir]} " \
'are formatted.'
end
Expand Down
34 changes: 24 additions & 10 deletions lib/sequenceserver/makeblastdb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def any_to_format_or_reformat?
any_to_format? || any_to_reformat?
end

def no_fastas?
probably_fastas.empty?
end

# Runs makeblastdb on each file in `fastas_to_format` and
# `fastas_to_reformat`.
def run
Expand Down Expand Up @@ -107,22 +111,32 @@ def fastas_to_reformat
def fastas_to_format
return @fastas_to_format if defined?(@fastas_to_format)

@fastas_to_format = []
formatted_fasta_paths = formatted_fastas.map { |f| f[0] }
fasta_paths_to_format = probably_fastas - formatted_fasta_paths

@fastas_to_format = fasta_paths_to_format.map do |path|
[
path,
make_db_title(path),
guess_sequence_type_in_fasta(path)
]
end

@fastas_to_format
end

def probably_fastas
return @probably_fastas if defined?(@probably_fastas)

@probably_fastas = []

# Add a trailing slash to database_dir - Find.find doesn't work as
# expected without the trailing slash if database_dir is a symlink
# inside a docker container.
Find.find(database_dir + '/') do |path|
next if File.directory?(path)
next unless probably_fasta?(path)
next if formatted_fastas.any? { |f| f[0] == path }

@fastas_to_format << [path,
make_db_title(path),
guess_sequence_type_in_fasta(path)]
@probably_fastas << path if probably_fasta?(path)
end

@fastas_to_format
@probably_fastas
end

# Runs `blastdbcmd` to determine formatted FASTA files in the database
Expand Down
15 changes: 15 additions & 0 deletions spec/makeblastdb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ module SequenceServer
expect(makeblastdb.send(:multipart_database_name?, sample_name3)).to be_truthy
end

describe '#no_fastas?' do
it 'returns true if no FASTA files are found' do
makeblastdb = SequenceServer::MAKEBLASTDB.new(database_dir_without_parse_seqids)
expect(makeblastdb.no_fastas?).to be_truthy
end

it 'returns false if FASTA files are found' do
makeblastdb = SequenceServer::MAKEBLASTDB.new(database_dir_unformatted)
expect(makeblastdb.no_fastas?).to be_falsey

makeblastdb = SequenceServer::MAKEBLASTDB.new(database_dir_v4)
expect(makeblastdb.no_fastas?).to be_falsey
end
end

describe '#make_blast_database' do
context 'duplicate sequence ids' do
before do
Expand Down