Mercurial > repos > rv43 > chess_tomo
changeset 22:b156e4cee6d7 draft
planemo upload for repository https://github.com/rolfverberg/galaxytools commit f8c4bdb31c20c468045ad5e6eb255a293244bc6c-dirty
| author | rv43 |
|---|---|
| date | Tue, 21 Mar 2023 15:52:16 +0000 |
| parents | 7a7233e212be |
| children | fbbd82938303 |
| files | tomo_reconstruct.py tomo_reconstruct.xml |
| diffstat | 2 files changed, 147 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tomo_reconstruct.py Tue Mar 21 15:52:16 2023 +0000 @@ -0,0 +1,113 @@ +#!/usr/bin/env python3 + +import logging + +import argparse +import pathlib +import sys +#import tracemalloc + +from workflow.run_tomo import Tomo + +#from memory_profiler import profile +#@profile +def __main__(): + # Parse command line arguments + parser = argparse.ArgumentParser( + description='Perform a tomography reconstruction') + parser.add_argument('-i', '--input_file', + required=True, + type=pathlib.Path, + help='''Full or relative path to the input file (in Nexus format).''') + parser.add_argument('-c', '--center_file', + required=True, + type=pathlib.Path, + help='''Full or relative path to the center info file (in yaml format).''') + parser.add_argument('-o', '--output_file', + required=False, + type=pathlib.Path, + help='''Full or relative path to the output file (in Nexus format).''') + parser.add_argument('--galaxy_flag', + action='store_true', + help='''Use this flag to run the scripts as a galaxy tool.''') + parser.add_argument('-l', '--log', +# type=argparse.FileType('w'), + default=sys.stdout, + help='Logging stream or filename') + parser.add_argument('--log_level', + choices=logging._nameToLevel.keys(), + default='INFO', + help='''Specify a preferred logging level.''') + parser.add_argument('--x_bounds', + required=False, + nargs=2, + type=int, + help='''Boundaries of reconstructed images in x-direction.''') + parser.add_argument('--y_bounds', + required=False, + nargs=2, + type=int, + help='''Boundaries of reconstructed images in y-direction.''') + args = parser.parse_args() + + # Set log configuration + # When logging to file, the stdout log level defaults to WARNING + logging_format = '%(asctime)s : %(levelname)s - %(module)s : %(funcName)s - %(message)s' + level = logging.getLevelName(args.log_level) + if args.log is sys.stdout: + logging.basicConfig(format=logging_format, level=level, force=True, + handlers=[logging.StreamHandler()]) + else: + if isinstance(args.log, str): + logging.basicConfig(filename=f'{args.log}', filemode='w', + format=logging_format, level=level, force=True) + elif isinstance(args.log, io.TextIOWrapper): + logging.basicConfig(filemode='w', format=logging_format, level=level, + stream=args.log, force=True) + else: + raise(ValueError(f'Invalid argument --log: {args.log}')) + stream_handler = logging.StreamHandler() + logging.getLogger().addHandler(stream_handler) + stream_handler.setLevel(logging.WARNING) + stream_handler.setFormatter(logging.Formatter(logging_format)) + + # Starting memory monitoring +# tracemalloc.start() + + # Log command line arguments + logging.info(f'input_file = {args.input_file}') + logging.info(f'center_file = {args.center_file}') + logging.info(f'output_file = {args.output_file}') + logging.info(f'galaxy_flag = {args.galaxy_flag}') + logging.debug(f'log = {args.log}') + logging.debug(f'is log stdout? {args.log is sys.stdout}') + logging.debug(f'log_level = {args.log_level}') + logging.info(f'x_bounds = {args.x_bounds}') + logging.info(f'y_bounds = {args.y_bounds}') + + # Instantiate Tomo object + tomo = Tomo(galaxy_flag=args.galaxy_flag) + + # Read input file + data = tomo.read(args.input_file) + + # Read center data + center_data = tomo.read(args.center_file) + + # Find the calibrated center axis info + data = tomo.reconstruct_data(data, center_data, x_bounds=args.x_bounds, y_bounds=args.y_bounds) + + # Write output file + data = tomo.write(data, args.output_file) + + # Displaying memory usage +# logging.info(f'Memory usage: {tracemalloc.get_traced_memory()}') + + # stopping memory monitoring +# tracemalloc.stop() + + logging.info('Completed tomography reconstruction') + + +if __name__ == "__main__": + __main__()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tomo_reconstruct.xml Tue Mar 21 15:52:16 2023 +0000 @@ -0,0 +1,34 @@ +<tool id="tomo_reconstruct" name="Tomo Reconstruction" version="0.3.0" python_template_version="3.9"> + <description>Perform a tomography reconstruction</description> + <macros> + <import>tomo_macros.xml</import> + </macros> + <expand macro="requirements"/> + <command detect_errors="exit_code"> + <![CDATA[ + mkdir tomo_reconstruct_plots; + $__tool_directory__/tomo_reconstruct.py + --input_file "$input_file" + --center_file "$center_file" + --output_file "output.nex" + --galaxy_flag + -l "$log" + ]]> + </command> + <inputs> + <expand macro="common_inputs"/> + <param name="input_file" type="data" format="nex" optional="false" label="Reduced tomography data"/> + <param name="center_file" type="data" format="yaml" optional="false" label="Center axis input file"/> + </inputs> + <outputs> + <expand macro="common_outputs"/> + <collection name="tomo_reconstruct_plots" type="list" label="Data recontructed images"> + <discover_datasets pattern="__name_and_ext__" directory="tomo_reconstruct_plots"/> + </collection> + <data name="output_file" format="nex" label="Reconstructed tomography data" from_work_dir="output.nex"/> + </outputs> + <help><![CDATA[ + Reconstruct tomography images. + ]]></help> + <expand macro="citations"/> +</tool>
