// PdbToFasta.cpp #include #include #include #include #include #include #include #include #include #include "GzipReader.hpp" #include "PdbFinderWriter.hpp" #include "PdbSeqresParser.hpp" #include "SystemError.hpp" using namespace NGBW; int main(int argc, char **argv) { try { std::ios_base::sync_with_stdio(false); if(argc < 3 || argc > 4) throw std::invalid_argument("usage: fix-pdbfinder pdbseqres pdbfinder [ outputname ]"); boost::scoped_ptr output_file; if(argc == 4 && std::memcmp(argv[3], "-", 2) != 0) { output_file.reset(new std::ofstream(argv[3])); if(!output_file->good()) { std::string message("can't open "); message.append(argv[3]); throw SystemError("main", message, errno); } } SeqresMap sequences; GzipReader seqres_reader(argv[1]); PdbSeqresParser parser(seqres_reader); PdbSeqresRecord record; while (parser.Parse(record)) { SeqresMap::iterator entry(sequences.find(record.protein_id)); if (entry == sequences.end()) { ChainSet new_set; new_set.insert(record); sequences.insert(SeqresMap::value_type(record.protein_id, new_set)); } else (*entry).second.insert(record); } std::ostream &output = output_file ? *output_file : std::cout; GzipReader finder_reader(argv[2]); PdbFinderWriter writer(finder_reader, output); writer.Write(sequences); 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; } }