Skip to content
Merged
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
18 changes: 18 additions & 0 deletions src/utils/selectsites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,23 @@ regions_by_chrom(vector<GenomicRegion> &regions,
regions.shrink_to_fit();
}


inline bool
file_exists(const string &filename) {
return (access(filename.c_str(), F_OK) == 0);
}


static bool
is_compressed_file(const string &filename) {
const bgzf_file f(filename.c_str(), "r");
htsFormat fmt;
const int ret = hts_detect_format(f.f->fp, &fmt);
if (ret != 0) throw runtime_error("failed to detect format: " + filename);
return fmt.compression != no_compression;
}


int
main_selectsites(int argc, const char **argv) {

Expand Down Expand Up @@ -215,6 +227,12 @@ main_selectsites(int argc, const char **argv) {
if (isdir(sites_file.c_str()) || !file_exists(sites_file))
throw runtime_error("bad input sites file: " + sites_file);

if (is_compressed_file(sites_file)) {
LOAD_ENTIRE_FILE = true;
if (VERBOSE)
cerr << "input file is so must be loaded" << endl;
}

vector<GenomicRegion> regions;
ReadBEDFile(regions_file, regions);
if (!check_sorted(regions))
Expand Down