Commit 08de217b by Maarten L. Hekkelman

implemented operator[]

parent 3d93672f
...@@ -2117,6 +2117,17 @@ DSSP::iterator DSSP::end() const ...@@ -2117,6 +2117,17 @@ DSSP::iterator DSSP::end() const
return iterator(res); return iterator(res);
} }
DSSP::residue_info DSSP::operator[](const key_type &key) const
{
auto i = std::find_if(begin(), end(),
[key](const residue_info &res) { return res.asym_id() == std::get<0>(key) and res.seq_id() == std::get<1>(key); });
if (i == end())
throw std::out_of_range("Could not find residue with supplied key");
return *i;
}
statistics DSSP::get_statistics() const statistics DSSP::get_statistics() const
{ {
return m_impl->mStats; return m_impl->mStats;
......
...@@ -183,4 +183,41 @@ BOOST_AUTO_TEST_CASE(dssp_1) ...@@ -183,4 +183,41 @@ BOOST_AUTO_TEST_CASE(dssp_1)
BOOST_CHECK_EQUAL(residue.seq_id(), seqID); BOOST_CHECK_EQUAL(residue.seq_id(), seqID);
BOOST_CHECK_EQUAL((char)residue.type(), secstr.front()); BOOST_CHECK_EQUAL((char)residue.type(), secstr.front());
} }
}
// --------------------------------------------------------------------
BOOST_AUTO_TEST_CASE(dssp_2)
{
cif::file f(gTestDir / "1cbs.cif.gz");
BOOST_ASSERT(f.is_valid());
dssp::DSSP dssp(f.front(), 1, 3, true);
std::ifstream t(gTestDir / "1cbs-dssp-test.tsv");
std::string line;
while (getline(t, line))
{
auto f = cif::split(line, "\t");
BOOST_CHECK_EQUAL(f.size(), 3);
if (f.size() != 3)
continue;
int seqID;
std::from_chars(f[0].begin(), f[0].end(), seqID);
std::string asymID{ f[1] };
std::string secstr{ f[2] };
if (secstr == "_")
secstr = " ";
dssp::DSSP::key_type key{ asymID, seqID };
auto ri = dssp[key];
BOOST_CHECK_EQUAL(ri.asym_id(), asymID);
BOOST_CHECK_EQUAL(ri.seq_id(), seqID);
BOOST_CHECK_EQUAL((char)ri.type(), secstr.front());
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment