00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "dsrpdb/PDB.h"
00022 #include <cstdlib>
00023 #include <iostream>
00024 #include <fstream>
00025
00026 #ifdef PDB_USE_BOOST_PROGRAM_OPTIONS
00027 #include <boost/program_options.hpp>
00028 #endif
00029
00030 int main(int argc, char *argv[]){
00031 std::vector<std::string> input_files;
00032 std::string output_file;
00033 bool print_help=false;
00034 bool verbose=false;
00035
00036 #ifdef PDB_USE_BOOST_PROGRAM_OPTIONS
00037 {
00038 boost::program_options::options_description o("Allowed options"), po, ao;
00039 o.add_options()
00040 ("help", boost::program_options::bool_switch(&print_help), "produce help message")
00041 ("verbose,v", boost::program_options::bool_switch(&verbose),
00042 "Print error messages from reading the pdb files.");
00043 po.add_options()
00044 ("input-pdbs", boost::program_options::value< std::vector<std::string> >(&input_files),
00045 "The input and output files.");
00046
00047 ao.add(o).add(po);
00048
00049 boost::program_options::positional_options_description p;
00050 p.add("input-pdbs", -1);
00051
00052 boost::program_options::variables_map vm;
00053 boost::program_options::store(boost::program_options::command_line_parser(argc, argv).
00054 options(ao).positional(p).run(), vm);
00055 boost::program_options::notify(vm);
00056
00057
00058 if (input_files.size() <2 || print_help) {
00059 std::cout << "Concatenate a bunch of pdb files into one pdb file with many models.\n";
00060 std::cout << "usage: " << argv[0] << " input-pdb-0 input-pdb-1 ... output-pdb\n";
00061 std::cout << o << "\n";
00062 return EXIT_FAILURE;
00063 }
00064
00065 output_file=input_files.back();
00066 input_files.pop_back();
00067 }
00068
00069 #else
00070 for (int i=1; i< argc-1; ++i){
00071 input_files.push_back(argv[i]);
00072 }
00073 output_file = argv[argc-1];
00074 #endif
00075
00076
00077 dsrpdb::PDB outpdb;
00078
00079 for (unsigned int i=0; i < input_files.size(); ++i){
00080 std::ifstream in(input_files[i].c_str());
00081 if (!in){
00082 std::cerr << "Error opening input file " << input_files[i] << std::endl;
00083 return EXIT_FAILURE;
00084 }
00085 dsrpdb::PDB inpdb(in, verbose);
00086
00087 for (dsrpdb::PDB::Models_iterator mit= inpdb.models_begin(); mit != inpdb.models_end(); ++mit){
00088 dsrpdb::Model m= *mit;
00089 m.set_index(outpdb.number_of_models());
00090 outpdb.new_model(m);
00091 }
00092 }
00093
00094 if (output_file.empty()){
00095 outpdb.write(std::cout);
00096 } else {
00097 std::ofstream out(output_file.c_str());
00098 outpdb.write(out);
00099 }
00100
00101
00102 return EXIT_SUCCESS;
00103 }