Skip to content

Commit

Permalink
Warn users if one of the input files is empty or invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
milot-mirdita committed Apr 11, 2023
1 parent 3626bdb commit 10e0f1b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/util/createdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ int createdb(int argc, const char **argv, const Command& command) {
progress.updateProgress();
const KSeqWrapper::KSeqEntry &e = kseq->entry;
if (e.name.l == 0) {
Debug(Debug::ERROR) << "Fasta entry " << entries_num << " is invalid\n";
Debug(Debug::ERROR) << "Fasta entry " << numEntriesInCurrFile << " is invalid\n";
EXIT(EXIT_FAILURE);
}

Expand All @@ -199,7 +199,7 @@ int createdb(int argc, const char **argv, const Command& command) {
std::string headerId = Util::parseFastaHeader(header.c_str());
if (headerId.empty()) {
// An identifier is necessary for these two cases, so we should just give up
Debug(Debug::WARNING) << "Cannot extract identifier from entry " << entries_num << "\n";
Debug(Debug::WARNING) << "Cannot extract identifier from entry " << numEntriesInCurrFile << "\n";
}
header.push_back('\n');
}
Expand Down Expand Up @@ -233,7 +233,7 @@ int createdb(int argc, const char **argv, const Command& command) {
if (par.createdbMode == Parameters::SEQUENCE_SPLIT_MODE_SOFT) {
if (e.newlineCount != 1) {
if (e.newlineCount == 0) {
Debug(Debug::WARNING) << "Fasta entry " << entries_num << " has no newline character\n";
Debug(Debug::WARNING) << "Fasta entry " << numEntriesInCurrFile << " has no newline character\n";
} else if (e.newlineCount > 1) {
Debug(Debug::WARNING) << "Multiline fasta can not be combined with --createdb-mode 0\n";
}
Expand Down Expand Up @@ -273,6 +273,11 @@ int createdb(int argc, const char **argv, const Command& command) {
numEntriesInCurrFile++;
header.clear();
}

if (numEntriesInCurrFile == 0) {
Debug(Debug::WARNING) << "File " << sourceName << " is empty or invalid and was ignored\n";
}

delete kseq;
if (filenames.size() > 1 && par.createdbMode == Parameters::SEQUENCE_SPLIT_MODE_SOFT) {
size_t fileSize = FileUtil::getFileSize(filenames[fileIdx].c_str());
Expand Down

0 comments on commit 10e0f1b

Please sign in to comment.