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
00023 #include <vector>
00024 #include <iterator>
00025 #include <fstream>
00026 #include <dsrpdb/align.h>
00027 #include <dsrpdb/distance.h>
00028
00029
00030 #ifdef PDB_USE_BOOST_PROGRAM_OPTIONS
00031 #include <boost/program_options.hpp>
00032 #endif
00033
00034
00035 int main(int argc, char *argv[]){
00036 std::string base_file, input_file, output_file;
00037 bool print_help=false;
00038 bool crms=false, drms=false;
00039 int base_model=0;
00040 bool warn=false;
00041 #ifdef PDB_USE_BOOST_PROGRAM_OPTIONS
00042 {
00043 boost::program_options::options_description o("Allowed options"), po, ao;
00044 o.add_options()
00045 ("aligned-pdb,a", boost::program_options::value< std::string>(&output_file), "Where to write the result of aligning input-pdb to base-pdb.")
00046
00047 ("crms,c", boost::program_options::bool_switch(&crms), "Output the cRMS between the two pdbs (after alignment).")
00048 ("drms,d", boost::program_options::bool_switch(&drms), "Output the dRMS between the two pdbs.")
00049 ("verbose,v", boost::program_options::bool_switch(&warn), "Warn about errors parsing pdb file.")
00050 ("help", boost::program_options::bool_switch(&print_help), "Produce help message");
00051 po.add_options()("base-pdb", boost::program_options::value< std::string>(&base_file), "Base file")
00052 ("input-pdb", boost::program_options::value< std::string>(&input_file), "input file");
00053 ao.add(o).add(po);
00054
00055 boost::program_options::positional_options_description p;
00056 p.add("base-pdb", 1);
00057 p.add("input-pdb", 1);
00058
00059 boost::program_options::variables_map vm;
00060 boost::program_options::store(boost::program_options::command_line_parser(argc, argv).
00061 options(ao).positional(p).run(), vm);
00062 boost::program_options::notify(vm);
00063
00064
00065 if (base_file.empty() || input_file.empty() || print_help) {
00066 std::cout << "This program aligns two proteins and can compute distances between them.\n";
00067 std::cout << "usage: " << argv[0] << " base-pdb input-pdb\n\n";
00068 std::cout << o << "\n";
00069 return EXIT_FAILURE;
00070 }
00071 }
00072
00073 #else
00074 if (argc != 3){
00075 std::cerr << "The program is built without boost/program_options.hpp.\n";
00076 std::cerr << "useage: " << argv[0] << " file0.pdb file1.pdb" << std::endl;
00077 return EXIT_FAILURE;
00078 }
00079 input_file = argv[1];
00080 output_file = argv[2];
00081 #endif
00082
00083 std::ifstream in(input_file.c_str());
00084
00085 if (!in){
00086 std::cerr<< "Error opening input file: " << input_file << std::endl;
00087 return EXIT_FAILURE;
00088 }
00089 std::ifstream bin(base_file.c_str());
00090
00091 if (!bin){
00092 std::cerr<< "Error opening input file: " << base_file << std::endl;
00093 return EXIT_FAILURE;
00094 }
00095
00096 dsrpdb::PDB input(in, warn);
00097 dsrpdb::PDB base(bin, warn);
00098 dsrpdb::Protein base_protein;
00099 for (unsigned int i=0; i< base.number_of_models(); ++i){
00100 const dsrpdb::Model &m= base.model(i);
00101 if (base_model ==0 || m.index()==base_model) {
00102 for (unsigned int j=0; j< m.number_of_chains(); ++j){
00103 base_protein= m.chain(j);
00104
00105 }
00106 }
00107 }
00108
00109 if ( !output_file.empty() || crms) {
00110 for (unsigned int i=0; i< input.number_of_models(); ++i){
00111 dsrpdb::Model &m= input.model(i);
00112 dsrpdb::Protein &p= m.chain(0);
00113 dsrpdb::align_second_protein_to_first(base_protein, p);
00114 }
00115 }
00116
00117 if (!output_file.empty()) {
00118 std::ofstream out(output_file.c_str());
00119 if (!out){
00120 std::cerr << "Error opening output file "
00121 << output_file << std::endl;
00122 return EXIT_FAILURE;
00123 }
00124 input.write(out);
00125 }
00126
00127 if (crms) {
00128 std::cout << "cRMS:\n";
00129 for (unsigned int i=0; i< input.number_of_models(); ++i){
00130 dsrpdb::Model &m= input.model(i);
00131 dsrpdb::Protein &p= m.chain(0);
00132 double d=dsrpdb::no_align_cRMS(base_protein, p);
00133 if (d < .00001) d=0;
00134 std::cout << "Model " << i << " is " << d << std::endl;
00135 }
00136 }
00137
00138 if (drms) {
00139 std::cout << "dRMS:\n";
00140 for (unsigned int i=0; i< input.number_of_models(); ++i){
00141 dsrpdb::Model &m= input.model(i);
00142 dsrpdb::Protein &p= m.chain(0);
00143 double d=dsrpdb::dRMS(base_protein, p);
00144 if (d < .00001) d=0;
00145 std::cout << "Model " << i << " is " << d << std::endl;
00146 }
00147 }
00148
00149 return EXIT_SUCCESS;
00150
00151 }
00152