Mercurial > repos > bimib > cobraxy
comparison COBRAxy/ras_generator.py @ 309:38c9a958ea78 draft
Uploaded
| author | francesco_lapi |
|---|---|
| date | Thu, 22 May 2025 16:03:37 +0000 |
| parents | 0025449eadba |
| children | 0a3ca20848f3 |
comparison
equal
deleted
inserted
replaced
| 308:797d0e002934 | 309:38c9a958ea78 |
|---|---|
| 6 import pandas as pd | 6 import pandas as pd |
| 7 import pickle as pk | 7 import pickle as pk |
| 8 import utils.general_utils as utils | 8 import utils.general_utils as utils |
| 9 import utils.rule_parsing as ruleUtils | 9 import utils.rule_parsing as ruleUtils |
| 10 from typing import Union, Optional, List, Dict, Tuple, TypeVar | 10 from typing import Union, Optional, List, Dict, Tuple, TypeVar |
| 11 import os | |
| 11 | 12 |
| 12 ERRORS = [] | 13 ERRORS = [] |
| 13 ########################## argparse ########################################## | 14 ########################## argparse ########################################## |
| 14 ARGS :argparse.Namespace | 15 ARGS :argparse.Namespace |
| 15 def process_args(args:List[str] = None) -> argparse.Namespace: | 16 def process_args(args:List[str] = None) -> argparse.Namespace: |
| 210 gene_custom (dict or None): Custom gene data dictionary if provided. | 211 gene_custom (dict or None): Custom gene data dictionary if provided. |
| 211 | 212 |
| 212 Returns: | 213 Returns: |
| 213 dict: A dictionary containing gene data with gene IDs as keys and corresponding values. | 214 dict: A dictionary containing gene data with gene IDs as keys and corresponding values. |
| 214 """ | 215 """ |
| 215 args = process_args() | 216 |
| 216 for i in range(len(gene)): | 217 for i in range(len(gene)): |
| 217 tmp = gene.iloc[i, 0] | 218 tmp = gene.iloc[i, 0] |
| 218 gene.iloc[i, 0] = tmp.strip().split('.')[0] | 219 gene.iloc[i, 0] = tmp.strip().split('.')[0] |
| 219 | 220 |
| 220 gene_dup = [item for item, count in | 221 gene_dup = [item for item, count in |
| 225 gene_in_rule = None | 226 gene_in_rule = None |
| 226 | 227 |
| 227 if gene_dup: | 228 if gene_dup: |
| 228 if gene_custom == None: | 229 if gene_custom == None: |
| 229 | 230 |
| 230 if str(args.rules_selector) == 'HMRcore': | 231 if str(ARGS.rules_selector) == 'HMRcore': |
| 231 gene_in_rule = pk.load(open(args.tool_dir + '/local/pickle files/HMRcore_genes.p', 'rb')) | 232 gene_in_rule = pk.load(open(ARGS.tool_dir + '/local/pickle files/HMRcore_genes.p', 'rb')) |
| 232 | 233 |
| 233 elif str(args.rules_selector) == 'Recon': | 234 elif str(ARGS.rules_selector) == 'Recon': |
| 234 gene_in_rule = pk.load(open(args.tool_dir + '/local/pickle files/Recon_genes.p', 'rb')) | 235 gene_in_rule = pk.load(open(ARGS.tool_dir + '/local/pickle files/Recon_genes.p', 'rb')) |
| 235 | 236 |
| 236 elif str(args.rules_selector) == 'ENGRO2': | 237 elif str(ARGS.rules_selector) == 'ENGRO2': |
| 237 gene_in_rule = pk.load(open(args.tool_dir + '/local/pickle files/ENGRO2_genes.p', 'rb')) | 238 gene_in_rule = pk.load(open(ARGS.tool_dir + '/local/pickle files/ENGRO2_genes.p', 'rb')) |
| 238 | 239 |
| 239 utils.logWarning(f"{args.tool_dir}'/local/pickle files/ENGRO2_genes.p'", ARGS.out_log) | 240 utils.logWarning(f"{ARGS.tool_dir}'/local/pickle files/ENGRO2_genes.p'", ARGS.out_log) |
| 240 | 241 |
| 241 gene_in_rule = gene_in_rule.get(type_gene) | 242 gene_in_rule = gene_in_rule.get(type_gene) |
| 242 | 243 |
| 243 else: | 244 else: |
| 244 gene_in_rule = gene_custom | 245 gene_in_rule = gene_custom |
| 660 None | 661 None |
| 661 """ | 662 """ |
| 662 # get args from frontend (related xml) | 663 # get args from frontend (related xml) |
| 663 global ARGS | 664 global ARGS |
| 664 ARGS = process_args(args) | 665 ARGS = process_args(args) |
| 665 print(ARGS.rules_selector) | 666 |
| 666 # read dataset | 667 # read dataset |
| 667 dataset = read_dataset(ARGS.input, "dataset") | 668 dataset = read_dataset(ARGS.input, "dataset") |
| 668 dataset.iloc[:, 0] = (dataset.iloc[:, 0]).astype(str) | 669 dataset.iloc[:, 0] = (dataset.iloc[:, 0]).astype(str) |
| 669 | 670 |
| 670 # remove versioning from gene names | 671 # remove versioning from gene names |
| 671 dataset.iloc[:, 0] = dataset.iloc[:, 0].str.split('.').str[0] | 672 dataset.iloc[:, 0] = dataset.iloc[:, 0].str.split('.').str[0] |
| 672 | 673 |
| 673 # handle custom models | 674 # handle custom models |
| 674 model :utils.Model = ARGS.rules_selector | 675 model :utils.Model = ARGS.rules_selector |
| 676 | |
| 675 if model is utils.Model.Custom: | 677 if model is utils.Model.Custom: |
| 676 rules = load_custom_rules() | 678 rules = load_custom_rules() |
| 677 reactions = list(rules.keys()) | 679 reactions = list(rules.keys()) |
| 678 | 680 |
| 679 save_as_tsv(ras_for_cell_lines(dataset, rules), reactions) | 681 save_as_tsv(ras_for_cell_lines(dataset, rules), reactions) |
