Mercurial > repos > bimib > cobraxy
comparison COBRAxy/ras_generator.py @ 398:09064ce8f095 draft
Uploaded
author | francesco_lapi |
---|---|
date | Sun, 07 Sep 2025 16:01:16 +0000 |
parents | 0a3ca20848f3 |
children | e94735cb40fa |
comparison
equal
deleted
inserted
replaced
397:de4a373e338b | 398:09064ce8f095 |
---|---|
25 """ | 25 """ |
26 parser = argparse.ArgumentParser( | 26 parser = argparse.ArgumentParser( |
27 usage = '%(prog)s [options]', | 27 usage = '%(prog)s [options]', |
28 description = "process some value's genes to create a comparison's map.") | 28 description = "process some value's genes to create a comparison's map.") |
29 | 29 |
30 parser.add_argument( | 30 parser.add_argument("-rl", "--model_upload", type = str, |
31 '-rs', '--rules_selector', | |
32 type = utils.Model, default = utils.Model.ENGRO2, choices = list(utils.Model), | |
33 help = 'chose which type of dataset you want use') | |
34 | |
35 parser.add_argument("-rl", "--rule_list", type = str, | |
36 help = "path to input file with custom rules, if provided") | 31 help = "path to input file with custom rules, if provided") |
37 | 32 |
38 parser.add_argument("-rn", "--rules_name", type = str, help = "custom rules name") | 33 parser.add_argument("-rn", "--model_upload_name", type = str, help = "custom rules name") |
39 # ^ I need this because galaxy converts my files into .dat but I need to know what extension they were in | 34 # ^ I need this because galaxy converts my files into .dat but I need to know what extension they were in |
40 | 35 |
41 parser.add_argument( | 36 parser.add_argument( |
42 '-n', '--none', | 37 '-n', '--none', |
43 type = utils.Bool("none"), default = True, | 38 type = utils.Bool("none"), default = True, |
640 performed, significantly impacting the runtime. | 635 performed, significantly impacting the runtime. |
641 | 636 |
642 Returns: | 637 Returns: |
643 Dict[str, ruleUtils.OpList] : dict mapping reaction IDs to rules. | 638 Dict[str, ruleUtils.OpList] : dict mapping reaction IDs to rules. |
644 """ | 639 """ |
645 datFilePath = utils.FilePath.fromStrPath(ARGS.rule_list) # actual file, stored in galaxy as a .dat | 640 datFilePath = utils.FilePath.fromStrPath(ARGS.model_upload) # actual file, stored in galaxy as a .dat |
646 | 641 |
647 try: filenamePath = utils.FilePath.fromStrPath(ARGS.rules_name) # file's name in input, to determine its original ext | 642 try: filenamePath = utils.FilePath.fromStrPath(ARGS.model_upload_name) # file's name in input, to determine its original ext |
648 except utils.PathErr as err: | 643 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}") | 644 raise utils.PathErr(filenamePath, f"Please make sure your file's name is a valid file path, {err.msg}") |
650 | 645 |
651 if filenamePath.ext is utils.FileFormat.PICKLE: return utils.readPickle(datFilePath) | 646 if filenamePath.ext is utils.FileFormat.PICKLE: return utils.readPickle(datFilePath) |
652 | 647 |
676 dataset.iloc[:, 0] = (dataset.iloc[:, 0]).astype(str) | 671 dataset.iloc[:, 0] = (dataset.iloc[:, 0]).astype(str) |
677 | 672 |
678 # remove versioning from gene names | 673 # remove versioning from gene names |
679 dataset.iloc[:, 0] = dataset.iloc[:, 0].str.split('.').str[0] | 674 dataset.iloc[:, 0] = dataset.iloc[:, 0].str.split('.').str[0] |
680 | 675 |
676 rules = load_custom_rules() | |
677 reactions = list(rules.keys()) | |
678 | |
679 save_as_tsv(ras_for_cell_lines(dataset, rules), reactions) | |
680 if ERRORS: utils.logWarning( | |
681 f"The following genes are mentioned in the rules but don't appear in the dataset: {ERRORS}", | |
682 ARGS.out_log) | |
683 | |
684 | |
685 ############ | |
686 | |
681 # handle custom models | 687 # handle custom models |
682 model :utils.Model = ARGS.rules_selector | 688 #model :utils.Model = ARGS.rules_selector |
683 | 689 |
684 if model is utils.Model.Custom: | 690 #if model is utils.Model.Custom: |
685 rules = load_custom_rules() | 691 # rules = load_custom_rules() |
686 reactions = list(rules.keys()) | 692 # reactions = list(rules.keys()) |
687 | 693 |
688 save_as_tsv(ras_for_cell_lines(dataset, rules), reactions) | 694 # save_as_tsv(ras_for_cell_lines(dataset, rules), reactions) |
689 if ERRORS: utils.logWarning( | 695 # if ERRORS: utils.logWarning( |
690 f"The following genes are mentioned in the rules but don't appear in the dataset: {ERRORS}", | 696 # f"The following genes are mentioned in the rules but don't appear in the dataset: {ERRORS}", |
691 ARGS.out_log) | 697 # ARGS.out_log) |
692 | 698 |
693 return | 699 # return |
694 | 700 |
695 # This is the standard flow of the ras_generator program, for non-custom models. | 701 # This is the standard flow of the ras_generator program, for non-custom models. |
696 name = "RAS Dataset" | 702 #name = "RAS Dataset" |
697 type_gene = gene_type(dataset.iloc[0, 0], name) | 703 #type_gene = gene_type(dataset.iloc[0, 0], name) |
698 | 704 |
699 rules = model.getRules(ARGS.tool_dir) | 705 #rules = model.getRules(ARGS.tool_dir) |
700 genes = data_gene(dataset, type_gene, name, None) | 706 #genes = data_gene(dataset, type_gene, name, None) |
701 ids, rules = load_id_rules(rules.get(type_gene)) | 707 #ids, rules = load_id_rules(rules.get(type_gene)) |
702 | 708 |
703 resolve_rules, err = resolve(genes, rules, ids, ARGS.none, name) | 709 #resolve_rules, err = resolve(genes, rules, ids, ARGS.none, name) |
704 create_ras(resolve_rules, name, rules, ids, ARGS.ras_output) | 710 #create_ras(resolve_rules, name, rules, ids, ARGS.ras_output) |
705 | 711 |
706 if err: utils.logWarning( | 712 #if err: utils.logWarning( |
707 f"Warning: gene(s) {err} not found in class \"{name}\", " + | 713 # f"Warning: gene(s) {err} not found in class \"{name}\", " + |
708 "the expression level for this gene will be considered NaN", | 714 # "the expression level for this gene will be considered NaN", |
709 ARGS.out_log) | 715 # ARGS.out_log) |
710 | 716 |
711 print("Execution succeded") | 717 print("Execution succeded") |
712 | 718 |
713 ############################################################################### | 719 ############################################################################### |
714 if __name__ == "__main__": | 720 if __name__ == "__main__": |