Mercurial > repos > bimib > cobraxy
comparison COBRAxy/ras_generator.py @ 401:6c7ddf68381a draft
Uploaded
| author | francesco_lapi |
|---|---|
| date | Sun, 07 Sep 2025 20:29:23 +0000 |
| parents | e94735cb40fa |
| children | ccccb731c953 |
comparison
equal
deleted
inserted
replaced
| 400:e94735cb40fa | 401:6c7ddf68381a |
|---|---|
| 645 # filenamePath = None | 645 # filenamePath = None |
| 646 | 646 |
| 647 #if filenamePath.ext is utils.FileFormat.PICKLE: return utils.readPickle(datFilePath) | 647 #if filenamePath.ext is utils.FileFormat.PICKLE: return utils.readPickle(datFilePath) |
| 648 | 648 |
| 649 dict_rule = {} | 649 dict_rule = {} |
| 650 for line in utils.readCsv(datFilePath, delimiter = "\t"): | 650 |
| 651 if line[2] == "": | 651 try: |
| 652 dict_rule[line[0]] = ruleUtils.OpList([""]) | 652 # Proviamo prima con delimitatore tab |
| 653 else: | 653 for line in utils.readCsv(datFilePath, delimiter = "\t"): |
| 654 dict_rule[line[0]] = ruleUtils.parseRuleToNestedList(line[2]) | 654 if len(line) < 3: # Controlliamo che ci siano almeno 3 colonne |
| 655 | 655 utils.logWarning(f"Skipping malformed line: {line}", ARGS.out_log) |
| 656 continue | |
| 657 | |
| 658 if line[2] == "": | |
| 659 dict_rule[line[0]] = ruleUtils.OpList([""]) | |
| 660 else: | |
| 661 dict_rule[line[0]] = ruleUtils.parseRuleToNestedList(line[2]) | |
| 662 | |
| 663 except Exception as e: | |
| 664 # Se fallisce con tab, proviamo con virgola | |
| 665 try: | |
| 666 dict_rule = {} | |
| 667 for line in utils.readCsv(datFilePath, delimiter = ","): | |
| 668 if len(line) < 3: | |
| 669 utils.logWarning(f"Skipping malformed line: {line}", ARGS.out_log) | |
| 670 continue | |
| 671 | |
| 672 if line[2] == "": | |
| 673 dict_rule[line[0]] = ruleUtils.OpList([""]) | |
| 674 else: | |
| 675 dict_rule[line[0]] = ruleUtils.parseRuleToNestedList(line[2]) | |
| 676 except Exception as e2: | |
| 677 raise ValueError(f"Unable to parse rules file. Tried both tab and comma delimiters. Original errors: Tab: {e}, Comma: {e2}") | |
| 678 | |
| 679 if not dict_rule: | |
| 680 raise ValueError("No valid rules found in the uploaded file. Please check the file format.") | |
| 656 # csv rules need to be parsed, those in a pickle format are taken to be pre-parsed. | 681 # csv rules need to be parsed, those in a pickle format are taken to be pre-parsed. |
| 657 return dict_rule | 682 return dict_rule |
| 683 | |
| 658 | 684 |
| 659 def main(args:List[str] = None) -> None: | 685 def main(args:List[str] = None) -> None: |
| 660 """ | 686 """ |
| 661 Initializes everything and sets the program in motion based on the fronted input arguments. | 687 Initializes everything and sets the program in motion based on the fronted input arguments. |
| 662 | 688 |
