BALL  1.4.1
 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_COMMON_LIMITS_H
13 # include <BALL/COMMON/limits.h>
14 #endif
15 
16 #ifndef BALL_KERNEL_PROTEIN_H
17 # include <BALL/KERNEL/protein.h>
18 #endif
19 
20 #ifndef BALL_STRUCTURE_PEPTIDES_H
21 # include <BALL/STRUCTURE/peptides.h>
22 #endif
23 
24 #include <vector>
25 
26 namespace BALL
27 {
118  : public CIFFile
119  {
120  public:
121 
122  // constant variables to denote unknown values
123  static const float FLOAT_VALUE_NA;
124  static const int INT_VALUE_NA;
125 
127 
133 
140  {
141  public:
142  SampleCondition();
143 
144  // saveframe name -- referenced in the sample_condition_label
145  // of the saveframe "assigned_chemical_shifts"
147  // Accoring to the NMRStarFile 2.1 documentation
148  // the first entry MUST BE "_Variable_type".
149  // This is why we are allowed to map per type :-)
150  vector<String> types;
154 
155  bool hasType(String type) {return values.has(type);}
156  std::ostream& operator >> (std::ostream& s);
157  };
158 
163  {
164  public:
165 
171  {
172  public:
173  Component();
174  void clear();
175 
182 
183  std::ostream& operator >> (std::ostream& s);
184  };
185 
186  Sample();
187  void clear();
188 
192  vector <Component> components;
193 
194  std::ostream& operator >> (std::ostream& s);
195  };
196 
203  {
204  public:
206 
212  float shift_value;
216 
217  std::ostream& operator >> (std::ostream& s);
218  };
219 
226  {
227  public:
229 
230  // The saveframe's name = set name
231  // can be referenced in the saveframe "assigned_chemical_shifts"
233  std::vector<ShiftReferenceElement> elements;
234 
235  std::ostream& operator >> (std::ostream& s);
236  };
237 
244  {
245  public:
246  NMRAtomData();
247 
252  char atom_type;
253  float shift_value;
254  float error_value;
256 
257  bool operator == (const NMRAtomData& atom) const;
258  std::ostream& operator >> (std::ostream& s);
259  };
260 
261 
271  class BALL_EXPORT NMRAtomDataSet // _Saveframe_category assigned_chemical_shifts
272 
273  {
274  public:
275  NMRAtomDataSet(NMRStarFile* parent);
276 
279  std::vector<NMRAtomData> atom_data;
282  std::vector<String> samples;
283 
284  std::ostream& operator >> (std::ostream& s);
285 
286  protected:
288  };
289 
296  {
297  public:
299  ~EntryInformation();
300 
301  std::ostream& operator >> (std::ostream& s);
302  void clear();
303 
309 
310  };
311 
317  {
318  public:
321  {
322  public:
323  HomologDB();
324 
325  std::ostream& operator >> (std::ostream& s);
326  void clear();
327 
336  };
337 
338 
340 
348  // polymer residue sequence information
351  // we want to allow things like resid 137A, so we cannot use Index
352  // key: index -- value: aminoacidname
354  vector<HomologDB> homolog_database_entries;
355 
356  std::ostream& operator >> (std::ostream& s);
357  void clear();
358  };
359 
360 
366  {
367  // System related information
368  public:
370  {
371  public:
372  RelatedDB();
373 
374  std::ostream& operator >> (std::ostream& s);
375  void clear();
376 
382  };
383 
384 
385  // Central class for convenience
387  {
388  public:
389  ChemicalUnit();
390  std::ostream& operator >> (std::ostream& s);
391  void clear();
392 
397  };
398 
399 
400  MolecularSystem();
401  ~MolecularSystem();
402 
403  ChemicalUnit const& getChemicalUnit(Position i) const { return chemical_units[i]; }
404  ChemicalUnit& getChemicalUnit(Position i) { return chemical_units[i]; }
405 
406  Size getNumberOfChemicalUnits() const {return chemical_units.size(); }
407 
408  // Name of the molecular system
411  vector<ChemicalUnit> chemical_units;
418  // related entries in various DB's
419  vector<RelatedDB> related_database_entries;
420 
422 
423  std::ostream& operator >> (std::ostream& s);
424  void clear();
425  };
426 
427 
433  {
434  public:
439 
440  std::ostream& operator >> (std::ostream& s);
441  };
442 
443 
450  {
451  public:
452 
459  //<saveframe_id, atom_id_in_nmr_atom_data_set>
460  typedef std::pair<Position, Position> BMRBIndex;
461  typedef std::map<Atom const* , BMRBIndex> BALLToBMRBMapping;
462  typedef std::map<const NMRAtomData*, Atom const*> BMRBToBALLMapping;
463  //TODO: Dont use pointer but something more sophisticated!
464 
466 
471 
478  BALLToBMRBMapper(Chain const& chain, const NMRStarFile& nmr_data, const String& chemical_unit);
479 
481  virtual ~BALLToBMRBMapper() {}
482 
484 
487 
489  const Chain* getChain() const {return chain_;}
490 
492  void setChain(Chain const& chain) { chain_ = &chain;
493  num_mismatches_ = -1;
494  num_gaps_ = -1;}
495 
497  void setNMRStarFile(NMRStarFile const& nmrfile) {nmr_data_ = &nmrfile;
498  num_mismatches_ = -1;
499  num_gaps_ = -1;}
500 
502  const NMRStarFile* getNMRStarFile() const {return nmr_data_;}
503 
505  void setNMRAtomDataSet(NMRAtomDataSet const& nmr_atom_data_set){nmr_atom_data_set_= &nmr_atom_data_set;}
506 
508  bool setNMRAtomDataSetByName(String const& chemical_unit_name);
509 
510  // Get the NMRAtomDataSet
511  const NMRAtomDataSet* getNMRAtomDataSet() const{return nmr_atom_data_set_;}
512 
514  BALLToBMRBMapping& getBALLToBMRBMapping() {return ball_to_bmrb_map_;}
515 
517  const BALLToBMRBMapping& getBALLToBMRBMapping() const {return ball_to_bmrb_map_;}
518 
520  BMRBToBALLMapping& getBMRBToBALLMapping() {return bmrb_to_ball_map_;}
521 
523  const BMRBToBALLMapping& getBMRBToBALLMapping() const {return bmrb_to_ball_map_;}
524 
526  int getNumberOfMismatches(){return num_mismatches_;}
527 
529  int getNumberOfGaps(){return num_gaps_;}
530 
532  bool isMapped(const NMRAtomData& nmr_atom) const;
533 
539  const Atom* getBALLAtom(const NMRAtomData& nmr_atom) const;
540 
545  bool isMapped(Atom const* atom) const;
546 
548  BMRBIndex operator () (const Atom* atom);
549 
556  bool createTrivialMapping();
557 
567  bool createMapping(const String& aligned_ball_sequence,
568  const String& aligned_nmrstar_sequence);
569 
572  void clear();
573 
575 
576  protected:
577 
579 
583 
586 
589 
590  // NOTE: do *not* attempt to delete these pointers!
591  const Chain* chain_;
597  bool valid_;
599 
600  private:
601  const Atom* findNMRAtom_(const NMRAtomData& atom) const;
602 
603  };
604 
606 
609 
612  NMRStarFile();
613 
618  NMRStarFile(const String& file_name, File::OpenMode open_mode = std::ios::in);
619 
621  ~NMRStarFile();
623 
624 
628 
632  bool read();
633 
634  /* Read an NMRStarFile and assign the shifts to the
635  given AtomContainer using a trivial standard mapping.
636  If the AtomContainer is a system, the first chain in chosen.
637 
638  @param ac AtomContainer to which the NMRStarfile's shift should be assigned.
639  @return bool - <tt>true</tt> if reading the file was successful
640  */
641  //TODO to be able to use this function, further functions getMapping() and assign() are needed.
642  bool read(AtomContainer& ac);
643 
650  bool assignShifts(BALLToBMRBMapper& ball_to_bmrb_mapping);
651 
663  bool assignShifts(AtomContainer& ac,
664  const String& chemical_unit,
665  const String& aligned_ball_sequence,
666  const String& aligned_nmrstar_sequence);
667 
670  Size getNumberOfAtoms() const;
671 
674  Size getNumberOfShiftsAssigned() const {return number_of_assigned_shifts_;};
675 
678  const std::vector<NMRAtomDataSet>& getNMRData() const;
679 
682  const EntryInformation& getEntryInformation() const {return entry_information_;};
683 
686  const MolecularSystem& getMolecularInformation() const {return molecular_system_;};
687 
690  MolecularSystem& getMolecularInformation() {return molecular_system_;};
691 
692 
695  const MolecularSystem::ChemicalUnit& getChemicalUnitByLabel(String const& label) const;
696 
699  MolecularSystem::ChemicalUnit& getChemicalUnitByLabel(String const& label);
700 
701 
704  bool hasSampleCondition(String name);
705 
708  bool hasSampleCondition(String name) const;
709 
712  SampleCondition& getSampleConditionByName(String name);
713 
716  const SampleCondition& getSampleConditionByName(String name) const;
717 
719  SampleCondition& getSampleCondition(Position i) {return sample_conditions_[i];};
720 
722  const SampleCondition& getSampleCondition(Position i) const {return sample_conditions_[i];};
723 
725  Size getNumberOfSampleConditions() const {return sample_conditions_.size();};
726 
728  const std::vector<SampleCondition>& getSampleConditions() const {return sample_conditions_;};
729 
731  std::vector<SampleCondition>& getSampleConditions() {return sample_conditions_;};
732 
733  // addSampleCondition TODO!!
734 
736  std::vector<Sample> getSamples() const {return samples_;};
737  //const std::vector<Sample>& getSamples() const {return samples_;};
738 
740  Size getNumberOfSamples() const {return samples_.size();};
741 
743  bool hasSample(String label) const;
744 
748  Sample getSample(Position i) const;
749 
753  Sample getSample(String label) const;
754 
756  std::vector<ShiftReferenceSet>& getShiftReferenceSets() {return shift_references_;};
758  const std::vector<ShiftReferenceSet>& getShiftReferenceSets() const {return shift_references_;};
759 
761  Size getNumberOfShiftReferenceSets() const {return shift_references_.size();};
762 
764  bool hasShiftReferenceSet(String name);
765 
767  ShiftReferenceSet& getShiftReferenceSet(Position i) {return shift_references_[i];};
769  const ShiftReferenceSet& getShiftReferenceSet(Position i) const {return shift_references_[i];};
770 
772  const ShiftReferenceSet& getShiftReferenceSetByName(String name) const;
774  ShiftReferenceSet& getShiftReferenceSetByName(String name);
775 
776 
778  std::vector<NMRSpectrometer>& getNMRSpectrometers() {return nmr_spectrometers_;};
780  const std::vector<NMRSpectrometer>& getNMRSpectrometers() const {return nmr_spectrometers_;};
781 
783  Size getNumberOfNMRSpectrometers() const {return nmr_spectrometers_.size();};
784 
786  NMRSpectrometer& getNMRSpectrometer(Position i);
788  const NMRSpectrometer& getNMRSpectrometer(Position i) const;
789 
791  NMRSpectrometer& getNMRSpectrometerByName(String name);
793  const NMRSpectrometer& getNMRSpectrometerByName(String name) const;
794 
796  String getNMRSpectrometerManufacturer(Position i) const;
797 
799  float getNMRSpectrometerFieldStrength(Position i) const;
800 
801 
805  NMRStarFile::MonomericPolymer& getMonomericPolymer(Position i);
806 
810  const NMRStarFile::MonomericPolymer& getMonomericPolymer(Position i) const;
811 
815  NMRStarFile::MonomericPolymer& getMonomericPolymer(const String& name);
816 
820  const NMRStarFile::MonomericPolymer& getMonomericPolymer(const String& name) const;
821 
823  Size getNumberOfMonomericPolymers() const {return monomeric_polymers_.size();};
824 
826  vector<MonomericPolymer> getMonomericPolymers() const {return monomeric_polymers_;};
827 
829  bool hasMonomericPolymer(String name) const;
830 
836  bool isMonomericPolymer(String chemical_unit_label);
837 
841  //TODO: Store changes/additions as Saveframes also in CIFFile
842  void addMonomericPolymer(MonomericPolymer mp);
843 
844 
853  String getResidueSequence(Position i=0) const;
854 
856  bool hasHshifts() const {return has_H_shifts_;};
857 
859  bool hasCshifts() const {return has_C_shifts_;};
860 
862  bool hasNshifts() const {return has_N_shifts_;};
863 
865 
866 
870 
874  bool operator == (const NMRStarFile& f);
875 
879  bool operator != (const NMRStarFile& f);
880 
883  void clear();
884 
886 
887  private:
888 
889  /*_ @name NMRStar file specific Help-Methods
890  */
891  //_@{
892 
894  void readEntryInformation_();
895 
897  void readMolSystem_();
898 
900  void readMonomericPolymers_();
901 
903  void readSampleConditions_();
904 
906  void readShiftReferences_();
907 
909  void readShifts_();
910 
912  void readSamples_();
913 
915  void readNMRSpectrometer_();
916 
918  void findDependiencies_();
919 
921  void setSpecialCharacters_(String characters);
922 
924  bool isValidSingleValue_(String value);
925 
927  float valueToFloat_(String value);
928 
930  int valueToInt_(String value);
936  bool assignShifts_(BALLToBMRBMapper& pdb_to_bmrb_mapping);
937 
938  //_@}
939  /*_ @name NMRStar file specific attributes
940  */
941  //_@{
942 
943  /*_ A flag indicating validity of this instance. A sole NMRStarFile
944  instance cannot be valid, because it does not have any information.
945  */
946  bool valid_;
947 
950 
953 
956 
959 
961  std::vector<NMRAtomDataSet> atom_data_sets_;
962 
964  std::vector<SampleCondition> sample_conditions_;
965 
967  std::vector<Sample> samples_;
968 
970  std::vector<ShiftReferenceSet> shift_references_;
971 
973  std::vector<NMRSpectrometer> nmr_spectrometers_;
974 
976  vector<MonomericPolymer> monomeric_polymers_;
977 
982 
983  // a dummy saveframe
984  SaveFrame dummy_saveframe_;
985 
986  // a dummy sample condition
988 
989  // a dummy sample
991 
992  // a dummy shift reference set
994 
995  // a dummy nmr spectrometer
997 
998  // a dummy nmr spectrometer
1000 
1003  //_@}
1004  };
1005 
1007 } // Namespace BALL
1008 
1009 #endif // BALL_FORMAT_NMRSTARFILE_H