comparison COBRAxy/utils/reaction_parsing.py @ 427:4a385fdb9e58 draft

Uploaded
author francesco_lapi
date Wed, 10 Sep 2025 11:38:08 +0000
parents 0a3ca20848f3
children a6e45049c1b9
comparison
equal deleted inserted replaced
426:00a78da611ba 427:4a385fdb9e58
122 customReactionsPath : path to the reactions information file. 122 customReactionsPath : path to the reactions information file.
123 123
124 Returns: 124 Returns:
125 ReactionsDict : dictionary encoding custom reactions information. 125 ReactionsDict : dictionary encoding custom reactions information.
126 """ 126 """
127 reactionsData :Dict[str, str] = {row[0]: row[1] for row in utils.readCsv(utils.FilePath.fromStrPath(customReactionsPath), delimiter = "\t")} 127 try:
128 rows = utils.readCsv(utils.FilePath.fromStrPath(customReactionsPath), delimiter = "\t", skipHeader=False)
129 if len(rows) <= 1:
130 raise ValueError("The custom reactions file must contain at least one reaction.")
131
132 id_idx, idx_formula = utils.findIdxByName(rows[0], "Formula")
133
134 except Exception as e:
135
136 rows = utils.readCsv(utils.FilePath.fromStrPath(customReactionsPath), delimiter = "\t", skipHeader=False)
137 if len(rows) <= 1:
138 raise ValueError("The custom reactions file must contain at least one reaction.")
139
140 id_idx, idx_formula = utils.findIdxByName(rows[0], "Formula")
141
142 reactionsData = {row[id_idx] : row[idx_formula] for row in rows[1:]}
143
128 return create_reaction_dict(reactionsData) 144 return create_reaction_dict(reactionsData)
129 145