def main(): start_time = datetime.now() args = cells_standard_space_cli_parser().parse_args() args.paths = prep.Paths(args.output_dir) args.paths.standard_space_output_folder = args.output_dir args.paths.cells_in_standard_space = join(args.paths.output_dir, "cells_in_standard_space.xml") cli_path_update(args.paths, args) args.paths.make_invert_cell_position_paths() args = define_pixel_sizes(args) # TODO: implement a recursive function to remove the need to do this # (probably using pathlib) system.ensure_directory_exists(args.paths.output_dir) system.ensure_directory_exists(args.paths.standard_space_output_folder) tools.start_logging( args.paths.output_dir, args=args, verbose=args.debug, filename="cells_to_standard_space", log_header="CELL TRANSFORMATION TO STANDARD SPACE LOG", ) logging.info("Starting transformation of cell positions") transform_cells_to_standard_space(args) logging.info("Finished. Total time taken: %s", datetime.now() - start_time)
def main(): # TODO: remove converting to strings when cellfinder is python >3.6 only start_time = datetime.now() args = cube_extract_cli_parser().parse_args() args = define_pixel_sizes(args) args = prep_channel_ids(args) # TODO: can these be set in argparse? args.output_dir = Path(args.output_dir) args.cells_file_path = Path(args.cells_file_path) args.cube_extract_cli = True args.paths = prep.Paths(args.output_dir) system.ensure_directory_exists(args.output_dir) tools.start_logging( str(args.output_dir), args=args, verbose=args.debug, filename="batch_cube_extraction", log_header="CELLFINDER BATCH CUBE EXTRACTION LOG", ) logging.info("Starting cube extraction") num_channels = len(args.raw_data_paths) if args.cells_file_path.is_dir(): indv_cells_paths = natsorted(subdirs(args.cells_file_path)) elif args.cells_file_path.is_file(): tmp_paths = tools.get_text_lines(args.cells_file_path) indv_cells_paths = natsorted([Path(path) for path in tmp_paths]) if indv_cells_paths[0].is_dir(): logging.info("Assuming cube definition data is output from ROI Sorter") cells_dir_names = [path.name for path in indv_cells_paths] if tools.is_any_list_overlap(cells_dir_names, train_data_gen_dir_names): # If there is only training data from one sample, make a list of 1 indv_cells_paths = [args.cells_file_path] for idx, sample_dir in enumerate(indv_cells_paths): logging.info("Extracting cubes from: {}".format(sample_dir.name)) args.all_planes_paths = [] system.ensure_directory_exists( args.output_dir.joinpath(sample_dir.name)) for channel in range(num_channels): args.all_planes_paths.append( tools.get_text_lines( args.raw_data_paths[channel], return_lines=idx, sort=True, )) for sub_dir_name in train_data_gen_dir_names: if sub_dir_name in subdirs(sample_dir, names_only=True): logging.info("Extracting: {}".format(sub_dir_name)) args.paths.tmp__cubes_output_dir = str( args.output_dir.joinpath(sample_dir.name, sub_dir_name)) args.paths.cells_file_path = str( args.cells_file_path.joinpath(sample_dir.name, sub_dir_name)) extract_loop(args) else: if indv_cells_paths[0].suffix in SUPPORTED_CELL_FILE_FORMATS: logging.info("Cube definition file is: '{}', proceeding." "".format(indv_cells_paths[0].suffix)) raise NotImplementedError( "Cube definition file is: '{}', NOT YET SUPPORTED." "".format(indv_cells_paths[0].suffix)) else: raise NotImplementedError( "File format: '{}' is not yet supported. Please use the " "output of ROI Sorter, or provide one of: {}".format( indv_cells_paths[0].suffix, SUPPORTED_CELL_FILE_FORMATS)) logging.info("Finished. Total time taken: %s", datetime.now() - start_time)