From 4f1ba46383f81b11d4be915d9c074d6ccac4a975 Mon Sep 17 00:00:00 2001 From: Ben Webb Date: Fri, 6 Sep 2024 14:29:00 -0700 Subject: [PATCH] Squashed 'modules/core/dependency/python-ihm/' changes from 78f2788400..5c7c382a41 5c7c382a41 Prepare for 1.5 release 4df39c4d83 Don't duplicate struct_ref.id, closes ihmwg/python-ihm#149 git-subtree-dir: modules/core/dependency/python-ihm git-subtree-split: 5c7c382a415580b1999d743c3fd119668fcd79ee --- .../core/dependency/python-ihm/ChangeLog.rst | 9 ++++ .../core/dependency/python-ihm/MANIFEST.in | 2 +- .../dependency/python-ihm/ihm/__init__.py | 2 +- .../core/dependency/python-ihm/ihm/dumper.py | 51 +++++++++---------- .../python-ihm/ihm/util/__init__.py | 7 ++- modules/core/dependency/python-ihm/setup.py | 2 +- .../dependency/python-ihm/test/test_dumper.py | 11 ++++ .../python-ihm/util/debian/changelog | 6 +++ .../python-ihm/util/python-ihm.spec | 5 +- 9 files changed, 63 insertions(+), 32 deletions(-) diff --git a/modules/core/dependency/python-ihm/ChangeLog.rst b/modules/core/dependency/python-ihm/ChangeLog.rst index 72025e96b1..562c2e37da 100644 --- a/modules/core/dependency/python-ihm/ChangeLog.rst +++ b/modules/core/dependency/python-ihm/ChangeLog.rst @@ -1,3 +1,12 @@ +1.5 - 2024-09-06 +================ + - Trying to create a :class:`ihm.Residue`, :class:`ihm.EntityRange`, or + :class:`ihm.AsymUnitRange` that references out-of-range residues (i.e. + ``seq_id`` less than 1 or beyond the length of the :class:`ihm.Entity` + sequence) will now raise an error. + - Bugfix: :class:`ihm.reference.Reference` objects are no longer given + erroneous duplicate IDs on output (#149). + 1.4 - 2024-08-30 ================ - :class:`ihm.metadata.CIFParser` now extracts metadata from mmCIF starting diff --git a/modules/core/dependency/python-ihm/MANIFEST.in b/modules/core/dependency/python-ihm/MANIFEST.in index 8b529ee103..804716ec64 100644 --- a/modules/core/dependency/python-ihm/MANIFEST.in +++ b/modules/core/dependency/python-ihm/MANIFEST.in @@ -4,4 +4,4 @@ include examples/* include util/make-mmcif.py include src/ihm_format.h include src/ihm_format.i -include src/ihm_format_wrap_1.4.c +include src/ihm_format_wrap_1.5.c diff --git a/modules/core/dependency/python-ihm/ihm/__init__.py b/modules/core/dependency/python-ihm/ihm/__init__.py index 781c5fde90..9c85da7e4f 100644 --- a/modules/core/dependency/python-ihm/ihm/__init__.py +++ b/modules/core/dependency/python-ihm/ihm/__init__.py @@ -20,7 +20,7 @@ import json from . import util -__version__ = '1.4' +__version__ = '1.5' class __UnknownValue(object): diff --git a/modules/core/dependency/python-ihm/ihm/dumper.py b/modules/core/dependency/python-ihm/ihm/dumper.py index f582b4232a..3d3cbd5f0a 100644 --- a/modules/core/dependency/python-ihm/ihm/dumper.py +++ b/modules/core/dependency/python-ihm/ihm/dumper.py @@ -422,19 +422,21 @@ def _prettyprint_seq(seq, width): class _StructRefDumper(Dumper): def finalize(self, system): - self._refs_by_id = {} + # List of (entity, ref) by ID + self._refs_by_id = [] + seen_refs = {} align_id = itertools.count(1) for e in system.entities: for r in e.references: util._remove_id(r) for e in system.entities: - seen_refs = {} # Two refs are not considered duplicated if they relate to - # different entities, so keep list per entity - self._refs_by_id[id(e)] = by_id = [] + # different entities, so add entity to reference signature for r in e.references: - util._assign_id(r, seen_refs, by_id, seen_obj=r._signature()) + sig = (id(e), r._signature()) + util._assign_id(r, seen_refs, self._refs_by_id, seen_obj=sig, + by_id_obj=(e, r)) for a in r._get_alignments(): a._id = next(align_id) @@ -520,23 +522,21 @@ def dump(self, system, writer): ["id", "entity_id", "db_name", "db_code", "pdbx_db_accession", "pdbx_align_begin", "pdbx_seq_one_letter_code", "details"]) as lp: - for e in system.entities: - for r in self._refs_by_id[id(e)]: - self._check_reference_sequence(e, r) - db_begin = min(a.db_begin for a in r._get_alignments()) - lp.write(id=r._id, entity_id=e._id, db_name=r.db_name, - db_code=r.db_code, pdbx_db_accession=r.accession, - pdbx_align_begin=db_begin, details=r.details, - pdbx_seq_one_letter_code=self._get_sequence(r)) + for e, r in self._refs_by_id: + self._check_reference_sequence(e, r) + db_begin = min(a.db_begin for a in r._get_alignments()) + lp.write(id=r._id, entity_id=e._id, db_name=r.db_name, + db_code=r.db_code, pdbx_db_accession=r.accession, + pdbx_align_begin=db_begin, details=r.details, + pdbx_seq_one_letter_code=self._get_sequence(r)) self.dump_seq(system, writer) self.dump_seq_dif(system, writer) def dump_seq(self, system, writer): def _all_alignments(): - for e in system.entities: - for r in self._refs_by_id[id(e)]: - for a in r._get_alignments(): - yield e, r, a + for e, r in self._refs_by_id: + for a in r._get_alignments(): + yield e, r, a with writer.loop( "_struct_ref_seq", ["align_id", "ref_id", "seq_align_beg", "seq_align_end", @@ -557,15 +557,14 @@ def dump_seq_dif(self, system, writer): "_struct_ref_seq_dif", ["pdbx_ordinal", "align_id", "seq_num", "db_mon_id", "mon_id", "details"]) as lp: - for e in system.entities: - for r in self._refs_by_id[id(e)]: - for a in r._get_alignments(): - for sd in a.seq_dif: - lp.write(pdbx_ordinal=next(ordinal), - align_id=a._id, seq_num=sd.seq_id, - db_mon_id=sd.db_monomer.id - if sd.db_monomer else ihm.unknown, - mon_id=sd.monomer.id, details=sd.details) + for e, r in self._refs_by_id: + for a in r._get_alignments(): + for sd in a.seq_dif: + lp.write(pdbx_ordinal=next(ordinal), + align_id=a._id, seq_num=sd.seq_id, + db_mon_id=sd.db_monomer.id + if sd.db_monomer else ihm.unknown, + mon_id=sd.monomer.id, details=sd.details) class _EntityPolyDumper(Dumper): diff --git a/modules/core/dependency/python-ihm/ihm/util/__init__.py b/modules/core/dependency/python-ihm/ihm/util/__init__.py index 5246d4497c..2ec8c65b71 100644 --- a/modules/core/dependency/python-ihm/ihm/util/__init__.py +++ b/modules/core/dependency/python-ihm/ihm/util/__init__.py @@ -27,13 +27,16 @@ def _remove_id(obj, attr='_id'): delattr(obj, attr) -def _assign_id(obj, seen_objs, obj_by_id, attr='_id', seen_obj=None): +def _assign_id(obj, seen_objs, obj_by_id, attr='_id', seen_obj=None, + by_id_obj=None): """Assign a unique ID to obj, and track all ids in obj_by_id.""" if seen_obj is None: seen_obj = obj + if by_id_obj is None: + by_id_obj = obj if seen_obj not in seen_objs: if not hasattr(obj, attr): - obj_by_id.append(obj) + obj_by_id.append(by_id_obj) setattr(obj, attr, len(obj_by_id)) seen_objs[seen_obj] = getattr(obj, attr) else: diff --git a/modules/core/dependency/python-ihm/setup.py b/modules/core/dependency/python-ihm/setup.py index a1af3383b6..264f1d180a 100755 --- a/modules/core/dependency/python-ihm/setup.py +++ b/modules/core/dependency/python-ihm/setup.py @@ -7,7 +7,7 @@ import sys import os -VERSION = "1.4" +VERSION = "1.5" copy_args = sys.argv[1:] diff --git a/modules/core/dependency/python-ihm/test/test_dumper.py b/modules/core/dependency/python-ihm/test/test_dumper.py index 4051a7310d..4c077defd3 100644 --- a/modules/core/dependency/python-ihm/test/test_dumper.py +++ b/modules/core/dependency/python-ihm/test/test_dumper.py @@ -606,6 +606,15 @@ def test_struct_ref(self): system.entities.append(ihm.Entity('LSPT', references=[r1, r2, r3, r4, r5])) + + # Duplicate reference, but should be included as it pertains to a + # different Entity + r3a = ihm.reference.UniProtSequence( + db_code='testcode2', accession='testacc2', sequence=None) + r3a.alignments.append(ihm.reference.Alignment( + db_begin=4, db_end=5, entity_begin=2, entity_end=3)) + system.entities.append(ihm.Entity('LSPTW', references=[r3a])) + dumper = ihm.dumper._EntityDumper() dumper.finalize(system) # Assign entity IDs @@ -626,6 +635,7 @@ def test_struct_ref(self): 2 1 UNP testcode testacc 4 SPTYQT test2 3 1 UNP testcode2 testacc2 4 . . 4 1 UNP testcode3 testacc3 4 ? . +5 2 UNP testcode2 testacc2 4 . . # # loop_ @@ -640,6 +650,7 @@ def test_struct_ref(self): 3 2 4 4 9 9 4 3 2 3 4 5 5 4 2 3 4 5 +7 5 2 3 4 5 # # loop_ diff --git a/modules/core/dependency/python-ihm/util/debian/changelog b/modules/core/dependency/python-ihm/util/debian/changelog index 3e706680a7..254168b482 100644 --- a/modules/core/dependency/python-ihm/util/debian/changelog +++ b/modules/core/dependency/python-ihm/util/debian/changelog @@ -1,3 +1,9 @@ +python-ihm (1.5-1~@CODENAME@) @CODENAME@; urgency=low + + * python-ihm 1.5 release + + -- Ben Webb Fri, 06 Sep 2024 14:15:12 -0700 + python-ihm (1.4-1~@CODENAME@) @CODENAME@; urgency=low * python-ihm 1.4 release diff --git a/modules/core/dependency/python-ihm/util/python-ihm.spec b/modules/core/dependency/python-ihm/util/python-ihm.spec index 6c815764b2..355d6e1794 100644 --- a/modules/core/dependency/python-ihm/util/python-ihm.spec +++ b/modules/core/dependency/python-ihm/util/python-ihm.spec @@ -1,7 +1,7 @@ Name: python3-ihm License: MIT Group: Applications/Engineering -Version: 1.4 +Version: 1.5 Release: 1%{?dist} Summary: Package for handling IHM mmCIF and BinaryCIF files Packager: Ben Webb @@ -36,6 +36,9 @@ sed -i -e "s/install_requires=\['msgpack'\]/#/" setup.py %defattr(-,root,root) %changelog +* Fri Sep 06 2024 Ben Webb 1.5-1 +- Update to latest upstream. + * Fri Aug 30 2024 Ben Webb 1.4-1 - Update to latest upstream.