Mercurial > repos > siwaa > gama_desc
diff desc.py @ 0:23b15c0eabff draft default tip
planemo upload for repository https://forgemia.inra.fr/nathalie.rousse/use/-/tree/gama/GAMA_DESC/galaxy-tools commit 6b9b95de1fe709f27a28d83797f81e91469edf79-dirty
author | siwaa |
---|---|
date | Mon, 18 Nov 2024 13:57:51 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/desc.py Mon Nov 18 13:57:51 2024 +0000 @@ -0,0 +1,69 @@ +#!/usr/bin/env python +# coding: utf-8 + +#----------------------------------------------------------------- +__author__ = "Nathalie Rousse (nathalie.rousse@inrae.fr)" +__copyright__ = "Copyright (C) 2024, Inrae (https://www.inrae.fr)" +__license__ = "MIT" +#----------------------------------------------------------------- + +import json + +# Produces a description JSON data from a GAML model file + +############################################################################### + +def make_json_experiments_by_types(gaml_file_path): + + # experiments contains lists of experiment names, by type + experiments = { "gui": [], "batch": [], "test": [], "memorize": [] } + + with open(gaml_file_path, 'r') as f: + lines = f.readlines() + + for line in lines: + experiment_name, type = None, None # default + line_kept = True # default + if "experiment" not in line : line_kept = False + if ("type " not in line and "type:" not in line) : line_kept = False + + if line_kept : + words = line.split() + if words[0] == 'experiment' : + experiment_name = words[1] + else: + line_kept = False + + if line_kept : + while " :" in line: + line = line.replace(" :", ":") + line = line.replace(":", ": ") + words = line.split() + for i,word in enumerate(words) : + if word == "type:" : + if words[i+1] in ("gui", "batch", "test", "memorize"): + type = words[i+1] + if line_kept and (experiment_name is not None) and (type is not None): + experiments[type].append(experiment_name) + + return experiments + +############################################################################### + +GAML_FILE_PATH = "model.gaml" +DESC_JSON_FILE_PATH = "desc.json" + +try : + desc = dict() + experiments = make_json_experiments_by_types(gaml_file_path=GAML_FILE_PATH) + desc['experiments_by_types'] = experiments + print(desc) + with open(DESC_JSON_FILE_PATH, "w") as json_file: + json_file.write(json.dumps(desc)) + +except Exception as e : + errortype = type(e).__name__ + errordetails = e.args + print("ERROR:", errortype, errordetails) + +###############################################################################