comparison COBRAxy/custom_data_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
4 import pickle 4 import pickle
5 import argparse 5 import argparse
6 import pandas as pd 6 import pandas as pd
7 import utils.general_utils as utils 7 import utils.general_utils as utils
8 import utils.rule_parsing as rulesUtils 8 import utils.rule_parsing as rulesUtils
9 from typing import Optional, Tuple, Union, Dict 9 from typing import Optional, Tuple, Union, List, Dict
10 import utils.reaction_parsing as reactionUtils 10 import utils.reaction_parsing as reactionUtils
11 11
12 ARGS : argparse.Namespace 12 ARGS : argparse.Namespace
13 def process_args() -> argparse.Namespace: 13 def process_args(args:List[str] = None) -> argparse.Namespace:
14 """ 14 """
15 Interfaces the script of a module with its frontend, making the user's choices for 15 Interfaces the script of a module with its frontend, making the user's choices for
16 various parameters available as values in code. 16 various parameters available as values in code.
17 17
18 Args: 18 Args:
33 parser.add_argument("-obnds", "--out_bounds", type = str, required = True, help = "Output bounds") 33 parser.add_argument("-obnds", "--out_bounds", type = str, required = True, help = "Output bounds")
34 34
35 parser.add_argument("-id", "--input", type = str, required = True, help = "Input model") 35 parser.add_argument("-id", "--input", type = str, required = True, help = "Input model")
36 parser.add_argument("-mn", "--name", type = str, required = True, help = "Input model name") 36 parser.add_argument("-mn", "--name", type = str, required = True, help = "Input model name")
37 # ^ I need this because galaxy converts my files into .dat but I need to know what extension they were in 37 # ^ I need this because galaxy converts my files into .dat but I need to know what extension they were in
38 38 parser.add_argument('-idop', '--output_path', type = str, default='result', help = 'output path for maps')
39 argsNamespace = parser.parse_args() 39 argsNamespace = parser.parse_args(args)
40 argsNamespace.out_dir = "result"
41 # ^ can't get this one to work from xml, there doesn't seem to be a way to get the directory attribute from the collection 40 # ^ can't get this one to work from xml, there doesn't seem to be a way to get the directory attribute from the collection
42 41
43 return argsNamespace 42 return argsNamespace
44 43
45 ################################- INPUT DATA LOADING -################################ 44 ################################- INPUT DATA LOADING -################################
182 181
183 for key, value in data.items(): 182 for key, value in data.items():
184 writer.writerow({ fieldNames[0] : key, fieldNames[1] : value }) 183 writer.writerow({ fieldNames[0] : key, fieldNames[1] : value })
185 184
186 ###############################- ENTRY POINT -################################ 185 ###############################- ENTRY POINT -################################
187 def main() -> None: 186 def main(args:List[str] = None) -> None:
188 """ 187 """
189 Initializes everything and sets the program in motion based on the fronted input arguments. 188 Initializes everything and sets the program in motion based on the fronted input arguments.
190 189
191 Returns: 190 Returns:
192 None 191 None
193 """ 192 """
194 # get args from frontend (related xml) 193 # get args from frontend (related xml)
195 global ARGS 194 global ARGS
196 ARGS = process_args() 195 ARGS = process_args(args)
197 196
198 # this is the worst thing I've seen so far, congrats to the former MaREA devs for suggesting this! 197 # this is the worst thing I've seen so far, congrats to the former MaREA devs for suggesting this!
199 if os.path.isdir(ARGS.out_dir) == False: os.makedirs(ARGS.out_dir) 198 if os.path.isdir(ARGS.output_path) == False: os.makedirs(ARGS.output_path)
200 199
201 # load custom model 200 # load custom model
202 model = load_custom_model( 201 model = load_custom_model(
203 utils.FilePath.fromStrPath(ARGS.input), utils.FilePath.fromStrPath(ARGS.name).ext) 202 utils.FilePath.fromStrPath(ARGS.input), utils.FilePath.fromStrPath(ARGS.name).ext)
204 203