OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
mmcif_info.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2011 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 #ifndef OST_MMCIF_INFO_HH
20 #define OST_MMCIF_INFO_HH
21 
22 #include <vector>
23 #include <map>
24 #include <boost/shared_ptr.hpp>
25 #include <ost/seq/sequence_list.hh>
26 #include <ost/geom/geom.hh>
27 #include <ost/string_ref.hh>
28 #include <ost/io/module_config.hh>
29 
30 namespace ost { namespace io {
31 
32 class DLLEXPORT_OST_IO MMCifInfoStructDetails {
33 public:
35  MMCifInfoStructDetails(): entry_id_(""), title_(""), casp_flag_('\0'),
36  descriptor_(""), mass_(0.0), mass_method_(""), model_details_(""),
37  model_type_details_("") {};
38 
42  void SetEntryID(String id) { entry_id_ = id; }
46  String GetEntryID() const { return entry_id_; }
47 
51  void SetCASPFlag(char flag) { casp_flag_ = flag; }
55  char GetCASPFlag() const { return casp_flag_; }
56 
60  void SetDescriptor(String desc) { descriptor_ = desc; }
64  String GetDescriptor() const { return descriptor_; }
65 
69  void SetMass(Real mass) { mass_ = mass; }
73  Real GetMass() const { return mass_; }
74 
78  void SetMassMethod(String method) { mass_method_ = method; }
82  String GetMassMethod() const { return mass_method_; }
83 
87  void SetModelDetails(String desc) { model_details_ = desc; }
91  String GetModelDetails() const { return model_details_; }
92 
96  void SetModelTypeDetails(String desc) { model_type_details_ = desc; }
100  String GetModelTypeDetails() const { return model_type_details_; }
101 
105  void SetTitle(String title) { title_ = title; }
109  String GetTitle() const { return title_; }
110 
111  bool operator==(const MMCifInfoStructDetails& sd) const {
112  if (this->entry_id_ != sd.entry_id_) {
113  return false;
114  }
115  if (this->casp_flag_ != sd.casp_flag_) {
116  return false;
117  }
118  if (this->descriptor_ != sd.descriptor_) {
119  return false;
120  }
121  if (this->mass_ != sd.mass_) {
122  return false;
123  }
124  if (this->mass_method_ != sd.mass_method_) {
125  return false;
126  }
127  if (this->model_details_ != sd.model_details_) {
128  return false;
129  }
130  if (this->model_type_details_ != sd.model_type_details_) {
131  return false;
132  }
133  if (this->title_ != sd.title_) {
134  return false;
135  }
136 
137  return true;
138  }
139 
140  bool operator!=(const MMCifInfoStructDetails& sd) const {
141  return !this->operator == (sd);
142  }
143 
144 private:
145  String entry_id_;
146  String title_;
147  char casp_flag_;
148  String descriptor_;
149  Real mass_;
150  String mass_method_;
151  String model_details_;
152  String model_type_details_;
153 };
154 
155 class DLLEXPORT_OST_IO MMCifInfoTransOp {
156 public:
158  MMCifInfoTransOp(): id_(""), type_("")
159  {
160  translation_ = geom::Vec3();
161  };
162 
166  void SetID(String id) { id_ = id; }
170  String GetID() const { return id_; }
171 
175  void SetType(String type) { type_ = type; }
179  String GetType() const { return type_; }
180 
184  void SetVector(Real x, Real y, Real z)
185  {
186  translation_.SetX(x);
187  translation_.SetY(y);
188  translation_.SetZ(z);
189  }
193  geom::Vec3 GetVector() const { return translation_; }
194 
198  void SetMatrix(Real i00, Real i01, Real i02,
199  Real i10, Real i11, Real i12,
200  Real i20, Real i21, Real i22)
201  {
202  rotation_ = geom::Mat3(i00,i01,i02, i10,i11,i12, i20,i21,i22);
203  }
207  geom::Mat3 GetMatrix() const { return rotation_; }
208 
209  bool operator==(const MMCifInfoTransOp& op) const {
210  if (this->id_ != op.id_) {
211  return false;
212  }
213  if (this->type_ != op.type_) {
214  return false;
215  }
216  if (this->translation_ != op.translation_) {
217  return false;
218  }
219  if (this->rotation_ != op.rotation_) {
220  return false;
221  }
222 
223  return true;
224  }
225 
226  bool operator!=(const MMCifInfoTransOp& op) const {
227  return !this->operator==(op);
228  }
229 
230 private:
231  String id_;
232  String type_;
233  geom::Vec3 translation_;
234  geom::Mat3 rotation_;
235 };
236 typedef boost::shared_ptr<MMCifInfoTransOp> MMCifInfoTransOpPtr;
237 
238 
239 class DLLEXPORT_OST_IO MMCifInfoBioUnit {
240 public:
242  MMCifInfoBioUnit(): id_(""), details_("") {};
243 
247  void Merge(MMCifInfoBioUnit& from);
248 
252  void SetID(String id) { id_ = id; }
256  String GetID() const { return id_; }
257 
261  void SetDetails(String details) { details_ = details; }
265  String GetDetails() const { return details_; }
266 
270  void AddChain(String chain);
271 
275  void SetChainList(std::vector<String> chains);
276 
280  const std::vector<String>& GetChainList() const { return chains_; }
281 
285  const std::vector<std::pair<int, int> >& GetChainIntervalList()
286  {
287  return tr_chains_;
288  }
289 
293  void AddOperations(std::vector<MMCifInfoTransOpPtr> operations);
294 
298  const std::vector<std::pair<int, int> >& GetOperationsIntervalList()
299  {
300  return tr_operations_;
301  }
302 
306  const std::vector<std::vector<MMCifInfoTransOpPtr> >& GetOperations()
307  {
308  return operations_;
309  }
310 
311  bool operator==(const MMCifInfoBioUnit& bu) const {
312  if (this->id_ != bu.id_) {
313  return false;
314  }
315  if (this->details_ != bu.details_) {
316  return false;
317  }
318  if (this->chains_ != bu.chains_) {
319  return false;
320  }
321  if (this->tr_chains_ != bu.tr_chains_) {
322  return false;
323  }
324  if (this->tr_operations_ != bu.tr_operations_) {
325  return false;
326  }
327  if (this->operations_.size() == bu.operations_.size()) {
328  std::vector<std::vector<MMCifInfoTransOpPtr> >::const_iterator th_ops_it;
329  std::vector<std::vector<MMCifInfoTransOpPtr> >::const_iterator bu_ops_it;
330  std::vector<MMCifInfoTransOpPtr>::const_iterator th_op_it;
331  std::vector<MMCifInfoTransOpPtr>::const_iterator bu_op_it;
332 
333  for (th_ops_it = this->operations_.begin(),
334  bu_ops_it = bu.operations_.begin();
335  th_ops_it != this->operations_.end();
336  ++th_ops_it, ++bu_ops_it) {
337  if (th_ops_it->size() == bu_ops_it->size()) {
338  for (th_op_it = th_ops_it->begin(), bu_op_it = bu_ops_it->begin();
339  th_op_it != th_ops_it->end();
340  ++th_op_it, ++bu_op_it) {
341  if (*th_op_it != *bu_op_it) {
342  return false;
343  }
344  }
345  } else {
346  return false;
347  }
348  }
349  } else {
350  return false;
351  }
352 
353  return true;
354  }
355 
356  bool operator!=(const MMCifInfoBioUnit& bu) const {
357  return !this->operator==(bu);
358  }
359 
360 private:
361  String id_;
362  String details_;
363  std::vector<String> chains_;
364  std::vector<std::pair<int, int> > tr_chains_; //< chains of a transformation
365  std::vector<std::vector<MMCifInfoTransOpPtr> > operations_;
366  std::vector<std::pair<int, int> > tr_operations_; //< ops. of a transformation
367 };
368 
369 class DLLEXPORT_OST_IO MMCifInfoCitation {
370 public:
372  MMCifInfoCitation(): id_(""), where_(UNKNOWN), cas_(""), published_in_(""),
373  volume_(""), page_first_(""), page_last_(""), doi_(""), pubmed_(0),
374  year_(0), title_("") {};
375 
379  void SetID(String id) { id_ = id; }
383  String GetID() const { return id_; }
384 
388  void SetCAS(String id) { cas_ = id; }
392  String GetCAS() const { return cas_; }
393 
397  void SetISBN(String code) { isbn_ = code; }
398 
402  String GetISBN() const { return isbn_; }
403 
407  void SetPublishedIn(String title) { published_in_ = title; }
408 
412  String GetPublishedIn() const { return published_in_; }
413 
417  void SetVolume(String volume) { volume_ = volume; }
418 
422  String GetVolume() const { return volume_; }
423 
427  void SetPageFirst(String first) { page_first_ = first; }
428 
432  String GetPageFirst() const { return page_first_; }
433 
437  void SetPageLast(String last) { page_last_ = last; }
438 
442  String GetPageLast() const { return page_last_; }
443 
447  void SetDOI(String doi) { doi_ = doi; }
448 
449 
453  String GetDOI() const { return doi_; }
454 
458  void SetPubMed(int no) { pubmed_ = no; }
459 
463  int GetPubMed() const { return pubmed_; }
464 
468  void SetYear(int year) { year_ = year; }
469 
470 
474  int GetYear() const { return year_; }
475 
476 
480  void SetTitle(String title) { title_ = title; }
481 
485  String GetTitle() const { return title_; }
486 
490  void SetAuthorList(std::vector<String> list) { authors_ = list; }
491 
495  const std::vector<String>& GetAuthorList() const { return authors_; }
496 
497  bool operator==(const MMCifInfoCitation& cit) const {
498  if (this->year_ != cit.year_) {
499  return false;
500  }
501  if (this->pubmed_ != cit.pubmed_) {
502  return false;
503  }
504  if (this->where_ != cit.where_) {
505  return false;
506  }
507  if (StringRef(this->id_.c_str(), this->id_.length()) !=
508  StringRef(cit.id_.c_str(), cit.id_.length())) {
509  return false;
510  }
511  if (StringRef(this->cas_.c_str(), this->cas_.length()) !=
512  StringRef(cit.cas_.c_str(), cit.cas_.length())) {
513  return false;
514  }
515  if (StringRef(this->isbn_.c_str(), this->isbn_.length()) !=
516  StringRef(cit.isbn_.c_str(), cit.isbn_.length())) {
517  return false;
518  }
519  if (StringRef(this->published_in_.c_str(), this->published_in_.length()) !=
520  StringRef(cit.published_in_.c_str(), cit.published_in_.length())) {
521  return false;
522  }
523  if (StringRef(this->volume_.c_str(), this->volume_.length()) !=
524  StringRef(cit.volume_.c_str(), cit.volume_.length())) {
525  return false;
526  }
527  if (StringRef(this->page_first_.c_str(), this->page_first_.length()) !=
528  StringRef(cit.page_first_.c_str(), cit.page_first_.length())) {
529  return false;
530  }
531  if (StringRef(this->page_last_.c_str(), this->page_last_.length()) !=
532  StringRef(cit.page_last_.c_str(), cit.page_last_.length())) {
533  return false;
534  }
535  if (StringRef(this->doi_.c_str(), this->doi_.length()) !=
536  StringRef(cit.doi_.c_str(), cit.doi_.length())) {
537  return false;
538  }
539  if (StringRef(this->title_.c_str(), this->title_.length()) !=
540  StringRef(cit.title_.c_str(), cit.title_.length())) {
541  return false;
542  }
543  if (this->authors_ != cit.authors_) {
544  return false;
545  }
546 
547  return true;
548  }
549 
550  bool operator!=(const MMCifInfoCitation& cit) const {
551  return !this->operator==(cit);
552  }
553 
554 private:
556  typedef enum {
557  JOURNAL,
558  BOOK,
559  UNKNOWN
560  } MMCifInfoCType;
561 
562  String id_;
563  MMCifInfoCType where_;
564  String cas_;
565  String isbn_;
566  String published_in_;
567  String volume_;
568  String page_first_;
569  String page_last_;
570  String doi_;
571  int pubmed_;
572  int year_;
573  String title_;
574  std::vector<String> authors_;
575 };
576 
579 class DLLEXPORT_OST_IO MMCifInfoObsolete {
580 public:
582  MMCifInfoObsolete(): date_(""), id_(UNKNOWN), pdb_id_(""),
583  replaced_pdb_id_("") {};
584 
588  void SetDate(String date) { date_ = date; }
589 
593  String GetDate() { return date_; }
594 
598  void SetID(StringRef type)
599  {
600  if (type == StringRef("OBSLTE", 6)) {
601  id_ = OBSLTE;
602  }
603  else if (type == StringRef("SPRSDE", 6)) {
604  id_ = SPRSDE;
605  }
606  }
607 
611  String GetID()
612  {
613  if (id_ == OBSLTE) {
614  return "Obsolete";
615  }
616  if (id_ == SPRSDE) {
617  return "Supersede";
618  }
619  return "Unknown";
620  }
621 
625  void SetPDBID(String id) { pdb_id_ = id; }
626 
630  String GetPDBID() { return pdb_id_; }
631 
635  void SetReplacedPDBID(String id) { replaced_pdb_id_ = id; }
636 
640  String GetReplacedPDBID() { return replaced_pdb_id_; }
641 
642 private:
644  typedef enum {
645  OBSLTE,
646  SPRSDE,
647  UNKNOWN
648  } MMCifObsoleteType;
649 
650  String date_;
651  MMCifObsoleteType id_;
652  String pdb_id_;
653  String replaced_pdb_id_;
654 };
655 
658 class DLLEXPORT_OST_IO MMCifInfoRevisions {
659 public:
661  MMCifInfoRevisions(): date_original_("?"), first_release_(0) {};
662 
666  void SetDateOriginal(String date) { date_original_ = date; }
667 
671  String GetDateOriginal() const { return date_original_; }
672 
678  void AddRevision(int num, String date, String status)
679  {
680  if (num_.size() && (num_.back() > num)) {
681  std::stringstream ss;
682  ss << "'num' component of 'database_pdb_rev' category has to increase ";
683  ss << "with every revision, last was ";
684  ss << num_.back();
685  ss << ", trying to add ";
686  ss << num;
687  throw IOException(ss.str());
688  }
689  num_.push_back(num);
690  date_.push_back(date);
691  status_.push_back(status);
692  // set first release date if not already occuoied
693  if (first_release_ == 0) {
694  if (status == "full release") {
695  first_release_ = status_.size();
696  }
697  }
698  }
699 
703  size_t GetSize() const { return num_.size(); }
704 
709  String GetDate(size_t i) const { return date_[i]; }
710 
715  int GetNum(size_t i) const { return num_[i]; }
716 
721  String GetStatus(size_t i) const { return status_[i]; }
722 
726  String GetLastDate() const { return date_.back(); }
727 
731  size_t GetFirstRelease() const
732  {
733  return first_release_;
734  }
735 
736 private:
737  String date_original_;
738  size_t first_release_;
739  std::vector<int> num_;
740  std::vector<String> date_;
741  std::vector<String> status_;
742 };
743 
744 
745 class MMCifInfoStructRef;
746 class MMCifInfoStructRefSeq;
747 class MMCifInfoStructRefSeqDif;
748 
749 
750 typedef boost::shared_ptr<MMCifInfoStructRef> MMCifInfoStructRefPtr;
751 typedef boost::shared_ptr<MMCifInfoStructRefSeq> MMCifInfoStructRefSeqPtr;
752 typedef boost::shared_ptr<MMCifInfoStructRefSeqDif> MMCifInfoStructRefSeqDifPtr;
753 
754 typedef std::vector<MMCifInfoStructRefPtr> MMCifInfoStructRefs;
755 typedef std::vector<MMCifInfoStructRefSeqPtr> MMCifInfoStructRefSeqs;
756 typedef std::vector<MMCifInfoStructRefSeqDifPtr> MMCifInfoStructRefSeqDifs;
757 class DLLEXPORT_OST_IO MMCifInfoStructRef {
758 public:
759  MMCifInfoStructRef(const String& id, const String& ent_id,
760  const String& db_name,
761  const String& db_ident, const String& db_access):
762  id_(id), ent_id_(ent_id), db_name_(db_name), db_ident_(db_ident),
763  db_access_(db_access)
764  { }
765  const String& GetID() const { return id_; }
766  const String& GetDBName() const { return db_name_; }
767  const String& GetDBID() const { return db_ident_; }
768  const String& GetEntityID() const { return ent_id_; }
769  const String& GetDBAccess() const { return db_access_; }
770  MMCifInfoStructRefSeqPtr AddAlignedSeq(const String& align_id,
771  const String& chain_name, int seq_begin,
772  int seq_end, int db_begin, int db_end);
773  MMCifInfoStructRefSeqPtr GetAlignedSeq(const String& align_id) const;
774  MMCifInfoStructRefSeqs GetAlignedSeqs() const
775  {
777  seqs.reserve(seqs_.size());
778  for (std::map<String, MMCifInfoStructRefSeqPtr>::const_iterator
779  i=seqs_.begin(), e=seqs_.end(); i!=e; ++i) {
780  seqs.push_back(i->second);
781  }
782  return seqs;
783  }
784 private:
785  String id_;
786  String ent_id_;
787  String db_name_;
788  String db_ident_;
789  String db_access_;
790  std::map<String, MMCifInfoStructRefSeqPtr> seqs_;
791 };
792 
793 class DLLEXPORT_OST_IO MMCifInfoStructRefSeq {
794 public:
795  MMCifInfoStructRefSeq(const String& align_id, const String& chain_name,
796  int seq_begin, int seq_end,
797  int db_begin, int db_end):
798  id_(align_id), chain_name_(chain_name),
799  seq_begin_(seq_begin), seq_end_(seq_end), db_begin_(db_begin), db_end_(db_end)
800  { }
801 
802  const String& GetID() const { return id_; }
803  const String& GetChainName() const { return chain_name_; }
804  int GetSeqBegin() const { return seq_begin_; }
805  int GetSeqEnd() const { return seq_end_; }
806  int GetDBBegin() const { return db_begin_; }
807  int GetDBEnd() const { return db_end_; }
808  MMCifInfoStructRefSeqDifPtr AddDif(int seq_num, int db_num,
809  const String& details);
810  const std::vector<MMCifInfoStructRefSeqDifPtr>& GetDifs() const { return difs_; }
811 private:
812  String id_;
813  String chain_name_;
814  int seq_begin_;
815  int seq_end_;
816  int db_begin_;
817  int db_end_;
818  std::vector<MMCifInfoStructRefSeqDifPtr> difs_;
819 };
820 
821 class DLLEXPORT_OST_IO MMCifInfoStructRefSeqDif {
822 public:
823  MMCifInfoStructRefSeqDif(int seq_rnum, int db_rnum, const String& details):
824  seq_rnum_(seq_rnum), db_rnum_(db_rnum), details_(details) {}
825  int GetSeqRNum() const { return seq_rnum_;}
826  int GetDBRNum() const { return db_rnum_; }
827  const String& GetDetails() const { return details_; }
828 private:
829  int seq_rnum_;
830  int db_rnum_;
831  String details_;
832 };
833 
847 class DLLEXPORT_OST_IO MMCifInfo {
848 public:
850  MMCifInfo(): exptl_method_(""), resolution_(0.0f) {};
851 
855  void AddCitation(MMCifInfoCitation citation) // unit test
856  {
857  citations_.push_back(citation);
858  }
859 
864  void AddAuthorsToCitation(StringRef id, std::vector<String> list); //unit test
865 
869  const std::vector<MMCifInfoCitation>& GetCitations() const
870  {
871  return citations_;
872  }
873 
877  void SetMethod(String method) { exptl_method_ = method; }
878 
882  const StringRef GetMethod() const
883  {
884  return StringRef(exptl_method_.c_str(), exptl_method_.length());
885  }
886 
890  void SetResolution(Real res) { resolution_ = res; }
891 
895  Real GetResolution() const { return resolution_; }
896 
901  void AddMMCifPDBChainTr(String cif, String pdb);
902 
907  String GetMMCifPDBChainTr(String cif) const;
908 
913  void AddPDBMMCifChainTr(String pdb, String cif);
914 
919  String GetPDBMMCifChainTr(String pdb) const;
920 
924  void AddBioUnit(MMCifInfoBioUnit bu);
925 
929  const std::vector<MMCifInfoBioUnit>& GetBioUnits() const
930  {
931  return biounits_;
932  }
933 
937  void AddOperation(MMCifInfoTransOpPtr op) // unit test
938  {
939  transops_.push_back(op);
940  }
941 
945  const std::vector<MMCifInfoTransOpPtr>& GetOperations() const
946  {
947  return transops_;
948  }
949 
953  void SetStructDetails(MMCifInfoStructDetails details)
954  {
955  struct_details_ = details;
956  }
957 
961  const MMCifInfoStructDetails GetStructDetails() const
962  {
963  return struct_details_;
964  }
965 
969  void SetObsoleteInfo(MMCifInfoObsolete obsolete)
970  {
971  obsolete_ = obsolete;
972  }
973 
977  MMCifInfoObsolete GetObsoleteInfo() const
978  {
979  return obsolete_;
980  }
981  const MMCifInfoStructRefs& GetStructRefs() const { return struct_refs_; }
982  void SetStructRefs(const MMCifInfoStructRefs& sr) { struct_refs_=sr; }
983 
987  void SetRevisionsDateOriginal(String date)
988  {
989  revisions_.SetDateOriginal(date);
990  }
991 
997  void AddRevision(int num, String date, String status)
998  {
999  revisions_.AddRevision(num, date, status);
1000  }
1001 
1005  MMCifInfoRevisions GetRevisions() const
1006  {
1007  return revisions_;
1008  }
1009 //protected:
1010 
1011 private:
1012  // members
1013  String exptl_method_;
1014  Real resolution_;
1015  MMCifInfoStructDetails struct_details_;
1016  MMCifInfoObsolete obsolete_;
1017  MMCifInfoRevisions revisions_;
1018  std::vector<MMCifInfoCitation> citations_;
1019  std::vector<MMCifInfoBioUnit> biounits_;
1020  std::vector<MMCifInfoTransOpPtr> transops_;
1021  MMCifInfoStructRefs struct_refs_;
1022  std::map<String, String> cif_2_pdb_chain_id_;
1023  std::map<String, String> pdb_2_cif_chain_id_;
1024 };
1025 
1026 
1027 }} // ns
1028 
1029 #endif