Skip to content

Commit 0c7c3f1

Browse files
selectsites: testing if the input file is compressed and if it is then not allowing for search on disk
1 parent c6e026f commit 0c7c3f1

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/utils/selectsites.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,23 @@ regions_by_chrom(vector<GenomicRegion> &regions,
159159
regions.shrink_to_fit();
160160
}
161161

162+
162163
inline bool
163164
file_exists(const string &filename) {
164165
return (access(filename.c_str(), F_OK) == 0);
165166
}
166167

168+
169+
static bool
170+
is_compressed_file(const string &filename) {
171+
const bgzf_file f(filename.c_str(), "r");
172+
htsFormat fmt;
173+
const int ret = hts_detect_format(f.f->fp, &fmt);
174+
if (ret != 0) throw runtime_error("failed to detect format: " + filename);
175+
return fmt.compression != no_compression;
176+
}
177+
178+
167179
int
168180
main_selectsites(int argc, const char **argv) {
169181

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

230+
if (is_compressed_file(sites_file)) {
231+
LOAD_ENTIRE_FILE = true;
232+
if (VERBOSE)
233+
cerr << "input file is so must be loaded" << endl;
234+
}
235+
218236
vector<GenomicRegion> regions;
219237
ReadBEDFile(regions_file, regions);
220238
if (!check_sorted(regions))

0 commit comments

Comments
 (0)