From e7536c15d87cf6da6a3a426ee34cdb2f64676222 Mon Sep 17 00:00:00 2001 From: Marco Biasini <marco.biasini@unibas.ch> Date: Tue, 9 Aug 2011 11:11:45 +0200 Subject: [PATCH] strip whitespace characters from SEQRES entries --- modules/base/src/string_ref.cc | 13 +++++++++++++ modules/base/src/string_ref.hh | 4 ++++ modules/io/src/mol/mmcif_reader.cc | 7 ++++--- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/modules/base/src/string_ref.cc b/modules/base/src/string_ref.cc index 5cc42986b..6a1d62254 100644 --- a/modules/base/src/string_ref.cc +++ b/modules/base/src/string_ref.cc @@ -113,4 +113,17 @@ std::vector<StringRef> StringRef::split(char p) const return result; } +std::string StringRef::str_no_whitespace() const +{ + std::string whitespaceless_string; + whitespaceless_string.reserve(this->size()); + for (const char* s=begin_; s!=end_; ++s) { + if (isspace(*s)) { + continue; + } + whitespaceless_string.push_back(*s); + + } + return whitespaceless_string; +} } diff --git a/modules/base/src/string_ref.hh b/modules/base/src/string_ref.hh index cc5661eba..d72a27a85 100644 --- a/modules/base/src/string_ref.hh +++ b/modules/base/src/string_ref.hh @@ -147,6 +147,10 @@ public: /// \brief split string into chunks delimited by \p p std::vector<StringRef> split(char p) const; + + /// \brief returns a new string with all whitespace removed from + /// this StringRef + std::string str_no_whitespace() const; private: const char* begin_; const char* end_; diff --git a/modules/io/src/mol/mmcif_reader.cc b/modules/io/src/mol/mmcif_reader.cc index b766d74fb..98c357225 100644 --- a/modules/io/src/mol/mmcif_reader.cc +++ b/modules/io/src/mol/mmcif_reader.cc @@ -518,22 +518,23 @@ void MMCifParser::ParseEntityPoly(const std::vector<StringRef>& columns) this->GetCurrentLinenum())); } if (read_seqres_) { + StringRef seqres; if (seqres_can_) { if (indices_[PDBX_SEQ_ONE_LETTER_CODE_CAN] != -1) { - edm_it->second.seqres = - columns[indices_[PDBX_SEQ_ONE_LETTER_CODE_CAN]].str(); + seqres=columns[indices_[PDBX_SEQ_ONE_LETTER_CODE_CAN]]; } else { throw IOException(this->FormatDiagnostic(STAR_DIAG_ERROR, "'entity_poly.pdbx_seq_one_letter_code_can' not available.'", this->GetCurrentLinenum())); } } else if (indices_[PDBX_SEQ_ONE_LETTER_CODE] != -1) { - edm_it->second.seqres = columns[indices_[PDBX_SEQ_ONE_LETTER_CODE]].str(); + seqres=columns[indices_[PDBX_SEQ_ONE_LETTER_CODE]]; } else { throw IOException(this->FormatDiagnostic(STAR_DIAG_ERROR, "'entity_poly.pdbx_seq_one_letter_code' not available.'", this->GetCurrentLinenum())); } + edm_it->second.seqres = seqres.str_no_whitespace(); } } -- GitLab