comparison COBRAxy/marea.py @ 146:88cf4543e210 draft

Uploaded
author bimib
date Wed, 06 Nov 2024 10:12:52 +0000
parents 0f5564819296
children 3fca9b568faf
comparison
equal deleted inserted replaced
145:0f5564819296 146:88cf4543e210
18 import copy 18 import copy
19 19
20 ERRORS = [] 20 ERRORS = []
21 ########################## argparse ########################################## 21 ########################## argparse ##########################################
22 ARGS :argparse.Namespace 22 ARGS :argparse.Namespace
23 def process_args() -> argparse.Namespace: 23 def process_args(args=None) -> argparse.Namespace:
24 """ 24 """
25 Interfaces the script of a module with its frontend, making the user's choices for various parameters available as values in code. 25 Interfaces the script of a module with its frontend, making the user's choices for various parameters available as values in code.
26 26
27 Args: 27 Args:
28 args : Always obtained (in file) from sys.argv 28 args : Always obtained (in file) from sys.argv
145 '-cm', '--custom_map', 145 '-cm', '--custom_map',
146 type = str, 146 type = str,
147 help='custom map to use') 147 help='custom map to use')
148 148
149 parser.add_argument( 149 parser.add_argument(
150 '-idop', '--output_path',
151 type = str,
152 default='result',
153 help = 'output path for maps')
154
155 parser.add_argument(
150 '-mc', '--choice_map', 156 '-mc', '--choice_map',
151 type = utils.Model, default = utils.Model.HMRcore, 157 type = utils.Model, default = utils.Model.HMRcore,
152 choices = [utils.Model.HMRcore, utils.Model.ENGRO2, utils.Model.Custom]) 158 choices = [utils.Model.HMRcore, utils.Model.ENGRO2, utils.Model.Custom])
153 159
154 args :argparse.Namespace = parser.parse_args() 160 args :argparse.Namespace = parser.parse_args(args)
155 if args.using_RAS and not args.using_RPS: args.net = False 161 if args.using_RAS and not args.using_RPS: args.net = False
156 162
157 return args 163 return args
158 164
159 ############################ dataset input #################################### 165 ############################ dataset input ####################################
649 f"{dataset1Name}_vs_{dataset2Name}" + (f" ({details})" if details else ""), 655 f"{dataset1Name}_vs_{dataset2Name}" + (f" ({details})" if details else ""),
650 # ^^^ yes this string is built every time even if the form is the same for the same 2 datasets in 656 # ^^^ yes this string is built every time even if the form is the same for the same 2 datasets in
651 # all output files: I don't care, this was never the performance bottleneck of the tool and 657 # all output files: I don't care, this was never the performance bottleneck of the tool and
652 # there is no other net gain in saving and re-using the built string. 658 # there is no other net gain in saving and re-using the built string.
653 ext, 659 ext,
654 prefix = "result") 660 prefix = ARGS.output_path)
655 661
656 FIELD_NOT_AVAILABLE = '/' 662 FIELD_NOT_AVAILABLE = '/'
657 def writeToCsv(rows: List[list], fieldNames :List[str], outPath :utils.FilePath) -> None: 663 def writeToCsv(rows: List[list], fieldNames :List[str], outPath :utils.FilePath) -> None:
658 fieldsAmt = len(fieldNames) 664 fieldsAmt = len(fieldNames)
659 with open(outPath.show(), "w", newline = "") as fd: 665 with open(outPath.show(), "w", newline = "") as fd:
863 869
864 dataset = dataset.drop(dataset.columns[0], axis = "columns").to_dict("list") 870 dataset = dataset.drop(dataset.columns[0], axis = "columns").to_dict("list")
865 return { id : list(map(utils.Float("Dataset values, not an argument"), values)) for id, values in dataset.items() }, IDs 871 return { id : list(map(utils.Float("Dataset values, not an argument"), values)) for id, values in dataset.items() }, IDs
866 872
867 ############################ MAIN ############################################# 873 ############################ MAIN #############################################
868 def main() -> None: 874 def main(args=None) -> None:
869 """ 875 """
870 Initializes everything and sets the program in motion based on the fronted input arguments. 876 Initializes everything and sets the program in motion based on the fronted input arguments.
871 877
872 Returns: 878 Returns:
873 None 879 None
874 880
875 Raises: 881 Raises:
876 sys.exit : if a user-provided custom map is in the wrong format (ET.XMLSyntaxError, ET.XMLSchemaParseError) 882 sys.exit : if a user-provided custom map is in the wrong format (ET.XMLSyntaxError, ET.XMLSchemaParseError)
877 """ 883 """
878 global ARGS 884 global ARGS
879 ARGS = process_args() 885 ARGS = process_args(args)
880 886
881 if not os.path.isdir('result'): 887 if not os.path.isdir(ARGS.output_path):
882 os.makedirs('result') 888 os.makedirs(ARGS.output_path)
883 889
884 core_map: ET.ElementTree = ARGS.choice_map.getMap( 890 core_map: ET.ElementTree = ARGS.choice_map.getMap(
885 ARGS.tool_dir, 891 ARGS.tool_dir,
886 utils.FilePath.fromStrPath(ARGS.custom_map) if ARGS.custom_map else None) 892 utils.FilePath.fromStrPath(ARGS.custom_map) if ARGS.custom_map else None)
887 893