Skip to content

Commit

Permalink
Parser: Added support for '-' as input from stdin.
Browse files Browse the repository at this point in the history
  • Loading branch information
OndrejSladky committed Aug 11, 2024
1 parent 54946ab commit de1314d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,19 @@ void AddKMers(kh_S64_t *kMers, size_t sequence_length, const char* sequence, int
/// Load a dictionary of k-mers from a fasta file.
/// If complements is true, add the canonical k-mers.
void ReadKMers(kh_S64_t *kMers, std::string &path, int k, bool complements, bool case_sensitive = false) {
gzFile fp;
kseq_t *seq;

fp = gzopen(path.c_str(), "r");
if (fp == nullptr) {
throw std::invalid_argument("couldn't open file " + path);
FILE *instream = nullptr;
if(path=="-"){
instream = stdin;
}
else {
instream = fopen(path.c_str(), "r");
if (instream == nullptr) {
throw std::invalid_argument("couldn't open file " + path);
}
}
gzFile fp = gzdopen(fileno(instream), "r");

seq = kseq_init(fp);
while (kseq_read(seq) >= 0) {
Expand Down

0 comments on commit de1314d

Please sign in to comment.