Mercurial > repos > bimib > cobraxy
changeset 401:6c7ddf68381a draft
Uploaded
author | francesco_lapi |
---|---|
date | Sun, 07 Sep 2025 20:29:23 +0000 |
parents | e94735cb40fa |
children | ccccb731c953 |
files | COBRAxy/ras_generator.py COBRAxy/ras_generator.xml |
diffstat | 2 files changed, 36 insertions(+), 8 deletions(-) [+] |
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.
--- a/COBRAxy/ras_generator.xml Sun Sep 07 20:07:44 2025 +0000 +++ b/COBRAxy/ras_generator.xml Sun Sep 07 20:29:23 2025 +0000 @@ -24,9 +24,11 @@ ]]> </command> <inputs> - <param name="model_upload" argument="--model_upload" type="data" format="csv, tsv, tabular" label="Custom model (optional)" help="If not provided, the selected model will be used." /> - <param name="input" argument="--input" type="data" format="tabular, csv, tsv" label="Gene Expression dataset:" /> - <param name="name" argument="--name" type="text" label="Dataset's name:" value="Dataset_RAS" help="Default: Dataset_RAS. Do not use white spaces or special symbols." /> + <param name="model_upload" argument="--model_upload" type="data" format="csv,tsv,tabular" + label="Model rules file:" help="Upload a CSV/TSV file containing reaction rules generated by the Model Initialization tool." /> + <param name="input" argument="--input" type="data" format="tabular,csv,tsv" label="Gene Expression dataset:" /> + <param name="name" argument="--name" type="text" label="Dataset's name:" value="Dataset_RAS" + help="Default: Dataset_RAS. Do not use white spaces or special symbols." /> <param name="none" argument="--none" type="boolean" checked="true" label="(A and NaN) solved as (A)?" /> </inputs>