Commit ebb27638 by Maarten L. Hekkelman

renaming compound code...

parent 3eb7e4c5
...@@ -23,3 +23,5 @@ msvc/.vs/ ...@@ -23,3 +23,5 @@ msvc/.vs/
msvc/**/Debug msvc/**/Debug
msvc/**/x64 msvc/**/x64
.vs/ .vs/
data/
test/rename-compound-test
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -116,6 +116,7 @@ class Atom ...@@ -116,6 +116,7 @@ class Atom
std::string labelAtomID() const; std::string labelAtomID() const;
std::string labelCompID() const; std::string labelCompID() const;
std::string labelAsymID() const; std::string labelAsymID() const;
std::string labelEntityID() const;
int labelSeqID() const; int labelSeqID() const;
std::string labelAltID() const; std::string labelAltID() const;
bool isAlternate() const; bool isAlternate() const;
...@@ -224,6 +225,7 @@ class Residue ...@@ -224,6 +225,7 @@ class Residue
const std::string& compoundID() const { return mCompoundID; } const std::string& compoundID() const { return mCompoundID; }
const std::string& asymID() const { return mAsymID; } const std::string& asymID() const { return mAsymID; }
int seqID() const { return mSeqID; } int seqID() const { return mSeqID; }
std::string entityID() const;
std::string authAsymID() const; std::string authAsymID() const;
std::string authSeqID() const; std::string authSeqID() const;
......
...@@ -2502,6 +2502,8 @@ void Category::update_value(RowSet &&rows, const std::string &tag, const std::st ...@@ -2502,6 +2502,8 @@ void Category::update_value(RowSet &&rows, const std::string &tag, const std::st
// we cannot simply rename the child but will have to create a new child. Unless that new // we cannot simply rename the child but will have to create a new child. Unless that new
// child already exists of course. // child already exists of course.
RowSet process(*childCat);
for (auto child: children) for (auto child: children)
{ {
Condition cond; Condition cond;
...@@ -2518,7 +2520,10 @@ void Category::update_value(RowSet &&rows, const std::string &tag, const std::st ...@@ -2518,7 +2520,10 @@ void Category::update_value(RowSet &&rows, const std::string &tag, const std::st
auto parents = find(std::move(cond)); auto parents = find(std::move(cond));
if (parents.empty()) if (parents.empty())
{
process.push_back(child);
continue; continue;
}
// oops, we need to split this child, unless a row already exists for the new value // oops, we need to split this child, unless a row already exists for the new value
Condition check; Condition check;
...@@ -2540,11 +2545,14 @@ void Category::update_value(RowSet &&rows, const std::string &tag, const std::st ...@@ -2540,11 +2545,14 @@ void Category::update_value(RowSet &&rows, const std::string &tag, const std::st
continue; continue;
// create the actual copy // create the actual copy
childCat->copyRow(child); auto copy = childCat->copyRow(child);
if (copy != child)
process.push_back(child);
} }
// finally, update the children // finally, update the children
childCat->update_value(std::move(children), childTag, value); if (not process.empty())
childCat->update_value(std::move(process), childTag, value);
} }
} }
} }
......
...@@ -605,6 +605,11 @@ std::string Atom::labelAsymID() const ...@@ -605,6 +605,11 @@ std::string Atom::labelAsymID() const
return impl()->mAsymID; return impl()->mAsymID;
} }
std::string Atom::labelEntityID() const
{
return property<std::string>("label_entity_id");
}
std::string Atom::labelAltID() const std::string Atom::labelAltID() const
{ {
return impl()->mAltID; return impl()->mAltID;
...@@ -841,6 +846,11 @@ Residue::~Residue() ...@@ -841,6 +846,11 @@ Residue::~Residue()
//std::cerr << "~Residue" << std::endl; //std::cerr << "~Residue" << std::endl;
} }
std::string Residue::entityID() const
{
return mAtoms.empty() ? "" : mAtoms.front().labelEntityID();
}
std::string Residue::authInsCode() const std::string Residue::authInsCode() const
{ {
assert(mStructure); assert(mStructure);
...@@ -2096,7 +2106,7 @@ void Structure::insertCompound(const std::string& compoundID, bool isEntity) ...@@ -2096,7 +2106,7 @@ void Structure::insertCompound(const std::string& compoundID, bool isEntity)
if (isEntity) if (isEntity)
{ {
auto& pdbxEntityNonpoly = db["pdbx_entity_nonpoly"]; auto& pdbxEntityNonpoly = db["pdbx_entity_nonpoly"];
if (pdbxEntityNonpoly.find(cif::Key("comp_id") == compoundID).empty()) if (not pdbxEntityNonpoly.exists(cif::Key("comp_id") == compoundID))
{ {
auto& entity = db["entity"]; auto& entity = db["entity"];
std::string entityID = std::to_string(entity.size() + 1); std::string entityID = std::to_string(entity.size() + 1);
...@@ -2239,19 +2249,66 @@ void Structure::changeResidue(const Residue& res, const std::string& newCompound ...@@ -2239,19 +2249,66 @@ void Structure::changeResidue(const Residue& res, const std::string& newCompound
{ {
using namespace cif::literals; using namespace cif::literals;
cif::Datablock& db = *mFile.impl().mDb;
std::string asymID = res.asymID();
const auto compound = Compound::create(newCompound); const auto compound = Compound::create(newCompound);
if (not compound) if (not compound)
throw std::runtime_error("Unknown compound " + newCompound); throw std::runtime_error("Unknown compound " + newCompound);
cif::Datablock& db = *mFile.impl().mDb; // First make sure the compound is already known or insert it.
// And if the residue is an entity, we must make sure it exists
std::string asymID = res.asymID();
std::string entityID; std::string entityID;
std::tie(entityID) = db["struct_asym"].find1<std::string>("id"_key == asymID, { "entity_id" }); if (res.isEntity())
{
// create a copy of the entity first
auto &entity = db["entity"];
try
{
std::tie(entityID) = entity.find1<std::string>("type"_key == "non-polymer" and "pdbx_description"_key == compound->name(), { "id" });
}
catch (const std::exception& ex)
{
entityID = entity.getUniqueID("");
entity.emplace({
{ "id", entityID },
{ "type", "non-polymer" },
{ "pdbx_description", compound->name() },
{ "formula_weight", compound->formulaWeight() }
});
}
auto &pdbxEntityNonpoly = db["pdbx_entity_nonpoly"];
pdbxEntityNonpoly.emplace({
{ "entity_id", entityID },
{ "name", compound->name() },
{ "comp_id", newCompound }
});
auto &pdbxNonPolyScheme = db["pdbx_nonpoly_scheme"];
for (auto &nps : pdbxNonPolyScheme.find("asym_id"_key == asymID))
nps.assign("entity_id", entityID, true);
// create rest
auto& chemComp = db["chem_comp"];
if (not chemComp.exists(cif::Key("id") == newCompound))
{
chemComp.emplace({
{ "id", newCompound },
{ "name", compound->name() },
{ "formula", compound->formula() },
{ "formula_weight", compound->formulaWeight() },
{ "type", compound->type() }
});
}
// // First make sure the compound is already known or insert it. // update the struct_asym for the new entity
// // And if the residue is an entity, we must make sure it exists db["struct_asym"].update_value("id"_key == asymID, "entity_id", entityID);
// insertCompound(newCompound, res.isEntity()); }
else
insertCompound(newCompound, false);
auto& atomSites = db["atom_site"]; auto& atomSites = db["atom_site"];
auto atoms = res.atoms(); auto atoms = res.atoms();
...@@ -2278,17 +2335,7 @@ void Structure::changeResidue(const Residue& res, const std::string& newCompound ...@@ -2278,17 +2335,7 @@ void Structure::changeResidue(const Residue& res, const std::string& newCompound
} }
for (auto a: atoms) for (auto a: atoms)
{ atomSites.update_value(cif::Key("id") == a.id(), "label_comp_id", newCompound);
auto r = atomSites.find(cif::Key("id") == a.id());
assert(r.size() == 1);
if (r.size() != 1)
continue;
r.front().assign("label_comp_id", newCompound, false);
if (not entityID.empty())
r.front().assign("label_entity_id", entityID, false);
}
} }
} }
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