Skip to content

Commit

Permalink
Use UniProt accession if available
Browse files Browse the repository at this point in the history
If a given chain provides the UniProt accession,
fill in the corresponding IHM information by
looking it up at the UniProt website.
  • Loading branch information
benmwebb committed Sep 19, 2023
1 parent 4139d4c commit 0febb24
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions modules/mmcif/pyext/src/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import ihm.protocol
import ihm.model
import ihm.citations
import ihm.reference
import operator
import inspect

Expand Down Expand Up @@ -126,6 +127,10 @@ def add(self, chain, seq_from_res=None):
self.system.entities.append(entity)
self._entities.append(entity)
self._sequence_dict[sequence] = entity
uniprot = chain.get_uniprot_accession()
if uniprot:
up = ihm.reference.UniProtSequence.from_accession(uniprot)
entity.references.append(up)
self[chain] = self._sequence_dict[sequence]
return self[chain], offset

Expand Down
33 changes: 33 additions & 0 deletions modules/mmcif/test/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@
import IMP.mmcif.data
import ihm
import os
import contextlib


@contextlib.contextmanager
def mocked_ihm_from_accession():
"""Prevent ihm.reference.UniProtSequence.from_accession from
accessing the network"""
def mock_from_acc(accession):
return ihm.reference.UniProtSequence(db_code='CSN1_HUMAN',
accession='Q13098',
sequence='someseq')

orig_meth = ihm.reference.UniProtSequence.from_accession
try:
ihm.reference.UniProtSequence.from_accession = mock_from_acc
yield
finally:
ihm.reference.UniProtSequence.from_accession = orig_meth


def add_attrs(r):
IMP.core.XYZR.setup_particle(
Expand Down Expand Up @@ -98,6 +117,20 @@ def test_entity_mapper_add(self):
seq_from_res=(1, (alpha['C'], None,
alpha['G'], None)))

def test_entity_uniprot(self):
"""Test EntityMapper.add() with UniProt accession"""
m = IMP.Model()
system = ihm.System()
e = IMP.mmcif.data._EntityMapper(system)
chain1 = make_chain(m, "A", "A", sequence='ACC')
chain1.set_uniprot_accession('Q13098')
with mocked_ihm_from_accession():
e.add(chain1)
entity, = system.entities
ref, = entity.references
self.assertEqual(ref.db_code, 'CSN1_HUMAN')
self.assertEqual(ref.accession, 'Q13098')

def test_entity_naming(self):
"""Test naming of Entities"""
m = IMP.Model()
Expand Down

0 comments on commit 0febb24

Please sign in to comment.