// PdbSeqresParser.cpp #include #include #include "PdbSeqresParser.hpp" namespace NGBW { // PdbSeqresParser bool PdbSeqresParser::Parse(PdbSeqresRecord &record) { record.clear(); if (m_line == NULL) ReadNextLine(); while (1) { if (m_input.Eof()) return false; if (m_line[0] == '>') { ParseHeader(record); break; } ReadNextLine(); } while (1) { if (m_input.Eof() || m_line[0] == '>') break; record.sequence.append(m_line); ReadNextLine(); } return true; } void PdbSeqresParser::ParseHeader(PdbSeqresRecord &record) { size_t length = std::strlen(m_line); size_t last = FindFirstSpace(1); if (last == std::string::npos) last = length; size_t index = 1; while (index < last) { record.protein_id.push_back(std::toupper(m_line[index])); index += 1; if (m_line[index] == '_') { index += 1; break; } } while (index < last) { record.chain_id.push_back(m_line[index]); index += 1; } if (last < length) { const char *sub_string = std::strstr(m_line + last, "length:"); if (sub_string != NULL) { size_t first = (sub_string - m_line) + 7; last = FindFirstSpace(first + 1); if (last == std::string::npos) last = length; record.length.assign(m_line + first, last - first); } } ReadNextLine(); } } // namespace NGBW