From d39bdc88deb61db3345f2af5ae661bad0687cc57 Mon Sep 17 00:00:00 2001 From: Stefan Bienert <stefan.bienert@unibas.ch> Date: Thu, 19 Jul 2012 14:31:46 +0200 Subject: [PATCH] Added translation from mmCIF chain name to traditional PDB chain name. --- modules/io/doc/mmcif.rst | 22 +++++++++++++++++++++- modules/io/pymod/export_mmcif_io.cc | 2 ++ modules/io/src/mol/mmcif_info.cc | 18 ++++++++++++++++++ modules/io/src/mol/mmcif_info.hh | 13 +++++++++++++ modules/io/src/mol/mmcif_reader.cc | 2 ++ modules/io/tests/test_mmcif_info.cc | 7 ++++++- 6 files changed, 62 insertions(+), 2 deletions(-) diff --git a/modules/io/doc/mmcif.rst b/modules/io/doc/mmcif.rst index 855ed0ea2..758862eeb 100644 --- a/modules/io/doc/mmcif.rst +++ b/modules/io/doc/mmcif.rst @@ -160,6 +160,25 @@ of the annotation available. .. method:: GetStructDetails() + .. method:: AddMMCifPDBChainTr(cif_chain_id, pdb_chain_id) + + Set up a translation for a certain mmCIF chain name to the traditional PDB + chain name. + + :param cif_chain_id: atom_site.label_asym_id + :type cif_chain_id: :class:`str` + :param pdb_chain_id: atom_site.auth_asym_id + :type pdb_chain_id: :class:`str` + + .. method:: GetMMCifPDBChainTr(cif_chain_id) + + Get the translation of a certain mmCIF chain name to the traditional PDB + chain name. + + :param cif_chain_id: atom_site.label_asym_id + :type cif_chain_id: :class:`str` + :returns: atom_site.auth_asym_id as :class:`str` + .. class:: MMCifInfoCitation This stores citation information from an input file. @@ -793,4 +812,5 @@ of the annotation available. .. LocalWords: cas isbn pubmed asu seqres conop ConnectAll casp COMPND OBSLTE .. LocalWords: SPRSDE pdb func autofunction exptl attr pdbx oper conf spr dif -.. LocalWords: biounits biounit uniprot UNP seqs +.. LocalWords: biounits biounit uniprot UNP seqs AddMMCifPDBChainTr cif asym +.. LocalWords: auth GetMMCifPDBChainTr diff --git a/modules/io/pymod/export_mmcif_io.cc b/modules/io/pymod/export_mmcif_io.cc index 6654393be..f94c257e6 100644 --- a/modules/io/pymod/export_mmcif_io.cc +++ b/modules/io/pymod/export_mmcif_io.cc @@ -280,6 +280,8 @@ void export_mmcif_io() .def("GetStructDetails", &MMCifInfo::GetStructDetails) .def("SetObsoleteInfo", &MMCifInfo::SetObsoleteInfo) .def("GetObsoleteInfo", &MMCifInfo::GetObsoleteInfo) + .def("AddMMCifPDBChainTr", &MMCifInfo::AddMMCifPDBChainTr) + .def("GetMMCifPDBChainTr", &MMCifInfo::GetMMCifPDBChainTr) .add_property("citations", make_function(&MMCifInfo::GetCitations, return_value_policy<copy_const_reference>())) .add_property("biounits", make_function(&MMCifInfo::GetBioUnits, diff --git a/modules/io/src/mol/mmcif_info.cc b/modules/io/src/mol/mmcif_info.cc index c8565a2e8..140676fe6 100644 --- a/modules/io/src/mol/mmcif_info.cc +++ b/modules/io/src/mol/mmcif_info.cc @@ -22,6 +22,24 @@ namespace ost { namespace io { +void MMCifInfo::AddMMCifPDBChainTr(String cif, String pdb) +{ + std::map<String, String>::iterator tr_it = cif_2_pdb_chain_id_.find(cif); + if (tr_it != cif_2_pdb_chain_id_.end()) { + throw IOException("mmCIF chain id '"+ cif +"' is already mapped to '"+ + tr_it->second+"'."); + } + cif_2_pdb_chain_id_.insert(std::pair<String, String>(cif, pdb)); +} + +String MMCifInfo::GetMMCifPDBChainTr(String cif) const +{ + std::map<String, String>::const_iterator tr_it = + cif_2_pdb_chain_id_.find(cif); + if (tr_it == cif_2_pdb_chain_id_.end()) { return ""; } + return tr_it->second; +} + void MMCifInfo::AddAuthorsToCitation(StringRef id, std::vector<String> list) { // find citation diff --git a/modules/io/src/mol/mmcif_info.hh b/modules/io/src/mol/mmcif_info.hh index b240e5a1c..68aa79bef 100644 --- a/modules/io/src/mol/mmcif_info.hh +++ b/modules/io/src/mol/mmcif_info.hh @@ -771,6 +771,18 @@ public: /// \return experiment resolution Real GetResolution() const { return resolution_; } + /// \brief Add a new mmCIF/ PDB chain name tuple. + /// + /// \param cif chain name as used by the mmCIF file (label_asym_id) + /// \param pdb chain name as used in the PDB file (auth_asym_id) + void AddMMCifPDBChainTr(String cif, String pdb); + + /// \brief Get a PDB chain name for a CIF chain name + /// + /// \param cif chain name as used by the mmCIF file (label_asym_id) + /// \return chain name as used in the PDB file (auth_asym_id) + String GetMMCifPDBChainTr(String cif) const; + /// \brief Add a biounit /// /// \param bu biounit to be added @@ -848,6 +860,7 @@ private: std::vector<MMCifInfoBioUnit> biounits_; ///< list of biounits std::vector<MMCifInfoTransOpPtr> transops_; MMCifInfoStructRefs struct_refs_; + std::map<String, String> cif_2_pdb_chain_id_; }; diff --git a/modules/io/src/mol/mmcif_reader.cc b/modules/io/src/mol/mmcif_reader.cc index 2bcdee810..6f35d4a2f 100644 --- a/modules/io/src/mol/mmcif_reader.cc +++ b/modules/io/src/mol/mmcif_reader.cc @@ -500,6 +500,8 @@ void MMCifReader::ParseAndAddAtom(const std::vector<StringRef>& columns) // store entity id chain_id_pairs_.push_back(std::pair<mol::ChainHandle,String>(curr_chain_, columns[indices_[LABEL_ENTITY_ID]].str())); + // store mmCIF - PDB chain name mapping + info_.AddMMCifPDBChainTr(cif_chain_name, auth_chain_name); } assert(curr_chain_.IsValid()); } else if (chain_id_pairs_.back().second != // unit test diff --git a/modules/io/tests/test_mmcif_info.cc b/modules/io/tests/test_mmcif_info.cc index 3d2674797..d5a1ac1a4 100644 --- a/modules/io/tests/test_mmcif_info.cc +++ b/modules/io/tests/test_mmcif_info.cc @@ -202,7 +202,12 @@ BOOST_AUTO_TEST_CASE(mmcif_info) #else BOOST_CHECK_CLOSE(info.GetResolution(), 1.9f, 0.001f); #endif - + + info.AddMMCifPDBChainTr("A", "B"); + BOOST_CHECK_THROW(info.AddMMCifPDBChainTr("A", "B"), IOException); + BOOST_CHECK("B" == info.GetMMCifPDBChainTr("A")); + BOOST_CHECK("" == info.GetMMCifPDBChainTr("C")); + BOOST_MESSAGE(" done."); } -- GitLab