Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ProteinSilentReport.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/ProteinSilentReport.hh
11 /// @brief report feature data to database
12 /// @author Matthew O'Meara
13 
14 // Unit Headers
16 
17 //External
18 #include <boost/uuid/uuid.hpp>
19 
20 // Project Headers
22 
38 #include <basic/options/option.hh>
39 #include <basic/database/sql_utils.hh>
40 #include <basic/options/keys/out.OptionKeys.gen.hh>
41 
42 // Platform Headers
43 #include <core/pose/Pose.hh>
44 #include <core/scoring/Energies.hh>
45 #include <core/pose/util.hh>
46 
48 #include <utility/sql_database/DatabaseSessionManager.hh>
49 #include <utility/vector1.hh>
50 #include <basic/Tracer.hh>
51 
52 // Boost Headers
53 #include <boost/foreach.hpp>
54 #define foreach BOOST_FOREACH
55 
56 // External Headers
57 #include <cppdb/frontend.h>
58 
59 // C++ Headers
60 #include <string>
61 
62 #include <protocols/jd2/Job.hh>
63 
64 namespace protocols{
65 namespace features{
66 
67 static basic::Tracer TR("protocols.features.ProteinSilentReport");
68 
69 using utility::sql_database::sessionOP;
70 using utility::vector1;
71 using cppdb::statement;
72 using core::Size;
73 using core::pose::Pose;
76 
78  initialized_(false),
79  database_filter_(NULL),
80  protocol_id_(0),
81  structure_map_(),
82  protocol_features_( new ProtocolFeatures() ),
83  batch_features_( new BatchFeatures() ),
84  pdb_data_features_( new PdbDataFeatures()),
85  structure_features_( new StructureFeatures() ),
86  structure_scores_features_( new StructureScoresFeatures() ),
87  score_type_features_(new ScoreTypeFeatures()),
88  pose_conformation_features_( new PoseConformationFeatures() ),
89  pose_comments_features_( new PoseCommentsFeatures() ),
90  protein_residue_conformation_features_( new ProteinResidueConformationFeatures() ),
91  residue_features_ (new ResidueFeatures() ),
92  residue_conformation_features_ (new ResidueConformationFeatures() ),
93  job_data_features_ (new JobDataFeatures() )
94 {
96 
97  if( basic::options::option[basic::options::OptionKeys::out::database_protocol_id].user() ){
98  protocol_id_ = basic::options::option[basic::options::OptionKeys::out::database_protocol_id];
99  }
100 }
101 
103  Report(),
104  initialized_(src.initialized_),
105  database_filter_(src.database_filter_),
106  protocol_id_(src.protocol_id_),
107  structure_map_(src.structure_map_),
108  protocol_features_(src.protocol_features_),
109  pdb_data_features_(src.pdb_data_features_),
110  structure_features_(src.structure_features_),
111  structure_scores_features_(src.structure_scores_features_),
112  score_type_features_(src.score_type_features_),
113  pose_conformation_features_(src.pose_conformation_features_),
114  pose_comments_features_(src.pose_comments_features_),
115  protein_residue_conformation_features_(src.protein_residue_conformation_features_),
116  residue_features_(src.residue_features_),
117  residue_conformation_features_ (src.residue_conformation_features_ ),
118  job_data_features_ ( src.job_data_features_)
119 {}
120 
122 
123 Size
125 
126 void
128  sessionOP db_session
129 ) const {
130  protocol_features_->write_schema_to_db(db_session);
131  batch_features_->write_schema_to_db(db_session);
132  structure_features_->write_schema_to_db(db_session);
133  score_type_features_->write_schema_to_db(db_session);
134  structure_scores_features_->write_schema_to_db(db_session);
135  pdb_data_features_->write_schema_to_db(db_session);
136  pose_conformation_features_->write_schema_to_db(db_session);
137  pose_comments_features_->write_schema_to_db(db_session);
138  residue_features_->write_schema_to_db(db_session);
139  protein_residue_conformation_features_->write_schema_to_db(db_session);
140  residue_conformation_features_->write_schema_to_db(db_session);
141  job_data_features_->write_schema_to_db(db_session);
142 }
143 
144 
145 void
147  Pose const & pose,
148  sessionOP db_session){
149  apply(pose, db_session, tag_from_pose(pose));
150 }
151 
152 
153 void
155  Pose const & pose,
156  sessionOP db_session,
157  std::string const & tag
158 ) {
159 
160  vector1< bool > relevant_residues(pose.total_residue(), true);
161 
162  //cppdb::transaction transact_guard(*db_session);
163  initialize(db_session);
164 
166  structure_features_->mark_structure_as_sampled(batch_id_,tag,input_tag,db_session);
167 
168  //transact_guard.commit();
169  if(!database_filter_){
170  write_full_report(pose,db_session,tag);
171  return;
172  }
173 
174  std::pair<bool, utility::vector1<boost::uuids::uuid> > temp= (*database_filter_)(pose, db_session, protocol_id_);
175  bool write_this_pose = temp.first;
176  utility::vector1<boost::uuids::uuid> struct_ids_to_delete = temp.second;
177  foreach(boost::uuids::uuid struct_id, struct_ids_to_delete){
178  delete_pose(db_session,struct_id);
179  }
180  if(write_this_pose){
181  write_full_report(pose,db_session,tag);
182  }
183 }
184 
185 void
187  sessionOP db_session,
188  boost::uuids::uuid struct_id,
189  Pose & pose){
190 
191  pose_conformation_features_->load_into_pose(db_session, struct_id, pose);
192  pdb_data_features_->load_into_pose(db_session,struct_id,pose);
193  job_data_features_->load_into_pose(db_session, struct_id, pose);
194  pose_comments_features_->load_into_pose(db_session, struct_id, pose);
195  protein_residue_conformation_features_->load_into_pose(db_session, struct_id, pose);
196  residue_conformation_features_->load_into_pose(db_session,struct_id,pose);
197 }
198 
199 void
201  sessionOP db_session,
202  boost::uuids::uuid struct_id,
203  std::set<core::Size> residue_numbers,
204  Pose & pose){
205 
206  //first load in the entire pose, then delete unspecified residues. This will be slower than
207  //it needs to be but should result in the most sensible state of the fold/atom trees.
208  load_pose(db_session, struct_id, pose);
209 
210  int total_res=pose.total_residue();
211  int num_removed_residues=0;
212  for(int i=1; i<=total_res; ++i){
213  //if the residue wasn't specified, delete it
214  if(residue_numbers.find(i)==residue_numbers.end()){
215  pose.conformation().delete_residue_slow(i-num_removed_residues);
216  ++num_removed_residues;
217  }
218  }
219 }
220 
222 {
223  return initialized_;
224 }
225 
226 void ProteinSilentReport::initialize(sessionOP db_session)
227 {
228  if(!initialized_)
229  {
230  write_schema_to_db(db_session);
231  write_protocol_report(db_session);
232  initialized_ = true;
233  }
234 }
235 
236 void
238  utility::sql_database::sessionOP db_session
239 ){
240  //MYSQL innoDB tables cannot defer foreign constraint checking, so we explicitly wrap these
241  //Calls in transaction guards to make sure the protocol and type_id features are set up properly
242  cppdb::transaction protocol_transaction(*db_session);
243 
244  //initialize protocol and batch id
245  std::pair<Size, Size> ids = get_protocol_and_batch_id("db_job_outputter", db_session);
246  protocol_id_=ids.first;
247  batch_id_=ids.second;
248  protocol_transaction.commit();
249 
250  cppdb::transaction score_type_transaction(*db_session);
251  score_type_features_->report_features(batch_id_, db_session);
252  score_type_transaction.commit();
253 }
254 void
256  core::pose::Pose const & pose,
257  utility::sql_database::sessionOP db_session,
258  std::string const & tag
259 ) {
260 
261  vector1< bool > relevant_residues(pose.total_residue(), true);
262 
263  cppdb::transaction transact_guard(*db_session);
265 
266  boost::uuids::uuid struct_id = structure_features_->report_features(
267  relevant_residues, batch_id_, db_session, tag, input_tag);
268 
269  pose_conformation_features_->report_features(
270  pose, relevant_residues, struct_id, db_session);
271 
272  pdb_data_features_->report_features(
273  pose,relevant_residues,struct_id,db_session);
274 
275  if(pose.energies().energies_updated()){
276  structure_scores_features_->report_features(
277  pose, relevant_residues, struct_id, db_session);
278  }
279 
280  pose_comments_features_->report_features(
281  pose, relevant_residues, struct_id, db_session);
282  residue_features_->report_features(
283  pose, relevant_residues, struct_id, db_session);
285  pose, relevant_residues, struct_id, db_session);
286  residue_conformation_features_->report_features(
287  pose, relevant_residues, struct_id, db_session);
288  job_data_features_->report_features(
289  pose, relevant_residues, struct_id, db_session);
290 
291  transact_guard.commit();
292 }
293 
294 void ProteinSilentReport::delete_pose_from_tag(utility::sql_database::sessionOP db_session, std::string const & tag)
295 {
296  boost::uuids::uuid struct_id = structure_features_->get_struct_id(db_session,tag,protocol_id_);
297  delete_pose(db_session,struct_id);
298 }
299 
300 void ProteinSilentReport::delete_pose(utility::sql_database::sessionOP db_session, boost::uuids::uuid const & struct_id)
301 {
302 
303  job_data_features_->delete_record(struct_id,db_session);
304  residue_conformation_features_->delete_record(struct_id,db_session);
305  protein_residue_conformation_features_->delete_record(struct_id,db_session);
306  residue_features_->delete_record(struct_id,db_session);
307  pose_comments_features_->delete_record(struct_id,db_session);
308  structure_scores_features_->delete_record(struct_id,db_session);
309  pdb_data_features_->delete_record(struct_id,db_session);
310  pose_conformation_features_->delete_record(struct_id,db_session);
311  structure_features_->delete_record(struct_id,db_session);
312 }
313 
315 {
316  return protocol_id_;
317 }
318 
320 {
321  return batch_id_;
322 }
323 
324 
325 } //namespace
326 } //namespace