Skip to content

Commit 1dcbfd5

Browse files
committed
Fix interproscan loader failing to load IPR by name
1 parent 7685251 commit 1dcbfd5

3 files changed

Lines changed: 31 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ $ chakin feature load_fasta \
8989
9090
- 2.3.2
9191
- Fix interproscan loader only loading the first result of XML v5
92+
- Fix interproscan loader failing to load IPR by name
9293
9394
- 2.3.1
9495
- Fix data loading in Tripal database

chado/client.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def _reset_cache(self):
4646
self._featured_dirty_rels = None
4747
self._analysisfeature_cache = None
4848
self._analysisprop_cache = None
49+
self._interpro_cache = None
4950

5051
self.cache_existing = True
5152

@@ -336,3 +337,18 @@ def _add_feat_cvterm_with_id(self, feat, cvterm_id, pub_id=None):
336337
if feat not in self._featcvterm_cache:
337338
self._featcvterm_cache[feat] = []
338339
self._featcvterm_cache[feat].append(cvterm_id)
340+
341+
def _init_interpro_cache(self, force=False):
342+
343+
if self._interpro_cache is not None and force:
344+
self._interpro_cache = None
345+
346+
if self._interpro_cache is None:
347+
self._interpro_cache = {}
348+
if self.cache_existing:
349+
res = self.session.query(self.model.dbxref.accession, self.model.cvterm.cvterm_id) \
350+
.join(self.model.db, self.model.db.db_id == self.model.dbxref.db_id) \
351+
.filter(self.model.db.name == "INTERPRO") \
352+
.join(self.model.cvterm, self.model.dbxref.dbxref_id == self.model.cvterm.dbxref_id)
353+
354+
self._interpro_cache = {x.accession: x.cvterm_id for x in res}

chado/load/__init__.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ def interpro(self, analysis_id, organism_id, input, parse_go=False, re_name=None
275275
# Cache analysisfeature content for given analysis_id
276276
self._init_analysisfeature_cache(analysis_id)
277277
self._init_featcvterm_cache()
278+
self._init_interpro_cache()
278279

279280
# Cache all existing cvterms from GO cv
280281
db = 'GO'
@@ -501,13 +502,19 @@ def _load_ipr_terms(self, ipr_terms, feature_id, analysis_id, skip_missing):
501502
# load the IPR terms that way, we need to just add them
502503
# as we encounter them. If the term already exists
503504
# we do not want to update it.
504-
cvterm_id = self.ci.create_cvterm(ipr_term['ipr_name'], 'INTERPRO', 'INTERPRO', term_definition=ipr_term['ipr_desc'], accession=ipr_id)
505-
if not cvterm_id:
506-
if skip_missing:
507-
warn('Could not find cvterm %s %s, skipping it', ipr_id, ipr_term['ipr_name'])
508-
continue
509-
else:
510-
raise Exception('Could not find cvterm %s %s' % ipr_id, ipr_term['ipr_name'])
505+
506+
# Check using IPRnumber (in case ipr_name changed at some point in time)
507+
if ipr_id in self._interpro_cache:
508+
cvterm_id = self._interpro_cache[ipr_id]
509+
else:
510+
cvterm_id = self.ci.create_cvterm(ipr_term['ipr_name'], 'INTERPRO', 'INTERPRO', term_definition=ipr_term['ipr_desc'], accession=ipr_id)
511+
if not cvterm_id:
512+
if skip_missing:
513+
warn('Could not find cvterm %s %s, skipping it', ipr_id, ipr_term['ipr_name'])
514+
continue
515+
else:
516+
raise Exception('Could not find cvterm %s %s' % ipr_id, ipr_term['ipr_name'])
517+
self._interpro_cache[ipr_id] = cvterm_id
511518

512519
# Insert IPR terms into the feature_cvterm table
513520
# the default pub_id of 1 (NULL) is used. if the cvterm already exists then just skip adding it

0 commit comments

Comments
 (0)