diff COBRAxy/ras_generator.py @ 401:6c7ddf68381a draft

Uploaded
author francesco_lapi
date Sun, 07 Sep 2025 20:29:23 +0000
parents e94735cb40fa
children ccccb731c953
line wrap: on
line diff
--- a/COBRAxy/ras_generator.py	Sun Sep 07 20:07:44 2025 +0000
+++ b/COBRAxy/ras_generator.py	Sun Sep 07 20:29:23 2025 +0000
@@ -647,15 +647,41 @@
     #if filenamePath.ext is utils.FileFormat.PICKLE: return utils.readPickle(datFilePath)
 
     dict_rule = {}
-    for line in utils.readCsv(datFilePath, delimiter = "\t"):
-        if line[2] == "":
-            dict_rule[line[0]] = ruleUtils.OpList([""])
-        else:
-            dict_rule[line[0]] = ruleUtils.parseRuleToNestedList(line[2])
 
+    try:
+        # Proviamo prima con delimitatore tab
+        for line in utils.readCsv(datFilePath, delimiter = "\t"):
+            if len(line) < 3:  # Controlliamo che ci siano almeno 3 colonne
+                utils.logWarning(f"Skipping malformed line: {line}", ARGS.out_log)
+                continue
+            
+            if line[2] == "":
+                dict_rule[line[0]] = ruleUtils.OpList([""])
+            else:
+                dict_rule[line[0]] = ruleUtils.parseRuleToNestedList(line[2])
+                
+    except Exception as e:
+        # Se fallisce con tab, proviamo con virgola
+        try:
+            dict_rule = {}
+            for line in utils.readCsv(datFilePath, delimiter = ","):
+                if len(line) < 3:
+                    utils.logWarning(f"Skipping malformed line: {line}", ARGS.out_log)
+                    continue
+                
+                if line[2] == "":
+                    dict_rule[line[0]] = ruleUtils.OpList([""])
+                else:
+                    dict_rule[line[0]] = ruleUtils.parseRuleToNestedList(line[2])
+        except Exception as e2:
+            raise ValueError(f"Unable to parse rules file. Tried both tab and comma delimiters. Original errors: Tab: {e}, Comma: {e2}")
+
+    if not dict_rule:
+            raise ValueError("No valid rules found in the uploaded file. Please check the file format.")
     # csv rules need to be parsed, those in a pickle format are taken to be pre-parsed.
     return dict_rule
 
+
 def main(args:List[str] = None) -> None:
     """
     Initializes everything and sets the program in motion based on the fronted input arguments.