Mercurial > repos > bimib > marea_2_0
changeset 223:00a58a6695e0 draft
Uploaded
author | luca_milaz |
---|---|
date | Sat, 06 Jul 2024 10:03:19 +0000 |
parents | 2778d3950ab7 |
children | e215efd29516 |
files | marea_2_0/model_generator.py marea_2_0/model_generator.xml marea_2_0/utils/model_generator.py marea_2_0/utils/model_generator.xml |
diffstat | 2 files changed, 0 insertions(+), 208 deletions(-) [+] |
line wrap: on
line diff
--- a/marea_2_0/utils/model_generator.py Sat Jul 06 10:00:28 2024 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,125 +0,0 @@ -import argparse -import utils.general_utils as utils -from typing import Optional, List -import os -import numpy as np -import pandas as pd -import cobra -from joblib import Parallel, delayed, cpu_count -import sys - -################################# process args ############################### -def process_args(args :List[str]) -> argparse.Namespace: - """ - Processes command-line arguments. - - Args: - args (list): List of command-line arguments. - - Returns: - Namespace: An object containing parsed arguments. - """ - parser = argparse.ArgumentParser(usage = '%(prog)s [options]', - description = 'process some value\'s') - - parser.add_argument( - '-ms', '--model_selector', - type = utils.Model, default = utils.Model.ENGRO2, choices = list(utils.Model.ENGRO2, utils.Model.Custom), - help = 'chose which type of model you want use') - - parser.add_argument("-mo", "--model", type = str, - help = "path to input file with custom rules, if provided") - - parser.add_argument("-mn", "--model_name", type = str, help = "custom mode name") - - parser.add_argument('-ol', '--out_log', - help = "Output log") - - parser.add_argument('-td', '--tool_dir', - type = str, - required = True, - help = 'your tool directory') - - parser.add_argument('-in', '--model', - required = True, - type=str, - help = 'input model') - - - parser.add_argument('-im', '--input_medium', - required = True, - type=str, - help = 'input medium') - - parser.add_argument('-ir', '--input_ras', - required = True, - type=str, - help = 'input ras') - - parser.add_argument('-ot', '--output_type', - type = str, - required = True, - help = 'output type') - - ARGS = parser.parse_args() - return ARGS - -########################### warning ########################################### -def warning(s :str) -> None: - """ - Log a warning message to an output log file and print it to the console. - - Args: - s (str): The warning message to be logged and printed. - - Returns: - None - """ - with open(ARGS.out_log, 'a') as log: - log.write(s + "\n\n") - print(s) - - -def write_to_file(dataset: pd.DataFrame, name: str, keep_index:bool=False)->None: - dataset.to_csv(ARGS.output_folder + name + ".csv", sep = '\t', index = keep_index) - - -def generate_model(cell_name, ras, medium): - # compute FVA - pass - - -############################# main ########################################### -def main() -> None: - """ - Initializes everything and sets the program in motion based on the fronted input arguments. - - Returns: - None - """ - if not os.path.exists('model_generator'): - os.makedirs('model_generator') - - num_processors = cpu_count() - - global ARGS - ARGS = process_args(sys.argv) - - ARGS.output_folder = 'model_generator/' - - ARGS.output_types = ARGS.output_type.split(",") - - ras = pd.read_table(ARGS.input_ras, header=0, sep=r'\s+', index_col = 0).T - ras.replace("None", None, inplace=True) - - #medium has rows cells and columns medium reactions, not common reactions set to None - medium = pd.read_csv(ARGS.input_medium, sep = '\t', header = 0, engine='python', index_col = 0) - - for index, row in ras.iterrows(): #iterate over cells RAS - generate_model(index, row, medium.loc[index]) - - pass - -############################################################################## -if __name__ == "__main__": - main() \ No newline at end of file
--- a/marea_2_0/utils/model_generator.xml Sat Jul 06 10:00:28 2024 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,83 +0,0 @@ -<tool id="modelGenerator" name="COBRAxy Model generator" version="2.0.0"> - - <macros> - <import>marea_macros.xml</import> - </macros> - - <requirements> - <requirement type="package" version="0.29.0">cobra</requirement> - <requirement type="package" version="4.9.3">lxml</requirement> - <requirement type="package" version="1.4.2">joblib</requirement> - </requirements> - - <command detect_errors="exit_code"> - <![CDATA[ - python $__tool_directory__/model_generator.py - --model_selector $cond_model.model_selector - --tool_dir $__tool_directory__ - --input_medium $input_medium - --input_ras $input_ras - --output_type "${",".join(map(str, $output_types))}" - --out_log $log - #if $cond_model.model_selector == 'Custom' - --model $model - --model_name $model.element_identifier - #end if - ]]> - </command> - - <inputs> - - <conditional name="cond_model"> - <expand macro="options"/> - <when value="Custom"> - <param name="model" argument="--model" type="data" format="json, xml" label="Custom modellll" /> - </when> - </conditional> - - <param name="input_ras" argument="--input_ras" multiple="false" type="data" format="tabular, csv, tsv" label="RAS matrix:" /> - - <param name="input_medium" argument="--input_medium" multiple="false" type="data" format="tabular, csv, tsv" label="Medium:"/> - - <param type="select" argument="--output_types" multiple="true" name="output_types" label="Desired outputs"> - <option value="FBA" selected="false">FBA</option> - <option value="pFBA" selected="false">pFBA</option> - <option value="FVA" selected="false">FVA</option> - <option value="sensitivity" selected="false">Sensitivity knock-out</option> - </param> - - </inputs> - - - <outputs> - <data format="txt" name="log" label="modelGenerator - Log" /> - <collection name="results" type="list" label="${tool.name} - Results"> - <discover_datasets pattern="__name_and_ext__" directory="model_generator"/> - </collection> - </outputs> - - - <help> - <![CDATA[ -What it does -------------- - -This tool generates flux samples starting from a model in JSON or XML format by using CBS (Corner-based sampling) and OPTGP (mproved Artificial Centering Hit-and-Run sampler) sampling algorithms. - -Accepted files: - - A model: JSON or XML file reporting reactions and rules contained in the model. It can be a single model, multiple models or a collection of models. - -Output: -------------- - -The tool generates: - - Samples: reporting the sampled fluxes for each reaction. Format: csv or pickle. - - a log file (.txt). - -**TIP**: The Batches parameter is useful to mantain in memory just a batch of samples at time. For example, if you wish to sample 10.000 points, than it is suggested to select n_samples = 1.000 and n_batches=10. - - -]]> - </help> - <expand macro="citations" /> -</tool> \ No newline at end of file