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 SetMethodDetails(String method_details) {
271  method_details_ = method_details;
272  }
276  String GetMethodDetails() const { return method_details_; }
277 
281  void AddChain(String chain);
282 
286  void SetChainList(std::vector<String> chains);
287 
291  const std::vector<String>& GetChainList() const { return chains_; }
292 
296  const std::vector<std::pair<int, int> >& GetChainIntervalList()
297  {
298  return tr_chains_;
299  }
300 
304  void AddOperations(std::vector<MMCifInfoTransOpPtr> operations);
305 
309  const std::vector<std::pair<int, int> >& GetOperationsIntervalList()
310  {
311  return tr_operations_;
312  }
313 
317  const std::vector<std::vector<MMCifInfoTransOpPtr> >& GetOperations()
318  {
319  return operations_;
320  }
321 
322  bool operator==(const MMCifInfoBioUnit& bu) const {
323  if (this->id_ != bu.id_) {
324  return false;
325  }
326  if (this->details_ != bu.details_) {
327  return false;
328  }
329  if (this->chains_ != bu.chains_) {
330  return false;
331  }
332  if (this->tr_chains_ != bu.tr_chains_) {
333  return false;
334  }
335  if (this->tr_operations_ != bu.tr_operations_) {
336  return false;
337  }
338  if (this->operations_.size() == bu.operations_.size()) {
339  std::vector<std::vector<MMCifInfoTransOpPtr> >::const_iterator th_ops_it;
340  std::vector<std::vector<MMCifInfoTransOpPtr> >::const_iterator bu_ops_it;
341  std::vector<MMCifInfoTransOpPtr>::const_iterator th_op_it;
342  std::vector<MMCifInfoTransOpPtr>::const_iterator bu_op_it;
343 
344  for (th_ops_it = this->operations_.begin(),
345  bu_ops_it = bu.operations_.begin();
346  th_ops_it != this->operations_.end();
347  ++th_ops_it, ++bu_ops_it) {
348  if (th_ops_it->size() == bu_ops_it->size()) {
349  for (th_op_it = th_ops_it->begin(), bu_op_it = bu_ops_it->begin();
350  th_op_it != th_ops_it->end();
351  ++th_op_it, ++bu_op_it) {
352  if (*th_op_it != *bu_op_it) {
353  return false;
354  }
355  }
356  } else {
357  return false;
358  }
359  }
360  } else {
361  return false;
362  }
363 
364  return true;
365  }
366 
367  bool operator!=(const MMCifInfoBioUnit& bu) const {
368  return !this->operator==(bu);
369  }
370 
371 private:
372  String id_;
373  String details_;
374  String method_details_;
375  std::vector<String> chains_;
376  std::vector<std::pair<int, int> > tr_chains_; //< chains of a transformation
377  std::vector<std::vector<MMCifInfoTransOpPtr> > operations_;
378  std::vector<std::pair<int, int> > tr_operations_; //< ops. of a transformation
379 };
380 
381 class DLLEXPORT_OST_IO MMCifInfoCitation {
382 public:
384  MMCifInfoCitation(): id_(""), where_(UNKNOWN), cas_(""), published_in_(""),
385  volume_(""), page_first_(""), page_last_(""), doi_(""), pubmed_(0),
386  year_(0), title_("") {};
387 
391  void SetID(String id) { id_ = id; }
395  String GetID() const { return id_; }
396 
400  void SetCAS(String id) { cas_ = id; }
404  String GetCAS() const { return cas_; }
405 
409  void SetISBN(String code) { isbn_ = code; }
410 
414  String GetISBN() const { return isbn_; }
415 
419  void SetPublishedIn(String title) { published_in_ = title; }
420 
424  String GetPublishedIn() const { return published_in_; }
425 
429  void SetVolume(String volume) { volume_ = volume; }
430 
434  String GetVolume() const { return volume_; }
435 
439  void SetPageFirst(String first) { page_first_ = first; }
440 
444  String GetPageFirst() const { return page_first_; }
445 
449  void SetPageLast(String last) { page_last_ = last; }
450 
454  String GetPageLast() const { return page_last_; }
455 
459  void SetDOI(String doi) { doi_ = doi; }
460 
461 
465  String GetDOI() const { return doi_; }
466 
470  void SetPubMed(int no) { pubmed_ = no; }
471 
475  int GetPubMed() const { return pubmed_; }
476 
480  void SetYear(int year) { year_ = year; }
481 
482 
486  int GetYear() const { return year_; }
487 
488 
492  void SetTitle(String title) { title_ = title; }
493 
497  String GetTitle() const { return title_; }
498 
502  void SetAuthorList(std::vector<String> list) { authors_ = list; }
503 
507  const std::vector<String>& GetAuthorList() const { return authors_; }
508 
509  bool operator==(const MMCifInfoCitation& cit) const {
510  if (this->year_ != cit.year_) {
511  return false;
512  }
513  if (this->pubmed_ != cit.pubmed_) {
514  return false;
515  }
516  if (this->where_ != cit.where_) {
517  return false;
518  }
519  if (StringRef(this->id_.c_str(), this->id_.length()) !=
520  StringRef(cit.id_.c_str(), cit.id_.length())) {
521  return false;
522  }
523  if (StringRef(this->cas_.c_str(), this->cas_.length()) !=
524  StringRef(cit.cas_.c_str(), cit.cas_.length())) {
525  return false;
526  }
527  if (StringRef(this->isbn_.c_str(), this->isbn_.length()) !=
528  StringRef(cit.isbn_.c_str(), cit.isbn_.length())) {
529  return false;
530  }
531  if (StringRef(this->published_in_.c_str(), this->published_in_.length()) !=
532  StringRef(cit.published_in_.c_str(), cit.published_in_.length())) {
533  return false;
534  }
535  if (StringRef(this->volume_.c_str(), this->volume_.length()) !=
536  StringRef(cit.volume_.c_str(), cit.volume_.length())) {
537  return false;
538  }
539  if (StringRef(this->page_first_.c_str(), this->page_first_.length()) !=
540  StringRef(cit.page_first_.c_str(), cit.page_first_.length())) {
541  return false;
542  }
543  if (StringRef(this->page_last_.c_str(), this->page_last_.length()) !=
544  StringRef(cit.page_last_.c_str(), cit.page_last_.length())) {
545  return false;
546  }
547  if (StringRef(this->doi_.c_str(), this->doi_.length()) !=
548  StringRef(cit.doi_.c_str(), cit.doi_.length())) {
549  return false;
550  }
551  if (StringRef(this->title_.c_str(), this->title_.length()) !=
552  StringRef(cit.title_.c_str(), cit.title_.length())) {
553  return false;
554  }
555  if (this->authors_ != cit.authors_) {
556  return false;
557  }
558 
559  return true;
560  }
561 
562  bool operator!=(const MMCifInfoCitation& cit) const {
563  return !this->operator==(cit);
564  }
565 
566 private:
568  typedef enum {
569  JOURNAL,
570  BOOK,
571  UNKNOWN
572  } MMCifInfoCType;
573 
574  String id_;
575  MMCifInfoCType where_;
576  String cas_;
577  String isbn_;
578  String published_in_;
579  String volume_;
580  String page_first_;
581  String page_last_;
582  String doi_;
583  int pubmed_;
584  int year_;
585  String title_;
586  std::vector<String> authors_;
587 };
588 
591 class DLLEXPORT_OST_IO MMCifInfoObsolete {
592 public:
594  MMCifInfoObsolete(): date_(""), id_(UNKNOWN), pdb_id_(""),
595  replaced_pdb_id_("") {};
596 
600  void SetDate(String date) { date_ = date; }
601 
605  String GetDate() { return date_; }
606 
610  void SetID(StringRef type)
611  {
612  if (type == StringRef("OBSLTE", 6)) {
613  id_ = OBSLTE;
614  }
615  else if (type == StringRef("SPRSDE", 6)) {
616  id_ = SPRSDE;
617  }
618  }
619 
623  String GetID()
624  {
625  if (id_ == OBSLTE) {
626  return "Obsolete";
627  }
628  if (id_ == SPRSDE) {
629  return "Supersede";
630  }
631  return "Unknown";
632  }
633 
637  void SetPDBID(String id) { pdb_id_ = id; }
638 
642  String GetPDBID() { return pdb_id_; }
643 
647  void SetReplacedPDBID(String id) { replaced_pdb_id_ = id; }
648 
652  String GetReplacedPDBID() { return replaced_pdb_id_; }
653 
654 private:
656  typedef enum {
657  OBSLTE,
658  SPRSDE,
659  UNKNOWN
660  } MMCifObsoleteType;
661 
662  String date_;
663  MMCifObsoleteType id_;
664  String pdb_id_;
665  String replaced_pdb_id_;
666 };
667 
670 class DLLEXPORT_OST_IO MMCifInfoRevisions {
671 public:
673  MMCifInfoRevisions(): date_original_("?"), first_release_(0) {};
674 
678  void SetDateOriginal(String date) { date_original_ = date; }
679 
683  String GetDateOriginal() const { return date_original_; }
684 
690  void AddRevision(int num, String date, String status)
691  {
692  if (num_.size() && (num_.back() > num)) {
693  std::stringstream ss;
694  ss << "'num' component of 'database_pdb_rev' category has to increase ";
695  ss << "with every revision, last was ";
696  ss << num_.back();
697  ss << ", trying to add ";
698  ss << num;
699  throw IOException(ss.str());
700  }
701  num_.push_back(num);
702  date_.push_back(date);
703  status_.push_back(status);
704  // set first release date if not already occuoied
705  if (first_release_ == 0) {
706  if (status == "full release") {
707  first_release_ = status_.size();
708  }
709  }
710  }
711 
715  size_t GetSize() const { return num_.size(); }
716 
721  String GetDate(size_t i) const { return date_[i]; }
722 
727  int GetNum(size_t i) const { return num_[i]; }
728 
733  String GetStatus(size_t i) const { return status_[i]; }
734 
738  String GetLastDate() const { return date_.back(); }
739 
743  size_t GetFirstRelease() const
744  {
745  return first_release_;
746  }
747 
748 private:
749  String date_original_;
750  size_t first_release_;
751  std::vector<int> num_;
752  std::vector<String> date_;
753  std::vector<String> status_;
754 };
755 
756 
757 class MMCifInfoStructRef;
758 class MMCifInfoStructRefSeq;
759 class MMCifInfoStructRefSeqDif;
760 
761 
762 typedef boost::shared_ptr<MMCifInfoStructRef> MMCifInfoStructRefPtr;
763 typedef boost::shared_ptr<MMCifInfoStructRefSeq> MMCifInfoStructRefSeqPtr;
764 typedef boost::shared_ptr<MMCifInfoStructRefSeqDif> MMCifInfoStructRefSeqDifPtr;
765 
766 typedef std::vector<MMCifInfoStructRefPtr> MMCifInfoStructRefs;
767 typedef std::vector<MMCifInfoStructRefSeqPtr> MMCifInfoStructRefSeqs;
768 typedef std::vector<MMCifInfoStructRefSeqDifPtr> MMCifInfoStructRefSeqDifs;
769 class DLLEXPORT_OST_IO MMCifInfoStructRef {
770 public:
771  MMCifInfoStructRef(const String& id, const String& ent_id,
772  const String& db_name,
773  const String& db_ident, const String& db_access):
774  id_(id), ent_id_(ent_id), db_name_(db_name), db_ident_(db_ident),
775  db_access_(db_access)
776  { }
777  const String& GetID() const { return id_; }
778  const String& GetDBName() const { return db_name_; }
779  const String& GetDBID() const { return db_ident_; }
780  const String& GetEntityID() const { return ent_id_; }
781  const String& GetDBAccess() const { return db_access_; }
782  MMCifInfoStructRefSeqPtr AddAlignedSeq(const String& align_id,
783  const String& chain_name, int seq_begin,
784  int seq_end, int db_begin, int db_end);
785  MMCifInfoStructRefSeqPtr GetAlignedSeq(const String& align_id) const;
786  MMCifInfoStructRefSeqs GetAlignedSeqs() const
787  {
789  seqs.reserve(seqs_.size());
790  for (std::map<String, MMCifInfoStructRefSeqPtr>::const_iterator
791  i=seqs_.begin(), e=seqs_.end(); i!=e; ++i) {
792  seqs.push_back(i->second);
793  }
794  return seqs;
795  }
796 private:
797  String id_;
798  String ent_id_;
799  String db_name_;
800  String db_ident_;
801  String db_access_;
802  std::map<String, MMCifInfoStructRefSeqPtr> seqs_;
803 };
804 
805 class DLLEXPORT_OST_IO MMCifInfoStructRefSeq {
806 public:
807  MMCifInfoStructRefSeq(const String& align_id, const String& chain_name,
808  int seq_begin, int seq_end,
809  int db_begin, int db_end):
810  id_(align_id), chain_name_(chain_name),
811  seq_begin_(seq_begin), seq_end_(seq_end), db_begin_(db_begin), db_end_(db_end)
812  { }
813 
814  const String& GetID() const { return id_; }
815  const String& GetChainName() const { return chain_name_; }
816  int GetSeqBegin() const { return seq_begin_; }
817  int GetSeqEnd() const { return seq_end_; }
818  int GetDBBegin() const { return db_begin_; }
819  int GetDBEnd() const { return db_end_; }
820  MMCifInfoStructRefSeqDifPtr AddDif(int seq_num, int db_num,
821  const String& details);
822  const std::vector<MMCifInfoStructRefSeqDifPtr>& GetDifs() const { return difs_; }
823 private:
824  String id_;
825  String chain_name_;
826  int seq_begin_;
827  int seq_end_;
828  int db_begin_;
829  int db_end_;
830  std::vector<MMCifInfoStructRefSeqDifPtr> difs_;
831 };
832 
833 class DLLEXPORT_OST_IO MMCifInfoStructRefSeqDif {
834 public:
835  MMCifInfoStructRefSeqDif(int seq_rnum, int db_rnum, const String& details):
836  seq_rnum_(seq_rnum), db_rnum_(db_rnum), details_(details) {}
837  int GetSeqRNum() const { return seq_rnum_;}
838  int GetDBRNum() const { return db_rnum_; }
839  const String& GetDetails() const { return details_; }
840 private:
841  int seq_rnum_;
842  int db_rnum_;
843  String details_;
844 };
845 
859 class DLLEXPORT_OST_IO MMCifInfo {
860 public:
862  MMCifInfo(): exptl_method_(""), resolution_(0.0f) {};
863 
867  void AddCitation(MMCifInfoCitation citation) // unit test
868  {
869  citations_.push_back(citation);
870  }
871 
876  void AddAuthorsToCitation(StringRef id, std::vector<String> list); //unit test
877 
881  const std::vector<MMCifInfoCitation>& GetCitations() const
882  {
883  return citations_;
884  }
885 
889  void SetMethod(String method) { exptl_method_ = method; }
890 
894  const StringRef GetMethod() const
895  {
896  return StringRef(exptl_method_.c_str(), exptl_method_.length());
897  }
898 
902  void SetResolution(Real res) { resolution_ = res; }
903 
907  Real GetResolution() const { return resolution_; }
908 
913  void AddMMCifPDBChainTr(String cif, String pdb);
914 
919  String GetMMCifPDBChainTr(String cif) const;
920 
925  void AddPDBMMCifChainTr(String pdb, String cif);
926 
931  String GetPDBMMCifChainTr(String pdb) const;
932 
936  void AddBioUnit(MMCifInfoBioUnit bu);
937 
941  const std::vector<MMCifInfoBioUnit>& GetBioUnits() const
942  {
943  return biounits_;
944  }
945 
949  void AddOperation(MMCifInfoTransOpPtr op) // unit test
950  {
951  transops_.push_back(op);
952  }
953 
957  const std::vector<MMCifInfoTransOpPtr>& GetOperations() const
958  {
959  return transops_;
960  }
961 
965  void SetStructDetails(MMCifInfoStructDetails details)
966  {
967  struct_details_ = details;
968  }
969 
973  const MMCifInfoStructDetails GetStructDetails() const
974  {
975  return struct_details_;
976  }
977 
981  void SetObsoleteInfo(MMCifInfoObsolete obsolete)
982  {
983  obsolete_ = obsolete;
984  }
985 
989  MMCifInfoObsolete GetObsoleteInfo() const
990  {
991  return obsolete_;
992  }
993  const MMCifInfoStructRefs& GetStructRefs() const { return struct_refs_; }
994  void SetStructRefs(const MMCifInfoStructRefs& sr) { struct_refs_=sr; }
995 
999  void SetRevisionsDateOriginal(String date)
1000  {
1001  revisions_.SetDateOriginal(date);
1002  }
1003 
1009  void AddRevision(int num, String date, String status)
1010  {
1011  revisions_.AddRevision(num, date, status);
1012  }
1013 
1017  MMCifInfoRevisions GetRevisions() const
1018  {
1019  return revisions_;
1020  }
1021 //protected:
1022 
1023 private:
1024  // members
1025  String exptl_method_;
1026  Real resolution_;
1027  MMCifInfoStructDetails struct_details_;
1028  MMCifInfoObsolete obsolete_;
1029  MMCifInfoRevisions revisions_;
1030  std::vector<MMCifInfoCitation> citations_;
1031  std::vector<MMCifInfoBioUnit> biounits_;
1032  std::vector<MMCifInfoTransOpPtr> transops_;
1033  MMCifInfoStructRefs struct_refs_;
1034  std::map<String, String> cif_2_pdb_chain_id_;
1035  std::map<String, String> pdb_2_cif_chain_id_;
1036 };
1037 
1038 
1039 }} // ns
1040 
1041 #endif