Skip to content

Commit 941110f

Browse files
committed
chore(rr_cache.py): config file search + unify compounds file headers
1 parent c1fccf6 commit 941110f

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

rr_cache/rr_cache.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,24 @@ def __init__(
114114

115115
self.__cspace = cspace
116116

117-
# Cache config
118-
cache_cfg_file = os_path.join(
119-
CONFIG_PATH, f'config_{self.__cspace}.json'
120-
)
117+
# Config file
118+
# Search first in install_dir,
119+
# then in default config path
120+
cache_cfg_fln = os_path.join(install_dir, 'config', f'config_{self.__cspace}.json')
121+
if not os_path.exists(cache_cfg_fln):
122+
cache_cfg_fln = os_path.join(CONFIG_PATH, f'config_{self.__cspace}.json')
123+
121124
try:
122-
with open(cache_cfg_file, 'r') as f:
125+
with open(cache_cfg_fln, 'r') as f:
123126
cache_cfg = json_load(f)
124127
rrCache.__cache_sources = cache_cfg['sources']
125128
rrCache.__cache = cache_cfg['cache']
126129
except FileNotFoundError:
127-
logger.error(f'Cache config file {cache_cfg_file} not found, please check the --chemical-space argument')
130+
logger.error(f'Cache config file {cache_cfg_fln} not found, please check the --chemical-space argument')
128131
logger.error('Exiting...')
129132
exit(1)
130133

134+
131135
# Cache elements list
132136
rrCache.__attributes_list = list(rrCache.__cache.keys())
133137

@@ -1034,6 +1038,10 @@ def _m_mnxm_strc(
10341038

10351039
# Parse the compounds.tsv file from RetroRules
10361040
for row in csv_DictReader(gzip_open(rr_compounds_path, 'rt', encoding='utf-8-sig'), delimiter='\t'):
1041+
row = {k.lower(): v for k, v in row.items()} # normalize keys to lowercase
1042+
if 'cid' not in row:
1043+
# convert into 'id'
1044+
row['cid'] = row.pop('id')
10371045
tmp = {
10381046
'formula': None,
10391047
'inchi': row['inchi'],

0 commit comments

Comments
 (0)