// PdbToFasta.cpp #include #include #include #include #include #include #include #include "FastaWriter.hpp" #include "GzipReader.hpp" #include "PdbFinderParser.hpp" #include "SystemError.hpp" using namespace NGBW; int main(int argc, char **argv) { try { std::ios_base::sync_with_stdio(false); if(argc != 4) throw std::invalid_argument("usage: pdb-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); GzipReader reader(argv[3]); PdbFinderParser parser(reader); PdbFinderRecord pdb_record; FastaRecord fasta_record; while (parser.Parse(pdb_record)) { fasta_record.organism.assign(pdb_record.organism); fasta_record.description.assign(pdb_record.description); for (ChainList::const_iterator i = pdb_record.chains.begin() ; i != pdb_record.chains.end() ; i++) { fasta_record.identity.assign(pdb_record.identity); fasta_record.identity.push_back('-'); fasta_record.identity.append((*i).identity); fasta_record.sequence.assign((*i).sequence); writer.Write(fasta_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; } }