|
5 | 5 | #include "FileUtil.h" |
6 | 6 | #include "accession2taxid.h" |
7 | 7 | #include "editNames.h" |
| 8 | +#include "fasta_validate.h" |
8 | 9 |
|
9 | 10 |
|
10 | 11 | void setDefaults_updateDB(LocalParameters & par){ |
11 | 12 | par.makeLibrary = 0; |
12 | 13 | par.gtdb = 0; |
| 14 | + par.validateInput = 0; |
13 | 15 | // par.skipRedundancy = 1; |
14 | 16 | par.reducedAA = 0; |
15 | 17 | par.ramUsage = 128; |
@@ -42,6 +44,38 @@ int updateDB(int argc, const char **argv, const Command &command){ |
42 | 44 | FileUtil::makeDir(newDbDir.c_str()); |
43 | 45 | } |
44 | 46 |
|
| 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 | + |
45 | 79 | if (par.gtdb == 1) { |
46 | 80 | accession2taxid(par.filenames[1], par.filenames[2]); |
47 | 81 | par.filenames[2] = par.filenames[2].substr(0, par.filenames[2].find_last_of('.')) + ".accession2taxid"; |
|
0 commit comments