# HG changeset patch # User luca_milaz # Date 1722887441 0 # Node ID 7557495e090c8434a30e8700b1f21902f68b1443 # Parent 0312366eabfdcb03e2e388b215c50ba956de6e55 Uploaded diff -r 0312366eabfd -r 7557495e090c marea_2/ras_generator.py --- a/marea_2/ras_generator.py Mon Aug 05 19:37:33 2024 +0000 +++ b/marea_2/ras_generator.py Mon Aug 05 19:50:41 2024 +0000 @@ -626,6 +626,26 @@ if geneName in supportedGenesInEncoding: return supportedGenesInEncoding[geneName] raise ValueError(f"Gene \"{geneName}\" non trovato, verifica di star utilizzando il modello corretto!") +def load_custom_rules2() -> Dict[str, ruleUtils.OpList]: + """ + Opens custom rules file and extracts the rules. If the file is in .csv format an additional parsing step will be + performed, significantly impacting the runtime. + + Returns: + Dict[str, ruleUtils.OpList] : dict mapping reaction IDs to rules. + """ + datFilePath = utils.FilePath.fromStrPath(ARGS.rule_list) # actual file, stored in galaxy as a .dat + + try: filenamePath = utils.FilePath.fromStrPath(ARGS.rules_name) # file's name in input, to determine its original ext + except utils.PathErr as err: + raise utils.PathErr(filenamePath, f"Please make sure your file's name is a valid file path, {err.msg}") + + + if filenamePath.ext is utils.FileFormat.PICKLE: return utils.readPickle(datFilePath) + + # csv rules need to be parsed, those in a pickle format are taken to be pre-parsed. + return { line[0] : ruleUtils.parseRuleToNestedList(line[1]) for line in utils.readCsv(datFilePath) } + def load_custom_rules() -> Dict[str, ruleUtils.OpList]: """ Opens custom rules file and extracts the rules. If the file is in .csv format an additional parsing step will be @@ -639,11 +659,12 @@ try: filenamePath = utils.FilePath.fromStrPath(ARGS.rules_name) # file's name in input, to determine its original ext except utils.PathErr as err: raise utils.PathErr(filenamePath, f"Please make sure your file's name is a valid file path, {err.msg}") + - if filenamePath.ext is utils.FileFormat.PICKLE: return utils.readPickle(datFilePath) + if filenamePath.ext is utils.FileFormat.PICKLE: return utils.readPickle(ARGS.rule_list) # csv rules need to be parsed, those in a pickle format are taken to be pre-parsed. - return { line[0] : ruleUtils.parseRuleToNestedList(line[1]) for line in utils.readCsv(datFilePath) } + return { line[0] : ruleUtils.parseRuleToNestedList(line[1]) for line in utils.readCsv(ARGS.rule_list) } def main() -> None: """