Skip to content

Commit

Permalink
Ignore empty lines that are usually present at end of file
Browse files Browse the repository at this point in the history
  • Loading branch information
gkarthik committed Jun 8, 2024
1 parent 14cf664 commit 49079e2
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/parse_gff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ gff3_feature::gff3_feature(std::string line) {
}
ctr++;
}
if (ctr < 9) std::cout << "GFF file is not in GFF3 file format!" << std::endl;
if (ctr < 9) std::cerr << "GFF file is not in GFF3 file format!" << std::endl;
line_stream.clear();
}

int gff3_feature::print() {
std::cout << seqid << "\t" << source << "\t" << type << "\t" << start << "\t"
std::cerr << seqid << "\t" << source << "\t" << type << "\t" << start << "\t"
<< end << "\t" << score << "\t" << strand << "\t" << phase << "\t";
std::map<std::string, std::string>::iterator it;
for (it = attributes.begin(); it != attributes.end(); it++) {
std::cout << it->first << ": " << it->second << "; ";
std::cerr << it->first << ": " << it->second << "; ";
}
std::cout << std::endl;
std::cerr << std::endl;
return 0;
}

Expand Down Expand Up @@ -131,16 +131,22 @@ gff3::gff3(std::string path) {
int gff3::read_file(std::string path) {
std::ifstream fin = std::ifstream(path);
if (!fin) {
std::cout << "GFF file does not exist at " << path << std::endl;
std::cerr << "GFF file does not exist at " << path << std::endl;
return -1;
}
std::string line;
while (std::getline(fin, line)) {
if (line[0] == '#') // Avoid comments in GFF file
continue;
features.push_back(gff3_feature(line));
if(!line.empty())
features.push_back(gff3_feature(line));
}
this->is_empty = false;
if(!features.empty()){
this->is_empty = false;
} else {
std::cerr << "GFF file is empty!" << std::endl;
}

return 0;
}

Expand Down

0 comments on commit 49079e2

Please sign in to comment.