Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PoseCommentsFeatures.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file protocols/features/PoseCommentsFeatures.cc
11 /// @brief report comments stored with each pose
12 /// @author Matthew O'Meara
13 
14 // Unit Headers
16 
17 // Project Headers
18 #include <core/pose/util.hh>
19 
20 //External
21 #include <boost/uuid/uuid.hpp>
22 #include <boost/uuid/uuid_io.hpp>
23 
24 // Platform Headers
25 #include <core/chemical/AA.hh>
27 // AUTO-REMOVED #include <core/pose/Pose.hh>
28 #include <core/types.hh>
29 
30 // Utility Headers
31 #include <numeric/xyzVector.hh>
32 #include <utility/vector1.hh>
33 #include <utility/sql_database/DatabaseSessionManager.hh>
34 #include <utility/tools/make_vector.hh>
35 
36 //Basic Headers
37 #include <basic/database/sql_utils.hh>
38 #include <basic/database/schema_generator/PrimaryKey.hh>
39 #include <basic/database/schema_generator/ForeignKey.hh>
40 #include <basic/database/schema_generator/Column.hh>
41 #include <basic/database/schema_generator/Schema.hh>
42 #include <basic/database/schema_generator/Constraint.hh>
43 #include <basic/options/option.hh>
44 #include <basic/options/keys/inout.OptionKeys.gen.hh>
45 
46 
47 #include <basic/database/insert_statement_generator/InsertGenerator.hh>
48 #include <basic/database/insert_statement_generator/RowData.hh>
49 
50 // External Headers
51 #include <cppdb/frontend.h>
52 
53 // Boost Headers
54 #include <boost/foreach.hpp>
55 #define foreach BOOST_FOREACH
56 
57 // C++ Headers
58 #include <string>
59 #include <map>
60 #include <sstream>
61 
62 namespace protocols{
63 namespace features{
64 
65 using std::string;
66 using std::map;
67 using core::Size;
68 using core::Real;
69 using core::pose::Pose;
74 using basic::database::table_exists;
75 using utility::sql_database::sessionOP;
76 using utility::vector1;
77 using cppdb::statement;
78 using cppdb::result;
79 using basic::database::insert_statement_generator::InsertGenerator;
80 using basic::database::insert_statement_generator::RowDataBaseOP;
81 using basic::database::insert_statement_generator::RowData;
82 
83 string
84 PoseCommentsFeatures::type_name() const { return "PoseCommentsFeatures"; }
85 
86 void
87 PoseCommentsFeatures::write_schema_to_db(utility::sql_database::sessionOP db_session) const{
88  using namespace basic::database::schema_generator;
89 
90  //******pose_comments******//
91  Column struct_id("struct_id", new DbUUID(), false);
92  Column comment_key("comment_key", new DbTextKey(), false);
93  Column value("value", new DbText(), false);
94 
95  utility::vector1<Column> pkey_cols;
96  pkey_cols.push_back(struct_id);
97  pkey_cols.push_back(comment_key);
98 
99  Schema pose_comments("pose_comments", PrimaryKey(pkey_cols));
100  pose_comments.add_column(struct_id);
101  pose_comments.add_column(comment_key);
102  pose_comments.add_column(value);
103 
104  pose_comments.add_foreign_key(ForeignKey(struct_id, "structures", "struct_id", true));
105  pose_comments.write(db_session);
106 
107 }
108 
111  utility::vector1<std::string> dependencies;
112  dependencies.push_back("StructureFeatures");
113  return dependencies;
114 }
115 
116 
117 Size
119  Pose const & pose,
120  vector1< bool > const & /*relevant_residues*/,
121  boost::uuids::uuid struct_id,
122  sessionOP db_session
123 ){
124 
125  InsertGenerator pose_comments_insert("pose_comments");
126  pose_comments_insert.add_column("struct_id");
127  pose_comments_insert.add_column("comment_key");
128  pose_comments_insert.add_column("value");
129 
130 
131  typedef map< string, string >::value_type kv_pair;
132 
133  RowDataBaseOP struct_id_data = new RowData<boost::uuids::uuid>("struct_id",struct_id);
134 
135  foreach(kv_pair const & kv, get_all_comments(pose)){
136 
137  RowDataBaseOP comment_key_data =new RowData<string>("comment_key",kv.first);
138  RowDataBaseOP value_data = new RowData<string>("value",kv.second);
139 
140  pose_comments_insert.add_row(utility::tools::make_vector(struct_id_data,comment_key_data,value_data));
141  }
142 
143  pose_comments_insert.write_to_database(db_session);
144 
145  return 0;
146 }
147 
149  boost::uuids::uuid struct_id,
150  utility::sql_database::sessionOP db_session
151 ) {
152 
153  std::string statement_string = "DELETE FROM pose_comments where struct_id = ?;";
154  statement stmt(basic::database::safely_prepare_statement(statement_string,db_session));
155  stmt.bind(1,struct_id);
156  basic::database::safely_write_to_database(stmt);
157 
158 }
159 
160 void
162  sessionOP db_session,
163  boost::uuids::uuid struct_id,
164  Pose & pose){
165 
166  if(!table_exists(db_session, "pose_comments")) return;
167 
168 
169  std::string statement_string =
170  "SELECT\n"
171  " comment_key,\n"
172  " value\n"
173  "FROM\n"
174  " pose_comments\n"
175  "WHERE\n"
176  " pose_comments.struct_id = ?;";
177  statement stmt(basic::database::safely_prepare_statement(statement_string,db_session));
178  stmt.bind(1,struct_id);
179 
180  result res(basic::database::safely_read_from_database(stmt));
181 
182  while(res.next()){
183  string key, value;
184  res >> key >> value;
185  add_comment(pose, key, value);
186  }
187 }
188 
189 } //namesapce
190 } //namespace