From 49079e241d33c4b9bc5eb92aed3f2da741f52a71 Mon Sep 17 00:00:00 2001 From: gkarthik Date: Fri, 7 Jun 2024 18:58:26 -0700 Subject: [PATCH] Ignore empty lines that are usually present at end of file --- src/parse_gff.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/parse_gff.cpp b/src/parse_gff.cpp index b78a7db9..f9cdcc8a 100644 --- a/src/parse_gff.cpp +++ b/src/parse_gff.cpp @@ -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::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; } @@ -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; }