Mercurial > repos > bimib > cobraxy
comparison COBRAxy/fromCSVtoCOBRA_beta.py @ 451:a4e8f3188813 draft
Uploaded
| author | francesco_lapi |
|---|---|
| date | Thu, 11 Sep 2025 20:34:30 +0000 |
| parents | |
| children | 51f794fff930 |
comparison
equal
deleted
inserted
replaced
| 450:d9a9e909cd9e | 451:a4e8f3188813 |
|---|---|
| 1 import os | |
| 2 import csv | |
| 3 import cobra | |
| 4 import pickle | |
| 5 import argparse | |
| 6 import pandas as pd | |
| 7 import utils.general_utils as utils | |
| 8 from typing import Optional, Tuple, Union, List, Dict | |
| 9 import logging | |
| 10 import utils.rule_parsing as rulesUtils | |
| 11 import utils.reaction_parsing as reactionUtils | |
| 12 import utils.model_utils as modelUtils | |
| 13 | |
| 14 ARGS : argparse.Namespace | |
| 15 def process_args(args: List[str] = None) -> argparse.Namespace: | |
| 16 """ | |
| 17 Parse command-line arguments for CustomDataGenerator. | |
| 18 """ | |
| 19 | |
| 20 parser = argparse.ArgumentParser( | |
| 21 usage="%(prog)s [options]", | |
| 22 description="Generate custom data from a given model" | |
| 23 ) | |
| 24 | |
| 25 parser.add_argument("--out_log", type=str, required=True, | |
| 26 help="Output log file") | |
| 27 | |
| 28 parser.add_argument("--input", type=str, | |
| 29 help="Input tabular file") | |
| 30 | |
| 31 parser.add_argument("--format", type=str, required=True, choices=["sbml", "json", "mat", "yaml"], | |
| 32 help="Model format (SBML, JSON, MATLAB, YAML)") | |
| 33 | |
| 34 parser.add_argument("--output", type=str, | |
| 35 help="Output model file") | |
| 36 | |
| 37 parser.add_argument("--tool_dir", type=str, default=os.path.dirname(__file__), | |
| 38 help="Tool directory (passed from Galaxy as $__tool_directory__)") | |
| 39 | |
| 40 | |
| 41 | |
| 42 return parser.parse_args(args) | |
| 43 | |
| 44 ###############################- ENTRY POINT -################################ | |
| 45 def main(args:List[str] = None) -> None: | |
| 46 """ | |
| 47 Initializes everything and sets the program in motion based on the fronted input arguments. | |
| 48 | |
| 49 Returns: | |
| 50 None | |
| 51 """ | |
| 52 # get args from frontend (related xml) | |
| 53 global ARGS | |
| 54 ARGS = process_args(args) | |
| 55 | |
| 56 model = modelUtils.build_cobra_model_from_csv(ARGS.model_upload) | |
| 57 | |
| 58 | |
| 59 if ARGS.format == "sbml": | |
| 60 cobra.io.write_sbml_model(model, ARGS.output) | |
| 61 elif ARGS.format == "json": | |
| 62 cobra.io.save_json_model(model, ARGS.output) | |
| 63 elif ARGS.format == "mat": | |
| 64 cobra.io.save_matlab_model(model, ARGS.output) | |
| 65 elif ARGS.format == "yaml": | |
| 66 cobra.io.save_yaml_model(model, ARGS.output) | |
| 67 | |
| 68 if __name__ == '__main__': | |
| 69 main() |
