comparison COBRAxy/ras_generator_beta.py @ 427:4a385fdb9e58 draft

Uploaded
author francesco_lapi
date Wed, 10 Sep 2025 11:38:08 +0000
parents 187cee1a00e2
children a6e45049c1b9
comparison
equal deleted inserted replaced
426:00a78da611ba 427:4a385fdb9e58
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 650
651 try: 651 try:
652 rows = utils.readCsv(datFilePath, delimiter = "\t", skipHeader=False)
653 if len(rows) <= 1:
654 raise ValueError("Model tabular with 1 column is not supported.")
655
656 if not rows:
657 raise ValueError("Model tabular is file is empty.")
658
659 id_idx, idx_gpr = utils.findIdxByName(rows[0], "GPR")
660
652 # Proviamo prima con delimitatore tab 661 # Proviamo prima con delimitatore tab
653 for line in utils.readCsv(datFilePath, delimiter = "\t"): 662 for line in rows[1:]:
654 if len(line) < 3: # Controlliamo che ci siano almeno 3 colonne 663 if len(line) <= idx_gpr:
655 utils.logWarning(f"Skipping malformed line: {line}", ARGS.out_log) 664 utils.logWarning(f"Skipping malformed line: {line}", ARGS.out_log)
656 continue 665 continue
657 666
658 if line[2] == "": 667 if line[idx_gpr] == "":
659 dict_rule[line[0]] = ruleUtils.OpList([""]) 668 dict_rule[line[id_idx]] = ruleUtils.OpList([""])
660 else: 669 else:
661 dict_rule[line[0]] = ruleUtils.parseRuleToNestedList(line[2]) 670 dict_rule[line[id_idx]] = ruleUtils.parseRuleToNestedList(line[idx_gpr])
662 671
663 except Exception as e: 672 except Exception as e:
664 # Se fallisce con tab, proviamo con virgola 673 # Se fallisce con tab, proviamo con virgola
665 try: 674 try:
666 dict_rule = {} 675 rows = utils.readCsv(datFilePath, delimiter = ",", skipHeader=False)
667 for line in utils.readCsv(datFilePath, delimiter = ","): 676
668 if len(line) < 3: 677 if len(rows) <= 1:
678 raise ValueError("Model tabular with 1 column is not supported.")
679
680 if not rows:
681 raise ValueError("Model tabular is file is empty.")
682
683 id_idx, idx_gpr = utils.findIdxByName(rows[0], "GPR")
684
685 # Proviamo prima con delimitatore tab
686 for line in rows[1:]:
687 if len(line) <= idx_gpr:
669 utils.logWarning(f"Skipping malformed line: {line}", ARGS.out_log) 688 utils.logWarning(f"Skipping malformed line: {line}", ARGS.out_log)
670 continue 689 continue
671 690
672 if line[2] == "": 691 if line[idx_gpr] == "":
673 dict_rule[line[0]] = ruleUtils.OpList([""]) 692 dict_rule[line[id_idx]] = ruleUtils.OpList([""])
674 else: 693 else:
675 dict_rule[line[0]] = ruleUtils.parseRuleToNestedList(line[2]) 694 dict_rule[line[id_idx]] = ruleUtils.parseRuleToNestedList(line[idx_gpr])
695
676 except Exception as e2: 696 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}") 697 raise ValueError(f"Unable to parse rules file. Tried both tab and comma delimiters. Original errors: Tab: {e}, Comma: {e2}")
678 698
679 if not dict_rule: 699 if not dict_rule:
680 raise ValueError("No valid rules found in the uploaded file. Please check the file format.") 700 raise ValueError("No valid rules found in the uploaded file. Please check the file format.")