Mercurial > repos > bimib > cobraxy
diff 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 |
line wrap: on
line diff
--- a/COBRAxy/utils/reaction_parsing.py Wed Sep 10 09:25:32 2025 +0000 +++ b/COBRAxy/utils/reaction_parsing.py Wed Sep 10 11:38:08 2025 +0000 @@ -124,6 +124,22 @@ Returns: ReactionsDict : dictionary encoding custom reactions information. """ - reactionsData :Dict[str, str] = {row[0]: row[1] for row in utils.readCsv(utils.FilePath.fromStrPath(customReactionsPath), delimiter = "\t")} + try: + rows = utils.readCsv(utils.FilePath.fromStrPath(customReactionsPath), delimiter = "\t", skipHeader=False) + if len(rows) <= 1: + raise ValueError("The custom reactions file must contain at least one reaction.") + + id_idx, idx_formula = utils.findIdxByName(rows[0], "Formula") + + except Exception as e: + + rows = utils.readCsv(utils.FilePath.fromStrPath(customReactionsPath), delimiter = "\t", skipHeader=False) + if len(rows) <= 1: + raise ValueError("The custom reactions file must contain at least one reaction.") + + id_idx, idx_formula = utils.findIdxByName(rows[0], "Formula") + + reactionsData = {row[id_idx] : row[idx_formula] for row in rows[1:]} + return create_reaction_dict(reactionsData)