Skip to content

Commit

Permalink
fix: Add check for .fai index files before parameter validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ekg committed Nov 6, 2024
1 parent 23bb4c0 commit dedb843
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/interface/parse_args.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,30 @@ void parse_args(int argc,

map_parameters.legacy_output = false;

//Check if files are valid
// Check if files are valid and have .fai indexes
for (const auto& file : map_parameters.refSequences) {
const std::string fai_path = file + ".fai";
std::ifstream fai_file(fai_path);
if (!fai_file.good()) {
std::cerr << "[wfmash] ERROR: Missing .fai index for reference file: " << file << std::endl;
std::cerr << "[wfmash] Please create the index with 'samtools faidx " << file << "'" << std::endl;
exit(1);
}
}
for (const auto& file : map_parameters.querySequences) {
// Don't check twice if query is same as reference
if (std::find(map_parameters.refSequences.begin(), map_parameters.refSequences.end(), file) == map_parameters.refSequences.end()) {
const std::string fai_path = file + ".fai";
std::ifstream fai_file(fai_path);
if (!fai_file.good()) {
std::cerr << "[wfmash] ERROR: Missing .fai index for query file: " << file << std::endl;
std::cerr << "[wfmash] Please create the index with 'samtools faidx " << file << "'" << std::endl;
exit(1);
}
}
}

// Check if files exist and are readable
skch::validateInputFiles(map_parameters.querySequences, map_parameters.refSequences);

std::cerr << "[wfmash] Parameters: k=" << map_parameters.kmerSize
Expand Down

0 comments on commit dedb843

Please sign in to comment.