// GenbankToFasta.cpp #include #include #include #include #include #include #include "FastaWriter.hpp" #include "GenbankParser.hpp" #include "GzipReader.hpp" #include "SystemError.hpp" using namespace NGBW; int main(int argc, char **argv) { try { std::ios_base::sync_with_stdio(false); if(argc < 3) throw std::invalid_argument("usage: genbank-to-fasta dataset outputname inputname..."); boost::scoped_ptr output_file; if(std::memcmp(argv[2], "-", 2) != 0) { output_file.reset(new std::ofstream(argv[2])); if(!output_file->good()) { std::string message("can't open "); message.append(argv[2]); throw SystemError("main", message, errno); } } std::ostream &output = output_file ? *output_file : std::cout; FastaWriter writer(argv[1], output); FastaRecord record; for (int i = 3 ; i < argc ; i += 1) { GzipReader reader(argv[i]); GenbankParser parser(reader); while (parser.Parse(record)) writer.Write(record); } return 0; } catch(const std::exception &err) { std::cerr << err.what() << std::endl; return 1; } catch(...) { std::cerr << "An unknown exception was thrown" << std::endl; return 1; } }