Skip to content

Commit

Permalink
Squashed 'modules/core/dependency/python-ihm/' changes from 78f278840…
Browse files Browse the repository at this point in the history
…0..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
  • Loading branch information
benmwebb committed Sep 6, 2024
1 parent ace4588 commit 4f1ba46
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 32 deletions.
9 changes: 9 additions & 0 deletions modules/core/dependency/python-ihm/ChangeLog.rst
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/core/dependency/python-ihm/MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion modules/core/dependency/python-ihm/ihm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import json
from . import util

__version__ = '1.4'
__version__ = '1.5'


class __UnknownValue(object):
Expand Down
51 changes: 25 additions & 26 deletions modules/core/dependency/python-ihm/ihm/dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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",
Expand All @@ -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):
Expand Down
7 changes: 5 additions & 2 deletions modules/core/dependency/python-ihm/ihm/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion modules/core/dependency/python-ihm/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import sys
import os

VERSION = "1.4"
VERSION = "1.5"

copy_args = sys.argv[1:]

Expand Down
11 changes: 11 additions & 0 deletions modules/core/dependency/python-ihm/test/test_dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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_
Expand All @@ -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_
Expand Down
6 changes: 6 additions & 0 deletions modules/core/dependency/python-ihm/util/debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
python-ihm (1.5-1~@CODENAME@) @CODENAME@; urgency=low

* python-ihm 1.5 release

-- Ben Webb <[email protected]> Fri, 06 Sep 2024 14:15:12 -0700

python-ihm (1.4-1~@CODENAME@) @CODENAME@; urgency=low

* python-ihm 1.4 release
Expand Down
5 changes: 4 additions & 1 deletion modules/core/dependency/python-ihm/util/python-ihm.spec
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
Expand Down Expand Up @@ -36,6 +36,9 @@ sed -i -e "s/install_requires=\['msgpack'\]/#/" setup.py
%defattr(-,root,root)

%changelog
* Fri Sep 06 2024 Ben Webb <[email protected]> 1.5-1
- Update to latest upstream.

* Fri Aug 30 2024 Ben Webb <[email protected]> 1.4-1
- Update to latest upstream.

Expand Down

0 comments on commit 4f1ba46

Please sign in to comment.