BALL  1.4.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
NMRStarFile.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 
5 #ifndef BALL_FORMAT_NMRSTARFILE_H
6 #define BALL_FORMAT_NMRSTARFILE_H
7 
8 #ifndef BALL_FORMAT_CIFFILE_H
9 # include <BALL/FORMAT/CIFFile.h>
10 #endif
11 
12 #ifndef BALL_KERNEL_PROTEIN_H
13 # include <BALL/KERNEL/protein.h>
14 #endif
15 
16 #ifndef BALL_STRUCTURE_PEPTIDES_H
17 # include <BALL/STRUCTURE/peptides.h>
18 #endif
19 
20 #include <vector>
21 
22 namespace BALL
23 {
114  : public CIFFile
115  {
116  public:
117 
118  // constant variables to denote unknown values
119  static const float FLOAT_VALUE_NA;
120  static const int INT_VALUE_NA;
121 
123 
129 
136  {
137  public:
138  SampleCondition();
139 
140  // saveframe name -- referenced in the sample_condition_label
141  // of the saveframe "assigned_chemical_shifts"
143  // Accoring to the NMRStarFile 2.1 documentation
144  // the first entry MUST BE "_Variable_type".
145  // This is why we are allowed to map per type :-)
146  vector<String> types;
150 
151  bool hasType(String type) {return values.has(type);}
152  std::ostream& operator >> (std::ostream& s);
153  };
154 
159  {
160  public:
161 
167  {
168  public:
169  Component();
170  void clear();
171 
178 
179  std::ostream& operator >> (std::ostream& s);
180  };
181 
182  Sample();
183  void clear();
184 
188  vector <Component> components;
189 
190  std::ostream& operator >> (std::ostream& s);
191  };
192 
199  {
200  public:
202 
208  float shift_value;
212 
213  std::ostream& operator >> (std::ostream& s);
214  };
215 
222  {
223  public:
225 
226  // The saveframe's name = set name
227  // can be referenced in the saveframe "assigned_chemical_shifts"
229  std::vector<ShiftReferenceElement> elements;
230 
231  std::ostream& operator >> (std::ostream& s);
232  };
233 
240  {
241  public:
242  NMRAtomData();
243 
248  char atom_type;
249  float shift_value;
250  float error_value;
252 
253  bool operator == (const NMRAtomData& atom) const;
254  std::ostream& operator >> (std::ostream& s);
255  };
256 
257 
267  class BALL_EXPORT NMRAtomDataSet // _Saveframe_category assigned_chemical_shifts
268 
269  {
270  public:
271  NMRAtomDataSet(NMRStarFile* parent);
272 
275  std::vector<NMRAtomData> atom_data;
278  std::vector<String> samples;
279 
280  std::ostream& operator >> (std::ostream& s);
281 
282  protected:
284  };
285 
292  {
293  public:
295  ~EntryInformation();
296 
297  std::ostream& operator >> (std::ostream& s);
298  void clear();
299 
305 
306  };
307 
313  {
314  public:
317  {
318  public:
319  HomologDB();
320 
321  std::ostream& operator >> (std::ostream& s);
322  void clear();
323 
332  };
333 
334 
336 
344  // polymer residue sequence information
347  // we want to allow things like resid 137A, so we cannot use Index
348  // key: index -- value: aminoacidname
350  vector<HomologDB> homolog_database_entries;
351 
352  std::ostream& operator >> (std::ostream& s);
353  void clear();
354  };
355 
356 
362  {
363  // System related information
364  public:
366  {
367  public:
368  RelatedDB();
369 
370  std::ostream& operator >> (std::ostream& s);
371  void clear();
372 
378  };
379 
380 
381  // Central class for convenience
383  {
384  public:
385  ChemicalUnit();
386  std::ostream& operator >> (std::ostream& s);
387  void clear();
388 
393  };
394 
395 
396  MolecularSystem();
397  ~MolecularSystem();
398 
399  ChemicalUnit const& getChemicalUnit(Position i) const { return chemical_units[i]; }
400  ChemicalUnit& getChemicalUnit(Position i) { return chemical_units[i]; }
401 
402  Size getNumberOfChemicalUnits() const {return chemical_units.size(); }
403 
404  // Name of the molecular system
407  vector<ChemicalUnit> chemical_units;
414  // related entries in various DB's
415  vector<RelatedDB> related_database_entries;
416 
418 
419  std::ostream& operator >> (std::ostream& s);
420  void clear();
421  };
422 
423 
429  {
430  public:
435 
436  std::ostream& operator >> (std::ostream& s);
437  };
438 
439 
446  {
447  public:
448 
455  //<saveframe_id, atom_id_in_nmr_atom_data_set>
456  typedef std::pair<Position, Position> BMRBIndex;
457  typedef std::map<Atom const* , BMRBIndex> BALLToBMRBMapping;
458  typedef std::map<const NMRAtomData*, Atom const*> BMRBToBALLMapping;
459  //TODO: Dont use pointer but something more sophisticated!
460 
462 
467 
474  BALLToBMRBMapper(Chain const& chain, const NMRStarFile& nmr_data, const String& chemical_unit);
475 
477  virtual ~BALLToBMRBMapper() {}
478 
480 
483 
485  const Chain* getChain() const {return chain_;}
486 
488  void setChain(Chain const& chain) { chain_ = &chain;
489  num_mismatches_ = -1;
490  num_gaps_ = -1;}
491 
493  void setNMRStarFile(NMRStarFile const& nmrfile) {nmr_data_ = &nmrfile;
494  num_mismatches_ = -1;
495  num_gaps_ = -1;}
496 
498  const NMRStarFile* getNMRStarFile() const {return nmr_data_;}
499 
501  void setNMRAtomDataSet(NMRAtomDataSet const& nmr_atom_data_set){nmr_atom_data_set_= &nmr_atom_data_set;}
502 
504  bool setNMRAtomDataSetByName(String const& chemical_unit_name);
505 
506  // Get the NMRAtomDataSet
507  const NMRAtomDataSet* getNMRAtomDataSet() const{return nmr_atom_data_set_;}
508 
510  BALLToBMRBMapping& getBALLToBMRBMapping() {return ball_to_bmrb_map_;}
511 
513  const BALLToBMRBMapping& getBALLToBMRBMapping() const {return ball_to_bmrb_map_;}
514 
516  BMRBToBALLMapping& getBMRBToBALLMapping() {return bmrb_to_ball_map_;}
517 
519  const BMRBToBALLMapping& getBMRBToBALLMapping() const {return bmrb_to_ball_map_;}
520 
522  int getNumberOfMismatches(){return num_mismatches_;}
523 
525  int getNumberOfGaps(){return num_gaps_;}
526 
528  bool isMapped(const NMRAtomData& nmr_atom) const;
529 
535  const Atom* getBALLAtom(const NMRAtomData& nmr_atom) const;
536 
541  bool isMapped(Atom const* atom) const;
542 
544  BMRBIndex operator () (const Atom* atom);
545 
552  bool createTrivialMapping();
553 
563  bool createMapping(const String& aligned_ball_sequence,
564  const String& aligned_nmrstar_sequence);
565 
568  void clear();
569 
571 
572  protected:
573 
575 
579 
582 
585 
586  // NOTE: do *not* attempt to delete these pointers!
587  const Chain* chain_;
593  bool valid_;
595 
596  private:
597  const Atom* findNMRAtom_(const NMRAtomData& atom) const;
598 
599  };
600 
602 
605 
608  NMRStarFile();
609 
614  NMRStarFile(const String& file_name, File::OpenMode open_mode = std::ios::in);
615 
617  ~NMRStarFile();
619 
620 
624 
628  bool read();
629 
630  /* Read an NMRStarFile and assign the shifts to the
631  given AtomContainer using a trivial standard mapping.
632  If the AtomContainer is a system, the first chain in chosen.
633 
634  @param ac AtomContainer to which the NMRStarfile's shift should be assigned.
635  @return bool - <tt>true</tt> if reading the file was successful
636  */
637  //TODO to be able to use this function, further functions getMapping() and assign() are needed.
638  bool read(AtomContainer& ac);
639 
646  bool assignShifts(BALLToBMRBMapper& ball_to_bmrb_mapping);
647 
659  bool assignShifts(AtomContainer& ac,
660  const String& chemical_unit,
661  const String& aligned_ball_sequence,
662  const String& aligned_nmrstar_sequence);
663 
666  Size getNumberOfAtoms() const;
667 
670  Size getNumberOfShiftsAssigned() const {return number_of_assigned_shifts_;};
671 
674  const std::vector<NMRAtomDataSet>& getNMRData() const;
675 
678  const EntryInformation& getEntryInformation() const {return entry_information_;};
679 
682  const MolecularSystem& getMolecularInformation() const {return molecular_system_;};
683 
686  MolecularSystem& getMolecularInformation() {return molecular_system_;};
687 
688 
691  const MolecularSystem::ChemicalUnit& getChemicalUnitByLabel(String const& label) const;
692 
695  MolecularSystem::ChemicalUnit& getChemicalUnitByLabel(String const& label);
696 
697 
700  bool hasSampleCondition(String name);
701 
704  bool hasSampleCondition(String name) const;
705 
708  SampleCondition& getSampleConditionByName(String name);
709 
712  const SampleCondition& getSampleConditionByName(String name) const;
713 
715  SampleCondition& getSampleCondition(Position i) {return sample_conditions_[i];};
716 
718  const SampleCondition& getSampleCondition(Position i) const {return sample_conditions_[i];};
719 
721  Size getNumberOfSampleConditions() const {return sample_conditions_.size();};
722 
724  const std::vector<SampleCondition>& getSampleConditions() const {return sample_conditions_;};
725 
727  std::vector<SampleCondition>& getSampleConditions() {return sample_conditions_;};
728 
729  // addSampleCondition TODO!!
730 
732  std::vector<Sample> getSamples() const {return samples_;};
733  //const std::vector<Sample>& getSamples() const {return samples_;};
734 
736  Size getNumberOfSamples() const {return samples_.size();};
737 
739  bool hasSample(String label) const;
740 
744  Sample getSample(Position i) const;
745 
749  Sample getSample(String label) const;
750 
752  std::vector<ShiftReferenceSet>& getShiftReferenceSets() {return shift_references_;};
754  const std::vector<ShiftReferenceSet>& getShiftReferenceSets() const {return shift_references_;};
755 
757  Size getNumberOfShiftReferenceSets() const {return shift_references_.size();};
758 
760  bool hasShiftReferenceSet(String name);
761 
763  ShiftReferenceSet& getShiftReferenceSet(Position i) {return shift_references_[i];};
765  const ShiftReferenceSet& getShiftReferenceSet(Position i) const {return shift_references_[i];};
766 
768  const ShiftReferenceSet& getShiftReferenceSetByName(String name) const;
770  ShiftReferenceSet& getShiftReferenceSetByName(String name);
771 
772 
774  std::vector<NMRSpectrometer>& getNMRSpectrometers() {return nmr_spectrometers_;};
776  const std::vector<NMRSpectrometer>& getNMRSpectrometers() const {return nmr_spectrometers_;};
777 
779  Size getNumberOfNMRSpectrometers() const {return nmr_spectrometers_.size();};
780 
782  NMRSpectrometer& getNMRSpectrometer(Position i);
784  const NMRSpectrometer& getNMRSpectrometer(Position i) const;
785 
787  NMRSpectrometer& getNMRSpectrometerByName(String name);
789  const NMRSpectrometer& getNMRSpectrometerByName(String name) const;
790 
792  String getNMRSpectrometerManufacturer(Position i) const;
793 
795  float getNMRSpectrometerFieldStrength(Position i) const;
796 
797 
801  NMRStarFile::MonomericPolymer& getMonomericPolymer(Position i);
802 
806  const NMRStarFile::MonomericPolymer& getMonomericPolymer(Position i) const;
807 
811  NMRStarFile::MonomericPolymer& getMonomericPolymer(const String& name);
812 
816  const NMRStarFile::MonomericPolymer& getMonomericPolymer(const String& name) const;
817 
819  Size getNumberOfMonomericPolymers() const {return monomeric_polymers_.size();};
820 
822  vector<MonomericPolymer> getMonomericPolymers() const {return monomeric_polymers_;};
823 
825  bool hasMonomericPolymer(String name) const;
826 
832  bool isMonomericPolymer(String chemical_unit_label);
833 
837  //TODO: Store changes/additions as Saveframes also in CIFFile
838  void addMonomericPolymer(MonomericPolymer mp);
839 
840 
849  String getResidueSequence(Position i=0) const;
850 
852  bool hasHshifts() const {return has_H_shifts_;};
853 
855  bool hasCshifts() const {return has_C_shifts_;};
856 
858  bool hasNshifts() const {return has_N_shifts_;};
859 
861 
862 
866 
870  bool operator == (const NMRStarFile& f);
871 
875  bool operator != (const NMRStarFile& f);
876 
879  void clear();
880 
882 
883  private:
884 
885  /*_ @name NMRStar file specific Help-Methods
886  */
887  //_@{
888 
890  void readEntryInformation_();
891 
893  void readMolSystem_();
894 
896  void readMonomericPolymers_();
897 
899  void readSampleConditions_();
900 
902  void readShiftReferences_();
903 
905  void readShifts_();
906 
908  void readSamples_();
909 
911  void readNMRSpectrometer_();
912 
914  void findDependiencies_();
915 
917  void setSpecialCharacters_(String characters);
918 
920  bool isValidSingleValue_(String value);
921 
923  float valueToFloat_(String value);
924 
926  int valueToInt_(String value);
932  bool assignShifts_(BALLToBMRBMapper& pdb_to_bmrb_mapping);
933 
934  //_@}
935  /*_ @name NMRStar file specific attributes
936  */
937  //_@{
938 
939  /*_ A flag indicating validity of this instance. A sole NMRStarFile
940  instance cannot be valid, because it does not have any information.
941  */
942  bool valid_;
943 
946 
949 
952 
955 
957  std::vector<NMRAtomDataSet> atom_data_sets_;
958 
960  std::vector<SampleCondition> sample_conditions_;
961 
963  std::vector<Sample> samples_;
964 
966  std::vector<ShiftReferenceSet> shift_references_;
967 
969  std::vector<NMRSpectrometer> nmr_spectrometers_;
970 
972  vector<MonomericPolymer> monomeric_polymers_;
973 
978 
979  // a dummy saveframe
980  SaveFrame dummy_saveframe_;
981 
982  // a dummy sample condition
984 
985  // a dummy sample
987 
988  // a dummy shift reference set
990 
991  // a dummy nmr spectrometer
993 
994  // a dummy nmr spectrometer
996 
999  //_@}
1000  };
1001 
1003 } // Namespace BALL
1004 
1005 #endif // BALL_FORMAT_NMRSTARFILE_H