Mercurial > repos > bimib > cobraxy
comparison COBRAxy/ras_generator.py @ 147:3fca9b568faf draft
Uploaded
author | bimib |
---|---|
date | Wed, 06 Nov 2024 13:57:24 +0000 |
parents | 7e703e546998 |
children |
comparison
equal
deleted
inserted
replaced
146:88cf4543e210 | 147:3fca9b568faf |
---|---|
10 from typing import Union, Optional, List, Dict, Tuple, TypeVar | 10 from typing import Union, Optional, List, Dict, Tuple, TypeVar |
11 | 11 |
12 ERRORS = [] | 12 ERRORS = [] |
13 ########################## argparse ########################################## | 13 ########################## argparse ########################################## |
14 ARGS :argparse.Namespace | 14 ARGS :argparse.Namespace |
15 def process_args() -> argparse.Namespace: | 15 def process_args(args:List[str] = None) -> argparse.Namespace: |
16 """ | 16 """ |
17 Processes command-line arguments. | 17 Processes command-line arguments. |
18 | 18 |
19 Args: | 19 Args: |
20 args (list): List of command-line arguments. | 20 args (list): List of command-line arguments. |
59 | 59 |
60 parser.add_argument( | 60 parser.add_argument( |
61 '-ra', '--ras_output', | 61 '-ra', '--ras_output', |
62 type = str, | 62 type = str, |
63 required = True, help = 'ras output') | 63 required = True, help = 'ras output') |
64 | 64 |
65 return parser.parse_args() | 65 |
66 return parser.parse_args(args) | |
66 | 67 |
67 ############################ dataset input #################################### | 68 ############################ dataset input #################################### |
68 def read_dataset(data :str, name :str) -> pd.DataFrame: | 69 def read_dataset(data :str, name :str) -> pd.DataFrame: |
69 """ | 70 """ |
70 Read a dataset from a CSV file and return it as a pandas DataFrame. | 71 Read a dataset from a CSV file and return it as a pandas DataFrame. |
645 if filenamePath.ext is utils.FileFormat.PICKLE: return utils.readPickle(datFilePath) | 646 if filenamePath.ext is utils.FileFormat.PICKLE: return utils.readPickle(datFilePath) |
646 | 647 |
647 # csv rules need to be parsed, those in a pickle format are taken to be pre-parsed. | 648 # csv rules need to be parsed, those in a pickle format are taken to be pre-parsed. |
648 return { line[0] : ruleUtils.parseRuleToNestedList(line[1]) for line in utils.readCsv(datFilePath) } | 649 return { line[0] : ruleUtils.parseRuleToNestedList(line[1]) for line in utils.readCsv(datFilePath) } |
649 | 650 |
650 def main() -> None: | 651 def main(args:List[str] = None) -> None: |
651 """ | 652 """ |
652 Initializes everything and sets the program in motion based on the fronted input arguments. | 653 Initializes everything and sets the program in motion based on the fronted input arguments. |
653 | 654 |
654 Returns: | 655 Returns: |
655 None | 656 None |
656 """ | 657 """ |
657 # get args from frontend (related xml) | 658 # get args from frontend (related xml) |
658 global ARGS | 659 global ARGS |
659 ARGS = process_args() | 660 ARGS = process_args(args) |
660 print(ARGS.rules_selector) | 661 print(ARGS.rules_selector) |
661 # read dataset | 662 # read dataset |
662 dataset = read_dataset(ARGS.input, "dataset") | 663 dataset = read_dataset(ARGS.input, "dataset") |
663 dataset.iloc[:, 0] = (dataset.iloc[:, 0]).astype(str) | 664 dataset.iloc[:, 0] = (dataset.iloc[:, 0]).astype(str) |
664 | 665 |