Skip to content

Commit bc30cee

Browse files
committed
input validation in updateDB
1 parent 09575f3 commit bc30cee

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/workflow/updateDB.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
#include "FileUtil.h"
66
#include "accession2taxid.h"
77
#include "editNames.h"
8+
#include "fasta_validate.h"
89

910

1011
void setDefaults_updateDB(LocalParameters & par){
1112
par.makeLibrary = 0;
1213
par.gtdb = 0;
14+
par.validateInput = 0;
1315
// par.skipRedundancy = 1;
1416
par.reducedAA = 0;
1517
par.ramUsage = 128;
@@ -42,6 +44,38 @@ int updateDB(int argc, const char **argv, const Command &command){
4244
FileUtil::makeDir(newDbDir.c_str());
4345
}
4446

47+
if (par.validateInput == 1) {
48+
const string & fnaListFileName = par.filenames[1];
49+
// Read the file line by line
50+
ifstream file(fnaListFileName);
51+
if (!file.is_open()) {
52+
cout << "Error: Unable to open file " << fnaListFileName << endl;
53+
return 1;
54+
}
55+
string singleFastaName;
56+
while (getline(file, singleFastaName)) {
57+
if (!LocalUtil::isFasta(singleFastaName)) {
58+
cout << "Error: " << singleFastaName << " has a unsupported extension." << endl;
59+
cout << " Allowed extensions are .fna, .fasta, .fa, and their gzip versions (e.g., .fna.gz)" << endl;
60+
file.close();
61+
return 1;
62+
}
63+
if (!FileUtil::fileExists(singleFastaName.c_str())) {
64+
cout << "Error: " << singleFastaName << " does not exist." << endl;
65+
file.close();
66+
return 1;
67+
}
68+
int validateRes = validate_fasta_file(singleFastaName.c_str(), 1);
69+
if (validateRes != 0) {
70+
cout << "Error: " << singleFastaName << " is not a valid FASTA file." << endl;
71+
cout << " Please check the entries in the file" << endl;
72+
file.close();
73+
return 1;
74+
}
75+
}
76+
}
77+
78+
4579
if (par.gtdb == 1) {
4680
accession2taxid(par.filenames[1], par.filenames[2]);
4781
par.filenames[2] = par.filenames[2].substr(0, par.filenames[2].find_last_of('.')) + ".accession2taxid";

0 commit comments

Comments
 (0)