Mercurial > repos > bimib > cobraxy
comparison COBRAxy/ras_generator.py @ 381:0a3ca20848f3 draft
Uploaded
| author | francesco_lapi |
|---|---|
| date | Fri, 05 Sep 2025 09:18:26 +0000 |
| parents | 38c9a958ea78 |
| children | 09064ce8f095 |
comparison
equal
deleted
inserted
replaced
| 380:03a7ba63813f | 381:0a3ca20848f3 |
|---|---|
| 521 dict: A dictionary where each key corresponds to a cell line name and each value is a dictionary | 521 dict: A dictionary where each key corresponds to a cell line name and each value is a dictionary |
| 522 where each key corresponds to a reaction ID and each value is its computed RAS score. | 522 where each key corresponds to a reaction ID and each value is its computed RAS score. |
| 523 """ | 523 """ |
| 524 ras_values_by_cell_line = {} | 524 ras_values_by_cell_line = {} |
| 525 dataset.set_index(dataset.columns[0], inplace=True) | 525 dataset.set_index(dataset.columns[0], inplace=True) |
| 526 # Considera tutte le colonne tranne la prima in cui ci sono gli hugo quindi va scartata | 526 |
| 527 for cell_line_name in dataset.columns[1:]: | 527 for cell_line_name in dataset.columns: #[1:]: |
| 528 cell_line = dataset[cell_line_name].to_dict() | 528 cell_line = dataset[cell_line_name].to_dict() |
| 529 ras_values_by_cell_line[cell_line_name]= get_ras_values(rules, cell_line) | 529 ras_values_by_cell_line[cell_line_name]= get_ras_values(rules, cell_line) |
| 530 return ras_values_by_cell_line | 530 return ras_values_by_cell_line |
| 531 | 531 |
| 532 def get_ras_values(value_rules: Dict[str, ruleUtils.OpList], dataset: Dict[str, Expr]) -> Dict[str, Ras]: | 532 def get_ras_values(value_rules: Dict[str, ruleUtils.OpList], dataset: Dict[str, Expr]) -> Dict[str, Ras]: |
| 648 except utils.PathErr as err: | 648 except utils.PathErr as err: |
| 649 raise utils.PathErr(filenamePath, f"Please make sure your file's name is a valid file path, {err.msg}") | 649 raise utils.PathErr(filenamePath, f"Please make sure your file's name is a valid file path, {err.msg}") |
| 650 | 650 |
| 651 if filenamePath.ext is utils.FileFormat.PICKLE: return utils.readPickle(datFilePath) | 651 if filenamePath.ext is utils.FileFormat.PICKLE: return utils.readPickle(datFilePath) |
| 652 | 652 |
| 653 dict_rule = {} | |
| 654 for line in utils.readCsv(datFilePath, delimiter = "\t"): | |
| 655 if line[2] == "": | |
| 656 dict_rule[line[0]] = ruleUtils.OpList([""]) | |
| 657 else: | |
| 658 dict_rule[line[0]] = ruleUtils.parseRuleToNestedList(line[2]) | |
| 659 | |
| 653 # csv rules need to be parsed, those in a pickle format are taken to be pre-parsed. | 660 # csv rules need to be parsed, those in a pickle format are taken to be pre-parsed. |
| 654 return { line[0] : ruleUtils.parseRuleToNestedList(line[1]) for line in utils.readCsv(datFilePath) } | 661 return dict_rule |
| 655 | 662 |
| 656 def main(args:List[str] = None) -> None: | 663 def main(args:List[str] = None) -> None: |
| 657 """ | 664 """ |
| 658 Initializes everything and sets the program in motion based on the fronted input arguments. | 665 Initializes everything and sets the program in motion based on the fronted input arguments. |
| 659 | 666 |
| 690 type_gene = gene_type(dataset.iloc[0, 0], name) | 697 type_gene = gene_type(dataset.iloc[0, 0], name) |
| 691 | 698 |
| 692 rules = model.getRules(ARGS.tool_dir) | 699 rules = model.getRules(ARGS.tool_dir) |
| 693 genes = data_gene(dataset, type_gene, name, None) | 700 genes = data_gene(dataset, type_gene, name, None) |
| 694 ids, rules = load_id_rules(rules.get(type_gene)) | 701 ids, rules = load_id_rules(rules.get(type_gene)) |
| 695 | 702 |
| 696 resolve_rules, err = resolve(genes, rules, ids, ARGS.none, name) | 703 resolve_rules, err = resolve(genes, rules, ids, ARGS.none, name) |
| 697 create_ras(resolve_rules, name, rules, ids, ARGS.ras_output) | 704 create_ras(resolve_rules, name, rules, ids, ARGS.ras_output) |
| 698 | 705 |
| 699 if err: utils.logWarning( | 706 if err: utils.logWarning( |
| 700 f"Warning: gene(s) {err} not found in class \"{name}\", " + | 707 f"Warning: gene(s) {err} not found in class \"{name}\", " + |
