From 36df6fd9697cb19ac4e35d60eff892e4491511e5 Mon Sep 17 00:00:00 2001 From: b-heifets Date: Thu, 29 Aug 2024 21:23:04 +0000 Subject: [PATCH] deploy: 953b0ae2fb4ff54b21283b65fc9ccf13e34c23bf --- _modules/index.html | 3 +- .../unravel/cluster_stats/brain_model.html | 53 +- _modules/unravel/cluster_stats/crop.html | 48 +- _modules/unravel/cluster_stats/cstats.html | 48 +- .../effect_sizes/effect_sizes.html | 59 +- .../effect_sizes_by_sex__absolute.html | 56 +- .../effect_sizes_by_sex__relative.html | 57 +- _modules/unravel/cluster_stats/fdr.html | 48 +- _modules/unravel/cluster_stats/fdr_range.html | 34 +- .../find_incongruent_clusters.html | 46 +- .../cluster_stats/group_bilateral_data.html | 38 +- _modules/unravel/cluster_stats/index.html | 39 +- _modules/unravel/cluster_stats/legend.html | 32 +- _modules/unravel/cluster_stats/mean_IF.html | 32 +- .../cluster_stats/mean_IF_summary.html | 54 +- _modules/unravel/cluster_stats/org_data.html | 48 +- _modules/unravel/cluster_stats/prism.html | 34 +- ...ecursively_mirror_rev_cluster_indices.html | 36 +- .../unravel/cluster_stats/stats_table.html | 13 +- _modules/unravel/cluster_stats/summary.html | 100 ++- _modules/unravel/cluster_stats/sunburst.html | 58 +- _modules/unravel/cluster_stats/table.html | 44 +- .../unravel/cluster_stats/validation.html | 90 +- _modules/unravel/core/argparse_utils.html | 523 ----------- .../unravel/core/argparse_utils_rich.html | 525 ----------- _modules/unravel/core/config.html | 2 +- _modules/unravel/core/help_formatter.html | 840 ++++++++++++++++++ _modules/unravel/core/img_tools.html | 27 +- _modules/unravel/core/utils.html | 152 ++-- _modules/unravel/image_io/h5_to_tifs.html | 31 +- _modules/unravel/image_io/img_to_npy.html | 24 +- _modules/unravel/image_io/img_to_points.html | 32 +- _modules/unravel/image_io/io_img.html | 40 +- _modules/unravel/image_io/io_nii.html | 53 +- _modules/unravel/image_io/metadata.html | 61 +- _modules/unravel/image_io/nii_hd.html | 18 +- _modules/unravel/image_io/nii_info.html | 17 +- _modules/unravel/image_io/nii_to_tifs.html | 25 +- _modules/unravel/image_io/nii_to_zarr.html | 22 +- _modules/unravel/image_io/points_to_img.html | 39 +- _modules/unravel/image_io/reorient_nii.html | 39 +- _modules/unravel/image_io/tif_to_tifs.html | 42 +- _modules/unravel/image_io/zarr_to_nii.html | 30 +- _modules/unravel/image_tools/DoG.html | 32 +- .../image_tools/atlas/relabel_nii.html | 41 +- .../unravel/image_tools/atlas/wireframe.html | 39 +- _modules/unravel/image_tools/avg.html | 20 +- _modules/unravel/image_tools/bbox.html | 26 +- _modules/unravel/image_tools/extend.html | 47 +- _modules/unravel/image_tools/max.html | 17 +- _modules/unravel/image_tools/pad.html | 27 +- _modules/unravel/image_tools/rb.html | 35 +- _modules/unravel/image_tools/resample.html | 25 +- .../unravel/image_tools/resample_points.html | 44 +- .../image_tools/spatial_averaging.html | 48 +- .../unravel/image_tools/transpose_axes.html | 34 +- .../image_tools/unique_intensities.html | 28 +- _modules/unravel/region_stats/rstats.html | 79 +- .../unravel/region_stats/rstats_mean_IF.html | 34 +- .../rstats_mean_IF_in_segmented_voxels.html | 83 +- .../region_stats/rstats_mean_IF_summary.html | 78 +- .../unravel/region_stats/rstats_summary.html | 58 +- .../unravel/register/affine_initializer.html | 31 +- _modules/unravel/register/reg.html | 99 ++- _modules/unravel/register/reg_check.html | 50 +- .../register/reg_check_brain_mask.html | 47 +- _modules/unravel/register/reg_prep.html | 70 +- _modules/unravel/segment/brain_mask.html | 57 +- _modules/unravel/segment/copy_tifs.html | 86 +- .../segment/ilastik_pixel_classification.html | 89 +- _modules/unravel/segment/labels_to_masks.html | 41 +- _modules/unravel/unravel_commands.html | 42 +- .../aggregate_files_from_sample_dirs.html | 47 +- .../aggregate_files_recursively.html | 26 +- .../unravel/utilities/clean_tif_dirs.html | 52 +- .../unravel/utilities/points_compressor.html | 44 +- .../unravel/utilities/prepend_conditions.html | 45 +- _modules/unravel/utilities/rename.html | 36 +- .../unravel/utilities/toggle_samples.html | 65 +- _modules/unravel/voxel_stats/apply_mask.html | 68 +- .../unravel/voxel_stats/hemi_to_LR_avg.html | 30 +- _modules/unravel/voxel_stats/mirror.html | 29 +- .../voxel_stats/other/IF_outliers.html | 22 +- .../unravel/voxel_stats/other/r_to_p.html | 32 +- _modules/unravel/voxel_stats/vstats.html | 61 +- _modules/unravel/voxel_stats/vstats_prep.html | 79 +- .../unravel/voxel_stats/whole_to_LR_avg.html | 42 +- _modules/unravel/voxel_stats/z_score.html | 87 +- _modules/unravel/warp/points_to_atlas.html | 66 +- _modules/unravel/warp/to_atlas.html | 78 +- _modules/unravel/warp/to_fixed.html | 39 +- _modules/unravel/warp/to_native.html | 59 +- _modules/unravel/warp/warp.html | 43 +- _sources/guide.md.txt | 38 +- _sources/unravel/core/argparse_utils.rst.txt | 9 - .../unravel/core/argparse_utils_rich.rst.txt | 9 - _sources/unravel/core/help_formatter.rst.txt | 9 + _sources/unravel/core/toc.rst.txt | 3 +- genindex.html | 63 +- guide.html | 38 +- index.html | 3 +- objects.inv | Bin 7492 -> 7549 bytes py-modindex.html | 9 +- searchindex.js | 2 +- unravel/cluster_stats/brain_model.html | 32 +- unravel/cluster_stats/crop.html | 32 +- unravel/cluster_stats/cstats.html | 45 +- .../effect_sizes/effect_sizes.html | 49 +- .../effect_sizes_by_sex__absolute.html | 36 +- .../effect_sizes_by_sex__relative.html | 46 +- unravel/cluster_stats/effect_sizes/toc.html | 3 +- unravel/cluster_stats/fdr.html | 26 +- unravel/cluster_stats/fdr_range.html | 15 +- .../find_incongruent_clusters.html | 37 +- .../cluster_stats/group_bilateral_data.html | 38 +- unravel/cluster_stats/index.html | 15 +- unravel/cluster_stats/legend.html | 23 +- unravel/cluster_stats/mean_IF.html | 15 +- unravel/cluster_stats/mean_IF_summary.html | 45 +- unravel/cluster_stats/org_data.html | 18 +- unravel/cluster_stats/prism.html | 29 +- ...ecursively_mirror_rev_cluster_indices.html | 19 +- unravel/cluster_stats/stats_table.html | 3 +- unravel/cluster_stats/summary.html | 80 +- unravel/cluster_stats/sunburst.html | 42 +- unravel/cluster_stats/table.html | 31 +- unravel/cluster_stats/toc.html | 23 +- unravel/cluster_stats/validation.html | 34 +- unravel/core/argparse_utils_rich.html | 712 --------------- unravel/core/config.html | 13 +- ...rgparse_utils.html => help_formatter.html} | 185 ++-- unravel/core/img_io.html | 3 +- unravel/core/img_tools.html | 3 +- unravel/core/toc.html | 24 +- unravel/core/utils.html | 71 +- unravel/image_io/h5_to_tifs.html | 21 +- unravel/image_io/img_to_npy.html | 5 +- unravel/image_io/img_to_points.html | 17 +- unravel/image_io/io_img.html | 13 +- unravel/image_io/io_nii.html | 41 +- unravel/image_io/metadata.html | 39 +- unravel/image_io/nii_hd.html | 5 +- unravel/image_io/nii_info.html | 5 +- unravel/image_io/nii_to_tifs.html | 5 +- unravel/image_io/nii_to_zarr.html | 5 +- unravel/image_io/points_to_img.html | 21 +- unravel/image_io/reorient_nii.html | 19 +- unravel/image_io/tif_to_tifs.html | 21 +- unravel/image_io/toc.html | 4 +- unravel/image_io/zarr_to_nii.html | 17 +- unravel/image_tools/DoG.html | 13 +- unravel/image_tools/atlas/relabel_nii.html | 18 +- unravel/image_tools/atlas/toc.html | 3 +- unravel/image_tools/atlas/wireframe.html | 26 +- unravel/image_tools/avg.html | 5 +- unravel/image_tools/bbox.html | 5 +- unravel/image_tools/extend.html | 5 +- unravel/image_tools/max.html | 5 +- unravel/image_tools/pad.html | 5 +- unravel/image_tools/rb.html | 25 +- unravel/image_tools/resample.html | 5 +- unravel/image_tools/resample_points.html | 16 +- unravel/image_tools/spatial_averaging.html | 21 +- unravel/image_tools/toc.html | 3 +- unravel/image_tools/transpose_axes.html | 5 +- unravel/image_tools/unique_intensities.html | 9 +- unravel/region_stats/rstats.html | 38 +- unravel/region_stats/rstats_mean_IF.html | 20 +- .../rstats_mean_IF_in_segmented_voxels.html | 30 +- .../region_stats/rstats_mean_IF_summary.html | 64 +- unravel/region_stats/rstats_summary.html | 26 +- unravel/region_stats/toc.html | 6 +- unravel/register/affine_initializer.html | 17 +- unravel/register/reg.html | 59 +- unravel/register/reg_check.html | 18 +- unravel/register/reg_check_brain_mask.html | 21 +- unravel/register/reg_prep.html | 31 +- unravel/register/toc.html | 10 +- unravel/segment/brain_mask.html | 27 +- unravel/segment/copy_tifs.html | 30 +- .../segment/ilastik_pixel_classification.html | 49 +- unravel/segment/labels_to_masks.html | 5 +- unravel/segment/toc.html | 3 +- unravel/toc.html | 63 +- unravel/unravel_commands.html | 32 +- .../aggregate_files_from_sample_dirs.html | 19 +- .../aggregate_files_recursively.html | 5 +- unravel/utilities/clean_tif_dirs.html | 25 +- unravel/utilities/points_compressor.html | 29 +- unravel/utilities/prepend_conditions.html | 35 +- unravel/utilities/rename.html | 18 +- unravel/utilities/toc.html | 13 +- unravel/utilities/toggle_samples.html | 30 +- unravel/voxel_stats/apply_mask.html | 17 +- unravel/voxel_stats/hemi_to_LR_avg.html | 13 +- unravel/voxel_stats/mirror.html | 15 +- unravel/voxel_stats/other/IF_outliers.html | 3 +- unravel/voxel_stats/other/r_to_p.html | 17 +- unravel/voxel_stats/other/toc.html | 3 +- unravel/voxel_stats/toc.html | 5 +- unravel/voxel_stats/vstats.html | 55 +- unravel/voxel_stats/vstats_prep.html | 25 +- unravel/voxel_stats/whole_to_LR_avg.html | 23 +- unravel/voxel_stats/z_score.html | 63 +- unravel/warp/points_to_atlas.html | 19 +- unravel/warp/to_atlas.html | 15 +- unravel/warp/to_fixed.html | 17 +- unravel/warp/to_native.html | 27 +- unravel/warp/toc.html | 5 +- unravel/warp/warp.html | 27 +- 210 files changed, 4696 insertions(+), 4782 deletions(-) delete mode 100644 _modules/unravel/core/argparse_utils.html delete mode 100644 _modules/unravel/core/argparse_utils_rich.html create mode 100644 _modules/unravel/core/help_formatter.html delete mode 100644 _sources/unravel/core/argparse_utils.rst.txt delete mode 100644 _sources/unravel/core/argparse_utils_rich.rst.txt create mode 100644 _sources/unravel/core/help_formatter.rst.txt delete mode 100644 unravel/core/argparse_utils_rich.html rename unravel/core/{argparse_utils.html => help_formatter.html} (67%) diff --git a/_modules/index.html b/_modules/index.html index a9215a98..37d9e5f7 100644 --- a/_modules/index.html +++ b/_modules/index.html @@ -370,9 +370,8 @@

All modules for which code is available

  • unravel.cluster_stats.sunburst
  • unravel.cluster_stats.table
  • unravel.cluster_stats.validation
  • -
  • unravel.core.argparse_utils
  • -
  • unravel.core.argparse_utils_rich
  • unravel.core.config
  • +
  • unravel.core.help_formatter
  • unravel.core.img_io
  • unravel.core.img_tools
  • unravel.core.utils
  • diff --git a/_modules/unravel/cluster_stats/brain_model.html b/_modules/unravel/cluster_stats/brain_model.html index ecd53de1..d32c39fc 100644 --- a/_modules/unravel/cluster_stats/brain_model.html +++ b/_modules/unravel/cluster_stats/brain_model.html @@ -352,14 +352,17 @@

    Source code for unravel.cluster_stats.brain_model

    #!/usr/bin/env python3 """ -Use ``cstats_brain_model`` from UNRAVEL to prep .nii.gz and RGBA .txt for vizualization in dsi_studio. -Usage: ------- - cstats_brain_model -i input.nii.gz -sa atlas/atlas_CCFv3_2020_30um_split.nii.gz -m -v +Use ``cstats_brain_model`` from UNRAVEL to prep an img.nii.gz and RGBA.txt LUT for vizualization in dsi_studio. + +Prereqs: + - Use ``cstats_summary`` or ``cstats_index`` to generate a valid cluster index. + +Inputs: + - input.nii.gz (e.g., a valid cluster index, but can be any binary or labeled image) Outputs: - - img_WB.nii.gz (bilateral version of cluster index w/ ABA colors) + - img_ABA.nii.gz (Allen brain atlas labels were applied) or img_ABA_WB.nii.gz if -m was used (WB = Whole Brain) - rgba.txt (RGBA values for each region in the cluster index) Note: @@ -368,10 +371,16 @@

    Source code for unravel.cluster_stats.brain_model

    - CCFv3-2020_regional_summary.csv is in UNRAVEL/unravel/core/csvs/ - It has columns: Region_ID, ID_Path, Region, Abbr, General_Region, R, G, B - Alternatively, use CCFv3-2017_regional_summary.csv or provide a custom CSV with the same columns. - - Use DSI Studio to visualize the cluster index with the RGBA values. + +Next steps: + - Use DSI Studio to visualize img_WB.nii.gz with the RGBA values. + + +Usage: +------ + cstats_brain_model -i input.nii.gz [-m] [-ax 2] [-s 0] [-sa atlas/atlas_CCFv3_2020_30um_split.nii.gz] [-csv CCFv3-2020_regional_summary.csv] [-v] """ -import argparse import nibabel as nib import numpy as np import pandas as pd @@ -379,7 +388,7 @@

    Source code for unravel.cluster_stats.brain_model

    from rich import print from rich.traceback import install -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM from unravel.core.config import Configuration from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg from unravel.voxel_stats.mirror import mirror @@ -388,15 +397,23 @@

    Source code for unravel.cluster_stats.brain_model

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input', help="path/img.nii.gz (e.g., valid cluster index)", required=True, action=SM) - parser.add_argument('-m', '--mirror', help='Mirror the image in the x-axis for a bilateral representation. Default: False', action='store_true', default=False) - parser.add_argument('-ax', '--axis', help='Axis to flip the image along if mirroing. Default: 2', default=2, type=int, action=SM) - parser.add_argument('-s', '--shift', help='Number of voxels to shift content after flipping. Default: 0', default=0, type=int, action=SM) - parser.add_argument('-sa', '--split_atlas', help='path/split_atlas.nii.gz. Default: atlas/atlas_CCFv3_2020_30um_split.nii.gz', default='atlas/atlas_CCFv3_2020_30um_split.nii.gz', action=SM) - parser.add_argument('-csv', '--csv_path', help='CSV name or path/name.csv. Default: CCFv3-2020_regional_summary.csv', default='CCFv3-2020_regional_summary.csv', action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help="path/img.nii.gz (e.g., a valid cluster map)", required=True, action=SM) + + opts_mirror = parser.add_argument_group('Optional args for mirroring the input') + opts_mirror.add_argument('-m', '--mirror', help='Provide flag to mirror the input image for a bilateral representation.', action='store_true', default=False) + opts_mirror.add_argument('-ax', '--axis', help='Axis to flip the image along if mirroing. Default: 2', default=2, type=int, action=SM) + opts_mirror.add_argument('-s', '--shift', help='Number of voxels to shift content after flipping. Default: 0', default=0, type=int, action=SM) + + opts_coloring = parser.add_argument_group('Optional args for region coloring') + opts_coloring.add_argument('-sa', '--split_atlas', help='path/split_atlas.nii.gz. Default: atlas/atlas_CCFv3_2020_30um_split.nii.gz', default='atlas/atlas_CCFv3_2020_30um_split.nii.gz', action=SM) + opts_coloring.add_argument('-csv', '--csv_path', help='CSV name or path/name.csv. Default: CCFv3-2020_regional_summary.csv', default='CCFv3-2020_regional_summary.csv', action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    @@ -454,7 +471,7 @@

    Source code for unravel.cluster_stats.brain_model

    histogram = histogram[1:] # Determine what regions are present based on the histogram - present_regions = np.where(histogram > 0)[0] + 1 # Add 1 to account for the background + present_regions = np.where(histogram > 0)[0] + 1 # Add 1 to account for the background # Get R, G, B values for each region if args.csv_path == 'CCFv3-2017_regional_summary.csv' or args.csv_path == 'CCFv3-2020_regional_summary.csv': diff --git a/_modules/unravel/cluster_stats/crop.html b/_modules/unravel/cluster_stats/crop.html index ff1b3614..1cb7e3d0 100644 --- a/_modules/unravel/cluster_stats/crop.html +++ b/_modules/unravel/cluster_stats/crop.html @@ -354,16 +354,28 @@

    Source code for unravel.cluster_stats.crop

     """
     Use ``cstats_crop`` from UNRAVEL to load image, load bounding box, crop cluster, and save as .nii.gz.
     
    -Usage
    ------
    -    cstats_crop -i path/img.nii.gz -b path/bbox.txt -o path/output_img.nii.gz -a -x $XY -z $Z -v
    +Note:
    +    - -x and -z need to be provided if the resolution is not extracted from the image metadata.
    +    - Use -a, -b, or -c to specify the crop method.
    +
    +Usage with all clusters:
    +------------------------
    +    cstats_crop -i path/img.nii.gz -o path/output_img.nii.gz -a [-x $XY] [-z $Z] [-v]
    +
    +Usage with a bounding box:
    +--------------------------
    +    cstats_crop -i path/img.nii.gz -o path/output_img.nii.gz -b path/bbox.txt [-x $XY] [-z $Z] [-v]
    +    
    +Usage with a cluster ID:
    +------------------------
    +    cstats_crop -i path/img.nii.gz -o path/output_img.nii.gz -c 1 [-x $XY] [-z $Z] [-v]
     """
     
    -import argparse
     from rich.traceback import install
     from rich import print
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
    +
     from unravel.core.config import Configuration
     from unravel.core.img_io import load_3D_img, save_as_nii
     from unravel.core.img_tools import find_bounding_box, cluster_IDs, crop
    @@ -373,16 +385,22 @@ 

    Source code for unravel.cluster_stats.crop

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input', help='path/img.czi, path/img.nii.gz, or path/tif_dir', action=SM) - parser.add_argument('-o', '--output', help='path/output_img.nii.gz', action=SM) - parser.add_argument('-b', '--bbox', help='path/bbox.txt', action=SM) - parser.add_argument('-c', '--cluster', help='Cluster intensity to get bbox and crop', action=SM) - parser.add_argument('-a', '--all_clusters', help='Crop each cluster. Default: False', action='store_true', default=False) - parser.add_argument('-x', '--xy_res', help='xy voxel size in microns for the raw data', type=float, action=SM) - parser.add_argument('-z', '--z_res', help='z voxel size in microns for the raw data', type=float, action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='path/img.czi, path/img.nii.gz, or path/tif_dir', action=SM) + + opts = parser.add_argument_group('Optional args') + opts.add_argument('-o', '--output', help='path/output_img.nii.gz', action=SM) + opts.add_argument('-b', '--bbox', help='path/bbox.txt', action=SM) + opts.add_argument('-c', '--cluster', help='Cluster ID/intensity to get bbox and crop', action=SM) + opts.add_argument('-a', '--all_clusters', help='Crop each cluster. Default: False', action='store_true', default=False) + opts.add_argument('-x', '--xy_res', help='xy voxel size in microns for the raw data', type=float, action=SM) + opts.add_argument('-z', '--z_res', help='z voxel size in microns for the raw data', type=float, action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/cluster_stats/cstats.html b/_modules/unravel/cluster_stats/cstats.html index b495434c..8b929eeb 100644 --- a/_modules/unravel/cluster_stats/cstats.html +++ b/_modules/unravel/cluster_stats/cstats.html @@ -354,13 +354,11 @@

    Source code for unravel.cluster_stats.cstats

    """
     Use ``cstats`` from UNRAVEL to validate clusters based on differences in cell/object or label density w/ t-tests.    
     
    -T-test usage:  
    -------------- 
    -    cstats --groups <group1> <group2> -hg <group1|group2>
    +Input files: 
    +    - `*`_density_data.csv from ``cstats_validation`` (e.g., in each subdir named after the rev_cluster_index.nii.gz file)
     
    -Tukey's test usage: 
    --------------------
    -    cstats --groups <group1> <group2> <group3> <group4> ... -hg <group1|group2>
    +Outputs:
    +    - ./_valid_clusters_stats/
     
     Note: 
         - Organize data in directories for each comparison (e.g., psilocybin > saline, etc.)
    @@ -369,9 +367,6 @@ 

    Source code for unravel.cluster_stats.cstats

        - The first 2 groups reflect the main comparison for validation rates.
         - Clusters are not considered valid if the effect direction does not match the expected direction.
     
    -Input files: 
    -    <asterisk>_density_data.csv from ``cstats_validation`` (e.g., in each subdir named after the rev_cluster_index.nii.gz file)    
    -
     CSV naming conventions:
         - Condition: first word before '_' in the file name
         - Side: last word before .csv (LH or RH)
    @@ -395,11 +390,15 @@ 

    Source code for unravel.cluster_stats.cstats

    Columns in the .csv files:
         sample, cluster_ID, <cell_count|label_volume>, cluster_volume, <cell_density|label_density>, ...
     
    -Outputs:
    -    - ./_valid_clusters_stats/
    +Usage for t-tests:
    +------------------
    +    cstats --groups <group1> <group2> -hg <group1|group2> [-cp <condition_prefixes>] [-alt <two-sided|less|greater>] [-pvt <p_value_threshold.txt>] [-v]
    +
    +Usage for Tukey's tests:
    +------------------------
    +    cstats --groups <group1> <group2> <group3> <group4> ... -hg <group1|group2> [-cp <condition_prefixes>] [-alt <two-sided|less|greater>] [-pvt <p_value_threshold.txt>] [-v]
     """
     
    -import argparse
     import numpy as np
     import pandas as pd
     from glob import glob
    @@ -410,7 +409,8 @@ 

    Source code for unravel.cluster_stats.cstats

    from scipy.stats import ttest_ind
     from statsmodels.stats.multicomp import pairwise_tukeyhsd
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
    +
     from unravel.core.config import Configuration
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, initialize_progress_bar
     
    @@ -419,14 +419,20 @@ 

    Source code for unravel.cluster_stats.cstats

     [docs]
     def parse_args():
    -    parser = argparse.ArgumentParser(formatter_class=SuppressMetavar)
    -    parser.add_argument('--groups', help='List of group prefixes. 2 groups --> t-test. >2 --> Tukey\'s tests (The first 2 groups reflect the main comparison for validation rates)', nargs='*', required=True, action=SM)
    -    parser.add_argument('-cp', '--condition_prefixes', help='Condition prefixes to group data (e.g., see info for examples)',  nargs='*', default=None, action=SM)
    -    parser.add_argument('-hg', '--higher_group', help='Specify the group that is expected to have a higher mean based on the direction of the p value map', required=True)
    -    parser.add_argument('-alt', "--alternate", help="Number of tails and direction ('two-sided' [default], 'less' [group1 < group2], or 'greater')", default='two-sided', action=SM)
    -    parser.add_argument('-pvt', '--p_val_txt', help='Name of the file w/ the corrected p value thresh (e.g., from cstats_fdr). Default: p_value_threshold.txt', default='p_value_threshold.txt', action=SM)
    -    parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False)
    -    parser.epilog = __doc__
    +    parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__)
    +
    +    reqs = parser.add_argument_group('Required arguments')
    +    reqs.add_argument('--groups', help='List of group prefixes. 2 groups --> t-test. >2 --> Tukey\'s tests (The first 2 groups reflect the main comparison for validation rates)', nargs='*', required=True, action=SM)
    +    reqs.add_argument('-hg', '--higher_group', help='Specify the group that is expected to have a higher mean based on the direction of the p value map', required=True)
    +
    +    opts = parser.add_argument_group('Optional args')
    +    opts.add_argument('-cp', '--condition_prefixes', help='Condition prefixes to group data (e.g., see info for examples)',  nargs='*', default=None, action=SM)
    +    opts.add_argument('-alt', "--alternate", help="Number of tails and direction ('two-sided' [default], 'less' [group1 < group2], or 'greater')", default='two-sided', action=SM)
    +    opts.add_argument('-pvt', '--p_val_txt', help='Name of the file w/ the corrected p value thresh (e.g., from cstats_fdr). Default: p_value_threshold.txt', default='p_value_threshold.txt', action=SM)
    +
    +    general = parser.add_argument_group('General arguments')
    +    general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False)
    +
         return parser.parse_args()
    diff --git a/_modules/unravel/cluster_stats/effect_sizes/effect_sizes.html b/_modules/unravel/cluster_stats/effect_sizes/effect_sizes.html index 862fb40a..b7ca8ba3 100644 --- a/_modules/unravel/cluster_stats/effect_sizes/effect_sizes.html +++ b/_modules/unravel/cluster_stats/effect_sizes/effect_sizes.html @@ -354,38 +354,38 @@

    Source code for unravel.cluster_stats.effect_sizes.effect_sizes

    """ Use ``effect_sizes`` from UNRAVEL to calculate the effect size for a comparison between two groups for each cluster [or a valid cluster list]. -Usage ------ - effect_sizes -i densities.csv -c1 saline -c2 psilocybin +Prereqs: + - ``cstats_validation`` to generate the input CSVs with densities. Inputs: - - CSV with densities (Columns: Samples, Conditions, Cluster_1, Cluster_2, ...) - -Arguments: - - -c1 and -c2 should match the condition name in the Conditions column of the input CSV or be a prefix of the condition name. + - CSV with densities (Columns: Samples, Sex, Conditions, Cluster_1, Cluster_2, ...) -Outputs CSV w/ the effect size and CI for each cluster: - <input>_Hedges_g_<condition_1>_<condition_2>.csv +Outputs: + - CSV w/ absolute effect sizes and upper and lower limits of the confidence interval (CI) for each cluster + - <input>_Hedges_g_<condition_1>_<condition_2>.csv -If -c is used, outputs a CSV with the effect sizes and CI for valid clusters: - <input>_Hedges_g_<condition_1>_<condition_2>_valid_clusters.csv - -The effect size is calculated as the unbiased Hedge\'s g effect sizes (corrected for sample size): - Hedges' g = ((c2-c1)/spooled*corr_factor) - CI = Hedges' g +/- t * SE - 0.2 - 0.5 = small effect; 0.5 - 0.8 = medium; 0.8+ = large +Note: + - -c1 and -c2 should match the condition name in the Conditions column of the input CSV or be a prefix of the condition name. + - The effect size is calculated as the unbiased Hedge\'s g effect sizes (corrected for sample size). + - Hedges' g = ((c2-c1)/spooled*corr_factor) + - CI = Hedges' g +/- t * SE + - 0.2-0.5 = small effect; 0.5-0.8 = medium; 0.8+ = large + - The CI is based on a two-tailed t-test with alpha = 0.05. + - More more info, see: https://pubmed.ncbi.nlm.nih.gov/37248402/ -Effect size calculations are described in the supplemental information here: https://pubmed.ncbi.nlm.nih.gov/37248402/ +Usage +----- + effect_sizes -i densities.csv -c1 saline -c2 psilocybin [-c 1 2 3 4 5] [-v] """ -import argparse import os import pandas as pd from rich.traceback import install from scipy.stats import t from termcolor import colored -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg @@ -393,16 +393,23 @@

    Source code for unravel.cluster_stats.effect_sizes.effect_sizes

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input_csv', help='CSV with densities (Columns: Samples, Conditions, Cluster_1, Cluster_2, ...)', action=SM) - parser.add_argument('-c1', '--condition_1', help='First condition of interest from csv (e.g., saline [data matching prefix pooled])', action=SM) - parser.add_argument('-c2', '--condition_2', help='Second condition (e.g, psilocybin [data matching prefix pooled])', action=SM) - parser.add_argument('-c', '--clusters', help='Space separated list of valid cluster IDs (default: process all clusters)', default=None, nargs='*', type=int, action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input_csv', help='CSV with densities (Columns: Samples, Conditions, Cluster_1, Cluster_2, ...)', required=True, action=SM) + reqs.add_argument('-c1', '--condition_1', help='First condition of interest from csv (e.g., saline [data matching prefix pooled])', required=True, action=SM) + reqs.add_argument('-c2', '--condition_2', help='Second condition (e.g, psilocybin [data matching prefix pooled])', required=True, action=SM) + + opts = parser.add_argument_group('Optional args') + opts.add_argument('-c', '--clusters', help='Space separated list of valid cluster IDs (default: process all clusters)', default=None, nargs='*', type=int, action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    +# TODO: explain in the help how the input CSVs are prepared. # Create a condition selector to handle pooling of data
    diff --git a/_modules/unravel/cluster_stats/effect_sizes/effect_sizes_by_sex__absolute.html b/_modules/unravel/cluster_stats/effect_sizes/effect_sizes_by_sex__absolute.html index 24951c11..e5dec87a 100644 --- a/_modules/unravel/cluster_stats/effect_sizes/effect_sizes_by_sex__absolute.html +++ b/_modules/unravel/cluster_stats/effect_sizes/effect_sizes_by_sex__absolute.html @@ -353,54 +353,62 @@

    Source code for unravel.cluster_stats.effect_sizes.effect_sizes_by_sex__abso """ Use ``effect_sizes_sex_abs`` from UNRAVEL to calculate the effect size for a comparison between two groups for each cluster [or a valid cluster list]. - -Usage: - effect_sizes_sex_abs -i densities.csv -c1 saline -c2 psilocybin + +Prereqs: + - ``cstats_validation`` to generate the input CSVs with densities. Inputs: - CSV with densities (Columns: Samples, Sex, Conditions, Cluster_1, Cluster_2, ...) - Enter M or F in the Sex column. -Arguments: - - -c1 and -c2 should match the condition name in the Conditions column of the input CSV or be a prefix of the condition name. +Outputs: + - CSV w/ absolute effect sizes and upper and lower limits of the confidence interval (CI) for each cluster + - <input>_Hedges_g_<condition_1>_<condition_2>_<M/F>.csv for males and females -Outputs CSV w/ the effect size and CI for each cluster: - <input>_Hedges_g_<condition_1>_<condition_2>.csv - -If -c is used, outputs a CSV with the effect sizes and CI for valid clusters: - <input>_Hedges_g_<condition_1>_<condition_2>_valid_clusters.csv +Note: + - -c1 and -c2 should match the condition name in the Conditions column of the input CSV or be a prefix of the condition name. + - The effect size is calculated as the unbiased Hedge\'s g effect sizes (corrected for sample size). + - Hedges' g = ((c2-c1)/spooled*corr_factor) + - CI = Hedges' g +/- t * SE + - 0.2-0.5 = small effect; 0.5-0.8 = medium; 0.8+ = large + - The CI is based on a two-tailed t-test with alpha = 0.05. + - More more info, see: https://pubmed.ncbi.nlm.nih.gov/37248402/ -The effect size is calculated as the unbiased Hedge\'s g effect sizes (corrected for sample size): - Hedges' g = ((c2-c1)/spooled*corr_factor) - CI = Hedges' g +/- t * SE - 0.2 - 0.5 = small effect; 0.5 - 0.8 = medium; 0.8+ = large +Usage: + effect_sizes_sex_abs -i densities.csv -c1 saline -c2 psilocybin [-c 1 2 3 4 5] [-v] """ -import argparse import os import pandas as pd from rich.traceback import install from scipy.stats import t from termcolor import colored -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg -
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input_csv', help='CSV with densities (Columns: Samples, Sex, Conditions, Cluster_1, Cluster_2, ...)', action=SM) - parser.add_argument('-c1', '--condition_1', help='First condition of interest from csv (e.g., saline [data matching prefix pooled])', action=SM) - parser.add_argument('-c2', '--condition_2', help='Second condition (e.g, psilocybin [data matching prefix pooled])', action=SM) - parser.add_argument('-c', '--clusters', help='Space separated list of valid cluster IDs (default: process all clusters)', default=None, nargs='*', type=int, action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input_csv', help='CSV with densities (Columns: Samples, Sex, Conditions, Cluster_1, Cluster_2, ...)', required=True, action=SM) + reqs.add_argument('-c1', '--condition_1', help='First condition of interest from csv (e.g., saline [data matching prefix pooled])', required=True, action=SM) + reqs.add_argument('-c2', '--condition_2', help='Second condition (e.g, psilocybin [data matching prefix pooled])', required=True, action=SM) + + opts = parser.add_argument_group('Optional args') + opts.add_argument('-c', '--clusters', help='Space separated list of valid cluster IDs (default: process all clusters)', default=None, nargs='*', type=int, action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    +# TODO: explain in the help how the input CSVs are prepared.
    [docs] diff --git a/_modules/unravel/cluster_stats/effect_sizes/effect_sizes_by_sex__relative.html b/_modules/unravel/cluster_stats/effect_sizes/effect_sizes_by_sex__relative.html index 0a56d497..03d40576 100644 --- a/_modules/unravel/cluster_stats/effect_sizes/effect_sizes_by_sex__relative.html +++ b/_modules/unravel/cluster_stats/effect_sizes/effect_sizes_by_sex__relative.html @@ -353,38 +353,40 @@

    Source code for unravel.cluster_stats.effect_sizes.effect_sizes_by_sex__rela """ Use ``effect_sizes_sex_rel`` from UNRAVEL to calculate the relative effect size for (comparing sexes) for a comparison between two groups for each cluster [or a valid cluster list]. - -Usage ------ - effect_sizes_sex_rel -i densities.csv -c1 saline -c2 psilocybin + +Prereqs: + - ``cstats_validation`` to generate the input CSVs with densities. Inputs: - CSV with densities (Columns: Samples, Sex, Conditions, Cluster_1, Cluster_2, ...) - Enter M or F in the Sex column. -Arguments: - - -c1 and -c2 should match the condition name in the Conditions column of the input CSV or be a prefix of the condition name. - -Outputs CSV w/ the relative effect size (F>M) and CI for each cluster: - <input>_Hedges_g_<condition_1>_<condition_2>_F_gt_M.csv +Outputs: + - CSV w/ relative effect sizes and upper and lower limits of the confidence interval (CI) for each cluster + - <input>_Hedges_g_<condition_1>_<condition_2>_F_gt_M.csv (F > M) -If -c is used, outputs a CSV with the effect sizes and CI for valid clusters: - <input>_Hedges_g_<condition_1>_<condition_2>_F_gt_M_valid_clusters.csv +Note: + - -c1 and -c2 should match the condition name in the Conditions column of the input CSV or be a prefix of the condition name. + - The effect size is calculated as the unbiased Hedge\'s g effect sizes (corrected for sample size). + - Hedges' g = ((c2-c1)/spooled*corr_factor) + - CI = Hedges' g +/- t * SE + - 0.2-0.5 = small effect; 0.5-0.8 = medium; 0.8+ = large + - The CI is based on a two-tailed t-test with alpha = 0.05. + - More more info, see: https://pubmed.ncbi.nlm.nih.gov/37248402/ -The effect size is calculated as the unbiased Hedge\'s g effect sizes (corrected for sample size): - Hedges' g = ((c2-c1)/spooled*corr_factor) - CI = Hedges' g +/- t * SE - 0.2 - 0.5 = small effect; 0.5 - 0.8 = medium; 0.8+ = large +Usage +----- + effect_sizes_sex_rel -i densities.csv -c1 saline -c2 psilocybin [-c 1 2 3 4 5] [-v] """ -import argparse import os import pandas as pd from rich.traceback import install from scipy.stats import t from termcolor import colored -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg @@ -392,16 +394,23 @@

    Source code for unravel.cluster_stats.effect_sizes.effect_sizes_by_sex__rela
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input_csv', help='CSV with densities (Columns: Samples, Sex, Conditions, Cluster_1, Cluster_2, ...)', action=SM) - parser.add_argument('-c1', '--condition_1', help='First condition of interest from csv (e.g., saline [data matching prefix pooled])', action=SM) - parser.add_argument('-c2', '--condition_2', help='Second condition (e.g, psilocybin [data matching prefix pooled])', action=SM) - parser.add_argument('-c', '--clusters', help='Space separated list of valid cluster IDs (default: process all clusters)', default=None, nargs='*', type=int, action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input_csv', help='CSV with densities (Columns: Samples, Sex, Conditions, Cluster_1, Cluster_2, ...)', required=True, action=SM) + reqs.add_argument('-c1', '--condition_1', help='First condition of interest from csv (e.g., saline [data matching prefix pooled])', required=True, action=SM) + reqs.add_argument('-c2', '--condition_2', help='Second condition (e.g, psilocybin [data matching prefix pooled])', required=True, action=SM) + + opts = parser.add_argument_group('Optional args') + opts.add_argument('-c', '--clusters', help='Space separated list of valid cluster IDs (default: process all clusters)', default=None, nargs='*', type=int, action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    +# TODO: explain in the help how the input CSVs are prepared.
    [docs] diff --git a/_modules/unravel/cluster_stats/fdr.html b/_modules/unravel/cluster_stats/fdr.html index 1c156c05..d021be6c 100644 --- a/_modules/unravel/cluster_stats/fdr.html +++ b/_modules/unravel/cluster_stats/fdr.html @@ -354,12 +354,8 @@

    Source code for unravel.cluster_stats.fdr

     """
     Use ``cstats_fdr`` from UNRAVEL to perform FDR correction on a 1 - p value map to define clusters.
     
    -Usage
    ------
    -    cstats_fdr -i path/vox_p_tstat1.nii.gz -mas path/mask.nii.gz -q 0.05
    -
     Inputs: 
    -    - p value map (e.g., <asterisk>vox_p_<asterisk>stat<asterisk>.nii.gz from vstats)    
    +    - p value map (e.g., `*`vox_p_`*`stat`*`.nii.gz from vstats)    
     
     Outputs saved in the output directory:
         - FDR-adjusted p value map
    @@ -369,7 +365,10 @@ 

    Source code for unravel.cluster_stats.fdr

         - p_value_threshold.txt
         - 1-p_value_threshold.txt
     
    -Cluster IDs are reversed in the cluster index image so that the largest cluster is 1, the second largest is 2, etc.
    +Note:
    +    - Cluster IDs are reversed in the cluster index image so that the largest cluster is 1, the second largest is 2, etc.
    +    - For bilateral data processed with a hemispheric mask, next run ``cstats_mirror_indices`` to mirror the cluster indices to the other hemisphere.
    +    - For unilateral data or bilateral data processed with a whole brain mask, the cluster indices are ready for validation with ``cstats_validation``.
     
     Making directional cluster indices from non-directional p value maps output from ANOVAs: 
         - Provide the average immunostaining intensity images for each group being contrasted (``img_avg``)
    @@ -378,12 +377,11 @@ 

    Source code for unravel.cluster_stats.fdr

         - The cluster index will be split accoding to the effect directions
         - ``cstats_fdr`` -i vox_p_fstat1.nii.gz -mas mask.nii.gz -q 0.05 -a1 group1_avg.nii.gz -a2 group2_avg.nii.gz -o stats_info_g1_v_g2 -v
     
    -For bilateral data processed with a hemispheric mask, next run ``cstats_mirror_indices`` to mirror the cluster indices to the other hemisphere.
    -
    -For unilateral data or bilateral data processed with a whole brain mask, the cluster indices are ready for validation with ``cstats_validation``.
    +Usage
    +-----
    +    cstats_fdr -i path/vox_p_tstat1.nii.gz -mas path/mask.nii.gz -q 0.05 0.01 0.001 [-ms 100] [-o output_dir] [-a1 path/avg_img1.nii.gz] [-a2 path/avg_img2.nii.gz] [-th 10] [-v]
     """
     
    -import argparse
     import concurrent.futures
     import subprocess
     import numpy as np
    @@ -393,7 +391,7 @@ 

    Source code for unravel.cluster_stats.fdr

     from rich import print
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SM, SuppressMetavar
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
     from unravel.core.config import Configuration
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, print_func_name_args_times
     
    @@ -401,17 +399,23 @@ 

    Source code for unravel.cluster_stats.fdr

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input', help='path/p_value_map.nii.gz', required=True, action=SM) - parser.add_argument('-mas', '--mask', help='path/mask.nii.gz', required=True, action=SM) - parser.add_argument('-q', '--q_value', help='Space-separated list of FDR q values', required=True, nargs='*', type=float, action=SM) - parser.add_argument('-ms', '--min_size', help='Min cluster size in voxels. Default: 100', default=100, type=int, action=SM) - parser.add_argument('-o', '--output', help='Output directory. Default: input_name_q{args.q_value}"', default=None, action=SM) - parser.add_argument('-a1', '--avg_img1', help='path/averaged_immunofluo_group1.nii.gz for spliting the cluster index based on effect direction', action=SM) - parser.add_argument('-a2', '--avg_img2', help='path/averaged_immunofluo_group2.nii.gz for spliting the cluster index based on effect direction', action=SM) - parser.add_argument('-th', '--threads', help='Number of threads. Default: 10', default=10, type=int, action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity', default=False, action='store_true') - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='path/p_value_map.nii.gz', required=True, action=SM) + reqs.add_argument('-mas', '--mask', help='path/mask.nii.gz', required=True, action=SM) + reqs.add_argument('-q', '--q_value', help='Space-separated list of FDR q values', required=True, nargs='*', type=float, action=SM) + + opts = parser.add_argument_group('Optional args') + opts.add_argument('-ms', '--min_size', help='Min cluster size in voxels. Default: 100', default=100, type=int, action=SM) + opts.add_argument('-o', '--output', help='Output directory. Default: input_name_q{args.q_value}"', default=None, action=SM) + opts.add_argument('-a1', '--avg_img1', help='path/averaged_immunofluo_group1.nii.gz for spliting the cluster index based on effect direction', action=SM) + opts.add_argument('-a2', '--avg_img2', help='path/averaged_immunofluo_group2.nii.gz for spliting the cluster index based on effect direction', action=SM) + opts.add_argument('-th', '--threads', help='Number of threads. Default: 10', default=10, type=int, action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', default=False, action='store_true') + return parser.parse_args()
    diff --git a/_modules/unravel/cluster_stats/fdr_range.html b/_modules/unravel/cluster_stats/fdr_range.html index 5c62bed2..ad65e6f4 100644 --- a/_modules/unravel/cluster_stats/fdr_range.html +++ b/_modules/unravel/cluster_stats/fdr_range.html @@ -354,21 +354,20 @@

    Source code for unravel.cluster_stats.fdr_range

    < """ Use ``cstats_fdr_range`` from UNRAVEL to output a list of FDR q values that yeild clusters. -Usage ------ - cstats_fdr_range -i path/vox_p_tstat1.nii.gz -mas path/mask.nii.gz - Inputs: - - p value map (e.g., *vox_p_*stat*.nii.gz from vstats) + - p value map (e.g., *vox_p_*stat*.nii.gz from vstats) + +Usage: +------ + cstats_fdr_range -i path/vox_p_tstat1.nii.gz -mas path/mask.nii.gz [-q 0.00001 0.00005 0.0001 0.0005 0.001 0.005 0.01 0.05 0.1 0.15 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 0.95 0.99 0.999 0.9999] [-th 22] [-v] """ -import argparse import concurrent.futures import subprocess from rich import print from rich.traceback import install -from unravel.core.argparse_utils import SM, SuppressMetavar +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM from unravel.core.config import Configuration from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg @@ -376,14 +375,21 @@

    Source code for unravel.cluster_stats.fdr_range

    <
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + q_values_default = [0.00001, 0.00005, 0.0001, 0.0005, 0.001, 0.005, 0.01, 0.05, 0.1, 0.15, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.95, 0.99, 0.999, 0.9999] - parser.add_argument('-i', '--input', help='path/p_value_map.nii.gz', required=True, action=SM) - parser.add_argument('-mas', '--mask', help='path/mask.nii.gz', required=True, action=SM) - parser.add_argument('-q', '--q_values', help='Space-separated list of q values. If omitted, a default list is used.', nargs='*', default=q_values_default, type=float, action=SM) - parser.add_argument('-th', '--threads', help='Number of threads. Default: 22', default=22, type=int, action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='path/p_value_map.nii.gz', required=True, action=SM) + reqs.add_argument('-mas', '--mask', help='path/mask.nii.gz', required=True, action=SM) + + opts = parser.add_argument_group('Optional args') + opts.add_argument('-q', '--q_values', help='Space-separated list of q values. Default: a list from 0.00001 to 0.9999 is used.', nargs='*', default=q_values_default, type=float, action=SM) + opts.add_argument('-th', '--threads', help='Number of threads. Default: 22', default=22, type=int, action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/cluster_stats/find_incongruent_clusters.html b/_modules/unravel/cluster_stats/find_incongruent_clusters.html index 127b4cf9..33bd6017 100644 --- a/_modules/unravel/cluster_stats/find_incongruent_clusters.html +++ b/_modules/unravel/cluster_stats/find_incongruent_clusters.html @@ -354,33 +354,31 @@

    Source code for unravel.cluster_stats.find_incongruent_clusters

    """ Use ``cstats_find_incongruent`` from UNRAVEL if ``cstats_fdr`` was used to convert non-directional p value maps into directional cluster indices. This helps to find clusters where the direction of the mean intensity difference between groups does not match direction of the difference in cell/label density between groups. -Usage ------ - cstats_find_incongruent -c tukey_results.csv -l groupA -g groupB - -This is useful to find clusters where z-scoring introduces incongruencies between the mean intensity difference and the density difference. - -For example, if group A has increased IF in region A and not B, z-scoring may decrease the relative intensity of region B. -This decrease for region B for one group, may introduce a difference in the mean intensity between groups that is not reflected in the density difference. +Input: + - ./_cluster_validation_info/tukey_results.csv or ttest_results.csv from ``cstats`` + - Columns: 'cluster_ID', 'comparison', 'higher_mean_group', 'p-value', 'significance' -Input csv: - ./_cluster_validation_info/tukey_results.csv or ttest_results.csv from ``cstats`` +Output: + - Cluster IDs where the mean intensity difference does not match the density difference between groups A and B. -Columns: - 'cluster_ID', 'comparison', 'higher_mean_group', 'p-value', 'significance' +Note: + - This is modules is useful to find clusters where z-scoring introduces incongruencies between the mean intensity difference and the density difference. + - For example, if group A has increased IF in region A and not B, z-scoring may decrease the relative intensity of region B. + - This decrease for region B for one group, may introduce a difference in the mean intensity between groups that is not reflected in the density difference. -Output: - Cluster IDs where the mean intensity difference does not match the density difference between groups A and B. +Usage: +------ + cstats_find_incongruent -c tukey_results.csv -l groupA -g groupB [-v] """ -import argparse from pathlib import Path import pandas as pd from glob import glob from rich import print from rich.traceback import install -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg @@ -388,12 +386,16 @@

    Source code for unravel.cluster_stats.find_incongruent_clusters

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-c', '--csv_name', help='Name of the CSV file.', required=True, action=SM) - parser.add_argument('-l', '--lesser_group', help='Group with a lower mean for the comparison of interest.', required=True, action=SM) - parser.add_argument('-g', '--greater_group', help='Group with a higher mean for the comparison of interest.', required=True, action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-c', '--csv_name', help='Name of the CSV file.', required=True, action=SM) + reqs.add_argument('-l', '--lesser_group', help='Group with a lower mean for the comparison of interest.', required=True, action=SM) + reqs.add_argument('-g', '--greater_group', help='Group with a higher mean for the comparison of interest.', required=True, action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/cluster_stats/group_bilateral_data.html b/_modules/unravel/cluster_stats/group_bilateral_data.html index bce76159..f4028a2c 100644 --- a/_modules/unravel/cluster_stats/group_bilateral_data.html +++ b/_modules/unravel/cluster_stats/group_bilateral_data.html @@ -354,17 +354,13 @@

    Source code for unravel.cluster_stats.group_bilateral_data

    """ Use ``cstats_group_data`` from UNRAVEL to organize bilateral csv outputs from ``cstats_validation`` -Run this command in the target_dir from ``cstats_org_data`` - -Usage ------ - cstats_group_data +Note: + - Run this command in the target_dir from ``cstats_org_data`` + - It consolidates CSV files into pooled directories based on hemisphere. -It consolidates CSV files into pooled directories based on hemisphere. - -Folder naming convention: - - <cluster_validation_dir>_LH for left hemisphere files - - <cluster_validation_dir>_RH for right hemisphere files +Input folder naming convention: + - <cluster_validation_dir>_LH for left hemisphere folders + - <cluster_validation_dir>_RH for right hemisphere folders For example, if the command is run in a directory containing the following directories: - cluster_valid_results_1_LH @@ -372,20 +368,22 @@

    Source code for unravel.cluster_stats.group_bilateral_data

    - cluster_valid_results_2_LH - cluster_valid_results_2_RH -The command will create a new directory for each cluster and move the corresponding left and right hemisphere files into it. -The original directories will be removed. - -The resulting directory structure will be: +Output directory structure: - cluster_valid_results_1 - cluster_valid_results_2 + - These directories will contain the left and right hemisphere files from the original directories. + - The original directories will be removed. + +Usage: +------ + cstats_group_data [-v] """ -import argparse import shutil from pathlib import Path from rich.traceback import install -from unravel.core.argparse_utils import SuppressMetavar +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM from unravel.core.config import Configuration from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, print_func_name_args_times @@ -393,9 +391,11 @@

    Source code for unravel.cluster_stats.group_bilateral_data

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/cluster_stats/index.html b/_modules/unravel/cluster_stats/index.html index f7a9885a..78d541a6 100644 --- a/_modules/unravel/cluster_stats/index.html +++ b/_modules/unravel/cluster_stats/index.html @@ -354,29 +354,28 @@

    Source code for unravel.cluster_stats.index

     """
     Use ``cstats_index`` from UNRAVEL to create a cluster index with valid clusters from a given NIfTI image.
     
    -Usage
    ------
    -    cstats_index -ci path/rev_cluster_index.nii.gz -a path/atlas.nii.gz -ids 1 2 3
    -    
     Outputs:
         - path/valid_clusters/rev_cluster_index_valid_clusters.nii.gz
    -    - path/valid_clusters/cluster_<asterisk>_sunburst.csv
    +    - path/valid_clusters/cluster_``*``_sunburst.csv
     
     Note:
         - Default csv: UNRAVEL/unravel/core/csvs/sunburst_IDPath_Abbrv.csv
         - CCFv3-2020_info.csv or CCFv3-2017_info.csv
    +
    +Usage
    +-----
    +    cstats_index -ci path/rev_cluster_index.nii.gz -ids 1 2 3 [-a atlas/atlas_CCFv3_2020_30um.nii.gz] [-vcd valid_clusters_dir] [-rgb] [-scsv sunburst_IDPath_Abbrv.csv] [-in CCFv3-2020_info.csv] [-v]
     """
     
     from pathlib import Path
     import nibabel as nib
     import numpy as np
    -import argparse
     from concurrent.futures import ThreadPoolExecutor
     from rich import print
     from rich.traceback import install
     
     from unravel.cluster_stats.sunburst import sunburst
    -from unravel.core.argparse_utils import SM, SuppressMetavar
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
     from unravel.core.config import Configuration
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg
     
    @@ -384,16 +383,22 @@ 

    Source code for unravel.cluster_stats.index

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-ci', '--cluster_idx', help='Path to the reverse cluster index NIfTI file.', required=True, action=SM) - parser.add_argument('-ids', '--valid_cluster_ids', help='Space-separated list of valid cluster IDs.', nargs='*', type=int, required=True, action=SM) - parser.add_argument('-vcd', '--valid_clusters_dir', help='path/name_of_the_output_directory. Default: valid_clusters', default='_valid_clusters', action=SM) - parser.add_argument('-a', '--atlas', help='path/atlas.nii.gz (Default: atlas/atlas_CCFv3_2020_30um.nii.gz)', default='atlas/atlas_CCFv3_2020_30um.nii.gz', action=SM) - parser.add_argument('-rgb', '--output_rgb_lut', help='Output sunburst_RGBs.csv if flag provided (for Allen brain atlas coloring)', action='store_true') - parser.add_argument('-scsv', '--sunburst_csv', help='CSV name or path/name.csv. Default: sunburst_IDPath_Abbrv.csv', default='sunburst_IDPath_Abbrv.csv', action=SM) - parser.add_argument('-in', '--info', help='CSV name or path/name.csv. Default: CCFv3-2020_info.csv', default='CCFv3-2020_info.csv', action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-ci', '--cluster_idx', help='Path to the reverse cluster index NIfTI file.', required=True, action=SM) + reqs.add_argument('-ids', '--valid_cluster_ids', help='Space-separated list of valid cluster IDs.', nargs='*', type=int, required=True, action=SM) + + opts = parser.add_argument_group('Optional args') + opts.add_argument('-vcd', '--valid_clusters_dir', help='path/name_of_the_output_directory. Default: valid_clusters', default='_valid_clusters', action=SM) + opts.add_argument('-a', '--atlas', help='path/atlas.nii.gz. Default: atlas/atlas_CCFv3_2020_30um.nii.gz', default='atlas/atlas_CCFv3_2020_30um.nii.gz', action=SM) + opts.add_argument('-rgb', '--output_rgb_lut', help='Output sunburst_RGBs.csv if flag provided (for Allen brain atlas coloring)', action='store_true') + opts.add_argument('-scsv', '--sunburst_csv', help='CSV name or path/name.csv. Default: sunburst_IDPath_Abbrv.csv', default='sunburst_IDPath_Abbrv.csv', action=SM) + opts.add_argument('-in', '--info', help='CSV name or path/name.csv. Default: CCFv3-2020_info.csv', default='CCFv3-2020_info.csv', action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/cluster_stats/legend.html b/_modules/unravel/cluster_stats/legend.html index 28973c30..2740d334 100644 --- a/_modules/unravel/cluster_stats/legend.html +++ b/_modules/unravel/cluster_stats/legend.html @@ -352,25 +352,24 @@

    Source code for unravel.cluster_stats.legend

    #!/usr/bin/env python3
     
     """
    -Use ``cstats_legend`` from UNRAVEL to summarize regional abbreviations from <asterisk>_valid_clusters_table.xlsx files.
    -
    -Usage:
    -------
    -    cstats_legend
    +Use ``cstats_legend`` from UNRAVEL to summarize regional abbreviations from _valid_clusters_table.xlsx files.
     
     Inputs:
    -    <asterisk>_valid_clusters_table.xlsx files in the working directory output from ``cstats_table``
    +    - <asterisk>_valid_clusters_table.xlsx files in the working directory output from ``cstats_table``
     
     Outputs:
    -    legend.xlsx
    +    - legend.xlsx
     
     Note: 
         - CCFv3-2020_info.csv is in UNRAVEL/unravel/core/csvs/
         - It has columns: structure_id_path,very_general_region,collapsed_region_name,abbreviation,collapsed_region,other_abbreviation,other_abbreviation_defined,layer,sunburst
         - Alternatively, use CCFv3-2017_info.csv or provide a custom CSV with the same columns.
    +
    +Usage:
    +------
    +    cstats_legend [-p path/dir/with/xlsx_files] [-csv CCFv3-2020_info.csv] [-v]
     """
     
    -import argparse
     from glob import glob
     from pathlib import Path
     import openpyxl
    @@ -382,7 +381,8 @@ 

    Source code for unravel.cluster_stats.legend

    from openpyxl.styles import Border, Side, Font
     from openpyxl.styles import Alignment
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
    +
     from unravel.core.config import Configuration
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg
     
    @@ -390,11 +390,15 @@ 

    Source code for unravel.cluster_stats.legend

     [docs]
     def parse_args():
    -    parser = argparse.ArgumentParser(formatter_class=SuppressMetavar)
    -    parser.add_argument('-p', '--path', help='Path to the directory containing the *_valid_clusters_table.xlsx files. Default: current working directory', action=SM)
    -    parser.add_argument('-csv', '--csv_path', help='CSV name or path/name.csv. Default: CCFv3-2020_info.csv', default='CCFv3-2020_info.csv', action=SM)
    -    parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False)
    -    parser.epilog = __doc__
    +    parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__)
    +
    +    opts = parser.add_argument_group('Optional args')
    +    opts.add_argument('-p', '--path', help='Path to the directory containing the *_valid_clusters_table.xlsx files. Default: current working directory', action=SM)
    +    opts.add_argument('-csv', '--csv_path', help='CSV name or path/name.csv. Default: CCFv3-2020_info.csv', default='CCFv3-2020_info.csv', action=SM)
    +
    +    general = parser.add_argument_group('General arguments')
    +    general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False)
    +
         return parser.parse_args()
    diff --git a/_modules/unravel/cluster_stats/mean_IF.html b/_modules/unravel/cluster_stats/mean_IF.html index 3cac69eb..c237ba2d 100644 --- a/_modules/unravel/cluster_stats/mean_IF.html +++ b/_modules/unravel/cluster_stats/mean_IF.html @@ -354,10 +354,6 @@

    Source code for unravel.cluster_stats.mean_IF

    """ Use ``cstats_mean_IF`` from UNRAVEL to measure mean intensity of immunofluorescence staining in clusters. -Usage: ------- - cstats_mean_IF -ci path/rev_cluster_index.nii.gz - Prereqs: - vstats - cstats_fdr @@ -369,22 +365,26 @@

    Source code for unravel.cluster_stats.mean_IF

    - ./cluster_mean_IF_{cluster_index}/image_name.csv for each image - Columns: sample, cluster_ID, mean_IF_intensity -Next: +Next steps: - cd cluster_mean_IF... - utils_prepend -sk <path/sample_key.csv> -f # If needed - [``cstats_index`` and ``cstats_table``] # for an xlsx table and anatomically ordered clusters that can be used with ``cstats_prism`` - cstats_mean_IF_summary --order Control Treatment --labels Control Treatment -t ttest # Plots each cluster and outputs a summary table w/ stats - cstats_mean_IF_summary --order group3 group2 group1 --labels Group_3 Group_2 Group_1 # Tukey tests + +Usage: +------ + cstats_mean_IF -ci path/rev_cluster_index.nii.gz [-ip '`*`.nii.gz'] [-c 1 2 3] [-v] """ -import argparse import csv import nibabel as nib import numpy as np from pathlib import Path from rich.traceback import install -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg from unravel.image_tools.unique_intensities import uniq_intensities @@ -393,12 +393,18 @@

    Source code for unravel.cluster_stats.mean_IF

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-ip', '--input_pattern', help="Pattern for NIfTI images to process relative to cwd. Default: '*.nii.gz'", default='*.nii.gz', action=SM) - parser.add_argument('-ci', '--cluster_index', help='Path/rev_cluster_index.nii.gz from ``cstats_fdr``', required=True, action=SM) - parser.add_argument('-c', '--clusters', help='Space-separated list of cluster IDs to process. Default: all clusters', nargs='*', type=int, action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-ci', '--cluster_index', help='Path/rev_cluster_index.nii.gz from ``cstats_fdr``', required=True, action=SM) + + opts = parser.add_argument_group('Optional args') + opts.add_argument('-ip', '--input_pattern', help="Pattern for NIfTI images to process relative to cwd. Default: '*.nii.gz'", default='*.nii.gz', action=SM) + opts.add_argument('-c', '--clusters', help='Space-separated list of cluster IDs to process. Default: all clusters', nargs='*', type=int, action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/cluster_stats/mean_IF_summary.html b/_modules/unravel/cluster_stats/mean_IF_summary.html index f9ff29f3..57982662 100644 --- a/_modules/unravel/cluster_stats/mean_IF_summary.html +++ b/_modules/unravel/cluster_stats/mean_IF_summary.html @@ -354,30 +354,29 @@

    Source code for unravel.cluster_stats.mean_IF_summary

    """ Use ``cstats_mean_IF_summary`` from UNRAVEL to output plots of mean IF intensities for each cluster in atlas space. -Usage for t-tests: ------------------- - cstats_mean_IF_summary --order Control Treatment --labels Control Treatment -t ttest - -Usage for Tukey's tests w/ reordering and renaming of conditions: ------------------------------------------------------------------ - cstats_mean_IF_summary --order group3 group2 group1 --labels Group_3 Group_2 Group_1 - -Note: - - The first word of the csv inputs is used for the the group names (underscore separated). - -Inputs: - - <asterisk>.csv files in the working dir with these columns: sample, cluster_ID, mean_IF_intensity - Prereqs: - Generate CSV inputs withs ``cstats_IF_mean`` - Add conditions to input CSV file names: ``utils_prepend`` -sk $SAMPLE_KEY -f +Inputs: + - `*`.csv files in the working dir with these columns: sample, cluster_ID, mean_IF_intensity + Outputs: - cluster_mean_IF_summary/cluster_<cluster_id>.pdf for each cluster - If significant differences are found, a prefix '_' is added to the filename to sort the files + +Note: + - The first word of the csv inputs is used for the the group names (underscore separated). + +Usage for t-tests: +------------------ + cstats_mean_IF_summary --order Control Treatment --labels Control Treatment -t ttest [--cluster_ids 1 2 3] [-alt two-sided] [-v] + +Usage for Tukey's tests w/ reordering and renaming of conditions: +----------------------------------------------------------------- + cstats_mean_IF_summary --order group3 group2 group1 --labels Group_3 Group_2 Group_1 [--cluster_ids 1 2 3] [-v] """ -import argparse import matplotlib as mpl mpl.use('Agg') import matplotlib.pyplot as plt @@ -392,7 +391,8 @@

    Source code for unravel.cluster_stats.mean_IF_summary

    from scipy.stats import ttest_ind, dunnett from statsmodels.stats.multicomp import pairwise_tukeyhsd -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg @@ -400,14 +400,20 @@

    Source code for unravel.cluster_stats.mean_IF_summary

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('--cluster_ids', help='List of cluster IDs to process (Default: process all clusters)', nargs='*', type=int, action=SM) - parser.add_argument('--order', nargs='*', help='Group Order for plotting (must match 1st word of CSVs)', action=SM) - parser.add_argument('--labels', nargs='*', help='Group Labels in same order', action=SM) - parser.add_argument('-t', '--test', help='Choose between "tukey", "dunnett", and "ttest" post-hoc tests. (Default: tukey)', default='tukey', choices=['tukey', 'dunnett', 'ttest'], action=SM) - parser.add_argument('-alt', "--alternate", help="Number of tails and direction for Dunnett's test {'two-sided', 'less' (means < ctrl), 'greater'}. Default: two-sided", default='two-sided', action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('--order', nargs='*', help='Group Order for plotting (must match 1st word of CSVs)', required=True, action=SM) + reqs.add_argument('--labels', nargs='*', help='Group Labels in same order', required=True, action=SM) + + opts = parser.add_argument_group('Optional args') + opts.add_argument('--cluster_ids', help='List of cluster IDs to process (Default: process all clusters)', nargs='*', type=int, action=SM) + opts.add_argument('-t', '--test', help='Choose between "tukey", "dunnett", and "ttest" post-hoc tests. (Default: tukey)', default='tukey', choices=['tukey', 'dunnett', 'ttest'], action=SM) + opts.add_argument('-alt', "--alternate", help="Number of tails and direction for Dunnett's test {'two-sided', 'less' (means < ctrl), 'greater'}. Default: two-sided", default='two-sided', action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/cluster_stats/org_data.html b/_modules/unravel/cluster_stats/org_data.html index 9e9aec58..f7f5aa3e 100644 --- a/_modules/unravel/cluster_stats/org_data.html +++ b/_modules/unravel/cluster_stats/org_data.html @@ -354,12 +354,20 @@

    Source code for unravel.cluster_stats.org_data

    """ Use ``cstats_org_data`` from UNRAVEL to aggregate and organize csv outputs from ``cstats_validation``. +Inputs: + - clusters/cluster_validation_results_`*` (glob pattern matching ``cstats_validation`` output dirs) + - CSVs with the density data (e.g., cell_density_data.csv or label_density_data.csv from ``cstats_validation``) + - Optional: path/vstats to copy p val, info, and index files + +Outputs: + - target_dir/sample??__cell_density_data__<cluster_validation_results_`*`>.csv + - target_dir/sample??__label_density_data__<cluster_validation_results_`*`>.csv + Usage ----- - cstats_org_data -e <list of experiment directories> -cvd '<asterisk>' -td <target_dir> -vd <path/vstats_dir> -v + cstats_org_data -cvd '<asterisk>' [-dt cell | label] [-vd path/vstats_dir] [-td target_dir] [-pvt p_value_threshold.txt] [-d list of paths] [-p sample??] [-v] """ -import argparse import re import shutil from glob import glob @@ -368,7 +376,8 @@

    Source code for unravel.cluster_stats.org_data

    from rich.live import Live from rich.traceback import install -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, get_samples @@ -376,17 +385,22 @@

    Source code for unravel.cluster_stats.org_data

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-e', '--exp_paths', help='List of experiment dir paths w/ sample?? dirs to process.', nargs='*', default=None, action=SM) - parser.add_argument('-p', '--pattern', help='Pattern for sample?? dirs. Use cwd if no matches.', default='sample??', action=SM) - parser.add_argument('-d', '--dirs', help='List of sample?? dir names or paths to dirs to process', nargs='*', default=None, action=SM) - parser.add_argument('-cvd', '--cluster_val_dirs', help='Glob pattern matching cluster validation output dirs to copy data from (relative to ./sample??/clusters/)', required=True, action=SM) - parser.add_argument('-vd', '--vstats_path', help='path/vstats_dir (the dir ``vstats`` was run from) to copy p val, info, and index files if provided', default=None, action=SM) - parser.add_argument('-dt', '--density_type', help='Type of density data to aggregate (cell [default] or label).', default='cell', action=SM) - parser.add_argument('-td', '--target_dir', help='path/dir to copy results. If omitted, copy data to the cwd', default=None, action=SM) - parser.add_argument('-pvt', '--p_val_txt', help='Name of the file w/ the corrected p value thresh (e.g., from ``cstats_fdr``). Default: p_value_threshold.txt', default='p_value_threshold.txt', action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity.', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-cvd', '--cluster_val_dirs', help='Glob pattern matching cluster validation output dirs to copy data from (relative to ./sample??/clusters/)', required=True, action=SM) + + opts = parser.add_argument_group('Optional args') + opts.add_argument('-dt', '--density_type', help='Type of density data to aggregate (cell [default] or label).', default='cell', action=SM) + opts.add_argument('-vd', '--vstats_path', help='path/vstats_dir (the dir ``vstats`` was run from) to copy p val, info, and index files if provided', default=None, action=SM) + opts.add_argument('-td', '--target_dir', help='path/dir to copy results. If omitted, copy data to the cwd', default=None, action=SM) + opts.add_argument('-pvt', '--p_val_txt', help='Name of the file w/ the corrected p value thresh (e.g., from ``cstats_fdr``). Default: p_value_threshold.txt', default='p_value_threshold.txt', action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-d', '--dirs', help='Paths to sample?? dirs and/or dirs containing them (space-separated) for batch processing. Default: current dir', nargs='*', default=None, action=SM) + general.add_argument('-p', '--pattern', help='Pattern for directories to process. Default: sample??', default='sample??', action=SM) + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()

    @@ -543,11 +557,9 @@

    Source code for unravel.cluster_stats.org_data

    target_dir = Path(args.target_dir).resolve() if args.target_dir else Path.cwd() target_dir.mkdir(exist_ok=True, parents=True) - samples = get_samples(args.dirs, args.pattern, args.exp_paths) - - for sample in samples: + sample_paths = get_samples(args.dirs, args.pattern, args.verbose) - sample_path = Path(sample).resolve() if sample != Path.cwd().name else Path.cwd() + for sample_path in sample_paths: clusters_path = sample_path / 'clusters' if clusters_path.exists(): diff --git a/_modules/unravel/cluster_stats/prism.html b/_modules/unravel/cluster_stats/prism.html index 8ddf918d..6a4daecd 100644 --- a/_modules/unravel/cluster_stats/prism.html +++ b/_modules/unravel/cluster_stats/prism.html @@ -354,15 +354,8 @@

    Source code for unravel.cluster_stats.prism

     """
     Use ``cstats_prism`` from UNRAVEL to organize data for clusters for plotting in Prism.
     
    -Usage
    ------
    -    cstats_prism -ids 1 2 3
    -
    -Note:
    -    - cstats_table saves valid_clusters_dir/valid_cluster_IDs_sorted_by_anatomy.txt
    -
     Inputs:
    -    <asterisk>.csv from ``cstats_org_data`` (in working dir) or ``cstats_mean_IF``
    +    `*`.csv from ``cstats_org_data`` (in working dir) or ``cstats_mean_IF``
     
     CSV naming conventions:
         - Condition: first word before '_' in the file name (use ``utils_prepend`` if needed)
    @@ -388,16 +381,23 @@ 

    Source code for unravel.cluster_stats.prism

         - [<cell_density|label_density>_summary.csv]
         - [<cell_density|label_density>_summary_across_clusters.csv]
         - [cluster_volume_summary.csv]
    +
    +Note:
    +    - cstats_table saves valid_clusters_dir/valid_cluster_IDs_sorted_by_anatomy.txt
    +
    +Usage:
    +------
    +    cstats_prism [-ids 1 2 3] [-p /path/to/csv/files/from/cstats_validation_or_cstats_mean_IF] [-v]
     """
     
    -import argparse
     import pandas as pd
     from glob import glob
     from pathlib import Path
     from rich import print
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
    +
     from unravel.core.config import Configuration
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg
     
    @@ -405,11 +405,15 @@ 

    Source code for unravel.cluster_stats.prism

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-ids', '--valid_cluster_ids', help='Space-separated list of valid cluster IDs to include in the summary.', nargs='*', type=int, default=None, action=SM) - parser.add_argument('-p', '--path', help='Path to the directory containing the CSV files from ``cstats_validation`` or ``cstats_mean_IF``. Default: current directory', action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + opts = parser.add_argument_group('Optional args') + opts.add_argument('-ids', '--valid_cluster_ids', help='Space-separated list of valid cluster IDs to include in the summary.', nargs='*', type=int, default=None, action=SM) + opts.add_argument('-p', '--path', help='Path to the directory containing the CSV files from ``cstats_validation`` or ``cstats_mean_IF``. Default: current directory', action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/cluster_stats/recursively_mirror_rev_cluster_indices.html b/_modules/unravel/cluster_stats/recursively_mirror_rev_cluster_indices.html index ad9cbbd9..16f048f7 100644 --- a/_modules/unravel/cluster_stats/recursively_mirror_rev_cluster_indices.html +++ b/_modules/unravel/cluster_stats/recursively_mirror_rev_cluster_indices.html @@ -354,18 +354,16 @@

    Source code for unravel.cluster_stats.recursively_mirror_rev_cluster_indices """ Use ``cstats_mirror_indices`` from UNRAVEL to recursively process img.nii.gz files, apply mirroring, and save new files. -Usage ------ - cstats_mirror_indices -m RH -v - -Use this command after ``cstats_fdr`` to mirror the cluster indices for the other side of the brain before running ``cstats_validation``. - Note: + - Use this command after ``cstats_fdr`` to mirror the cluster indices for the other side of the brain before running ``cstats_validation``. - Use -ax 2 and -s 0 for the CCFv3 2020 atlas. - - Use -ax 0 and -s 2 for the 25 um Gubra atlas. + - Use -ax 0 and -s 2 for the 25 um Gubra atlas (deprecated). + +Usage: +------ + cstats_mirror_indices -m <RH or LH> [-p glob_pattern] [-ax 2] [-s 0] [-v] """ -import argparse import numpy as np import nibabel as nib import shutil @@ -373,7 +371,7 @@

    Source code for unravel.cluster_stats.recursively_mirror_rev_cluster_indices from rich.traceback import install from concurrent.futures import ThreadPoolExecutor -from unravel.core.argparse_utils import SM, SuppressMetavar +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM from unravel.core.config import Configuration from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg from unravel.voxel_stats.mirror import mirror @@ -381,13 +379,19 @@

    Source code for unravel.cluster_stats.recursively_mirror_rev_cluster_indices
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-m', '--mas_side', help='Side of the brain corresponding to the mask used for ``vstats`` and ``cstats_fdr`` (RH or LH)', choices=['RH', 'LH'], required=True, action=SM) - parser.add_argument('-p', '--pattern', help='Glob pattern to match files. Default: **/*rev_cluster_index.nii.gz', default='**/*rev_cluster_index.nii.gz', action=SM) - parser.add_argument('-ax', '--axis', help='Axis to flip the image along. Default: 2', default=2, type=int, action=SM) - parser.add_argument('-s', '--shift', help='Number of voxels to shift content after flipping. Default: 0', default=0, type=int, action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-m', '--mas_side', help='Side of the brain corresponding to the mask used for ``vstats`` and ``cstats_fdr`` (RH or LH)', choices=['RH', 'LH'], required=True, action=SM) + + opts = parser.add_argument_group('Optional args') + opts.add_argument('-p', '--pattern', help='Glob pattern to match files. Default: **/*rev_cluster_index.nii.gz', default='**/*rev_cluster_index.nii.gz', action=SM) + opts.add_argument('-ax', '--axis', help='Axis to flip the image along. Default: 2', default=2, type=int, action=SM) + opts.add_argument('-s', '--shift', help='Number of voxels to shift content after flipping. Default: 0', default=0, type=int, action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/cluster_stats/stats_table.html b/_modules/unravel/cluster_stats/stats_table.html index 7c30874c..50476f9c 100644 --- a/_modules/unravel/cluster_stats/stats_table.html +++ b/_modules/unravel/cluster_stats/stats_table.html @@ -359,22 +359,23 @@

    Source code for unravel.cluster_stats.stats_table

    path/stats_table.py -cp cluster_validation_info.csv -o cluster_validation_summary.csv """ -import argparse import pandas as pd from pathlib import Path from glob import glob from rich.traceback import install -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-cp', '--csv_pattern', help="Pattern to match csv files. Default: cluster_validation_results.csv", default='cluster_validation_info.csv', action=SM) - parser.add_argument('-o', '--output', help='path/output.csv. Default: cluster_validation_summary.csv', default='cluster_validation_summary.csv', action=SM) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-cp', '--csv_pattern', help="Pattern to match csv files. Default: cluster_validation_results.csv", default='cluster_validation_info.csv', action=SM) + opts.add_argument('-o', '--output', help='path/output.csv. Default: cluster_validation_summary.csv', default='cluster_validation_summary.csv', action=SM) + return parser.parse_args()
    diff --git a/_modules/unravel/cluster_stats/summary.html b/_modules/unravel/cluster_stats/summary.html index d396cf27..63e4c69e 100644 --- a/_modules/unravel/cluster_stats/summary.html +++ b/_modules/unravel/cluster_stats/summary.html @@ -354,39 +354,31 @@

    Source code for unravel.cluster_stats.summary

    """ Use ``cstats_summary`` from UNRAVEL to aggregate and analyze cluster validation data from ``cstats_validation``. -Usage if running directly after ``cstats_validation``: ------------------------------------------------------- - cstats_summary -c <path/config.ini> -e <exp dir paths> -cvd 'psilocybin_v_saline_tstat1_q<asterisk>' -vd <path/vstats_dir> -sk <path/sample_key.csv> --groups <group1> <group2> -hg <higher_group> -v +Prereqs: + - ``cstats_validation`` + +Inputs: + - Cell/label density CSVs from from ``cstats_validation`` + - The current directory should not have other folders when running this script for the first time. + - Directories from ``cstats_summary`` or ``cstats_org_data`` are ok though. + - The sample_key.csv file should have the following format: + dir_name,condition + sample01,control + sample02,treatment + +Outputs: + - Files for 3D brain models of valid clusters + - CSVs with valid cluster data (e.g., aggregated data for Prism) + - CSVs for sunburst plots + - Excel files with tables summarizing top regions and defining region abbreviations + +``cstats_summary`` runs these commands: + - ``cstats_org_data``, ``cstats_group_data``, ``utils_prepend``, ``cstats``, ``cstats_index``, ``cstats_brain_model``, ``cstats_table``, ``cstats_prism``, ``cstats_legend`` Note: - - The current working directory should not have other directories when running this script for the first time. Directories from ``cstats_org_data`` are ok though. - -Usage if running after ``cstats_validation`` and ``cstats_org_data``: ---------------------------------------------------------------------- - cstats_summary -c <path/config.ini> -sk <path/sample_key.csv> --groups <group1> <group2> -hg <higher_group> -v - -Note: - - For the second usage, the ``-e``, ``-cvd``, and ``-vd`` arguments are not needed because the data is already in the working directory. - Only process one comparison at a time. If you have multiple comparisons, run this script separately for each comparison in separate directories. - Then aggregate the results as needed (e.g. to make a legend with all relevant abbeviations, copy the .xlsx files to a central location and run ``cstats_legend``). - -The current working directory should not have other directories when running this script for the first time. Directories from cstats_org_data are ok though. - -``cstats_summary`` runs commands in this order: - - ``cstats_org_data`` - - ``cstats_group_data`` - - ``utils_prepend`` - - ``cstats`` - - ``cstats_index`` - - ``cstats_brain_model`` - - ``cstats_table`` - - ``cstats_prism`` - - ``cstats_legend`` - -The sample_key.csv file should have the following format: - dir_name,condition - sample01,control - sample02,treatment + - See ``cstats`` for more information on -cp and -hg. If you need to rerun this script, delete the following directories and files in the current working directory: find . -name _valid_clusters -exec rm -rf {} \; -o -name cluster_validation_summary_t-test.csv -exec rm -f {} \; -o -name cluster_validation_summary_tukey.csv -exec rm -f {} \; -o -name 3D_brains -exec rm -rf {} \; -o -name valid_clusters_tables_and_legend -exec rm -rf {} \; -o -name _valid_clusters_stats -exec rm -rf {} \; @@ -394,10 +386,17 @@

    Source code for unravel.cluster_stats.summary

    If you want to aggregate CSVs for sunburst plots of valid clusters, run this in a root directory: find . -name "valid_clusters_sunburst.csv" -exec sh -c 'cp {} ./$(basename $(dirname $(dirname {})))_$(basename {})' \; -Likewise, you can aggregate raw data (raw_data_for_t-test_pooled.csv), stats (t-test_results.csv), and prism files (cell_density_summary_for_valid_clusters.csv). +Likewise, you can aggregate raw data (raw_data_for_t-test_pooled.csv), stats (t-test_results.csv), and prism files (cell_density_summary_for_valid_clusters.csv). + +Usage if running directly after ``cstats_validation``: +------------------------------------------------------ + cstats_summary -c <path/config.ini> -d <list of paths> -cvd 'psilocybin_v_saline_tstat1_q<asterisk>' -vd <path/vstats_dir> -sk <path/sample_key.csv> --groups <group1> <group2> -hg <higher_group> [-cp <condition_prefixes>] [-v] + +Usage if running after ``cstats_validation`` and ``cstats_org_data``: +--------------------------------------------------------------------- + cstats_summary -c <path/config.ini> -sk <path/sample_key.csv> --groups <group1> <group2> -hg <higher_group> [-cp <condition_prefixes>] [-v] """ -import argparse import nibabel as nib import numpy as np import subprocess @@ -406,7 +405,8 @@

    Source code for unravel.cluster_stats.summary

    from rich.traceback import install from unravel.cluster_stats.org_data import cp -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, load_config from unravel.utilities.aggregate_files_recursively import find_and_copy_files @@ -415,24 +415,30 @@

    Source code for unravel.cluster_stats.summary

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-c', '--config', help='Path to the config.ini file. Default: unravel/cluster_stats/summary.ini', default=Path(__file__).parent / 'summary.ini', action=SM) + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) - # cstats_org_data -e <list of experiment directories> -cvd '*' -td <target_dir> -vd <path/vstats_dir> -v - parser.add_argument('-e', '--exp_paths', help='List of experiment dir paths w/ sample?? dirs to process. (needed for cstats_org_data)', nargs='*', action=SM) - parser.add_argument('-cvd', '--cluster_val_dirs', help='Glob pattern matching cluster validation output dirs to copy data from (relative to ./sample??/clusters/; for cstats_org_data', action=SM) - parser.add_argument('-vd', '--vstats_path', help='path/vstats_dir (dir vstats was run from) to copy p val, info, and index files (for cstats_org_data)', action=SM) + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-c', '--config', help='Path to the config.ini file. Default: unravel/cluster_stats/summary.ini', default=Path(__file__).parent / 'summary.ini', action=SM) + + # cstats_org_data -d <list of experiment directories> -cvd '*' -td <target_dir> -vd <path/vstats_dir> -v + cstats_org_data = parser.add_argument_group('Optional args for cstats_org_data') + cstats_org_data.add_argument('-d', '--dirs', help='Paths to sample?? dirs and/or dirs containing them (space-separated) for batch processing. Default: current dir', nargs='*', default=None, action=SM) + cstats_org_data.add_argument('-cvd', '--cluster_val_dirs', help='Glob pattern matching cluster validation output dirs to copy data from (relative to ./sample??/clusters/; for cstats_org_data', action=SM) + cstats_org_data.add_argument('-vd', '--vstats_path', help='path/vstats_dir (dir vstats was run from) to copy p val, info, and index files (for cstats_org_data)', action=SM) # utils_prepend -c <path/sample_key.csv> -f -r - parser.add_argument('-sk', '--sample_key', help='path/sample_key.csv w/ directory names and conditions (for utils_prepend)', action=SM) + utils_prepend = parser.add_argument_group('Optional args for utils_prepend') + utils_prepend.add_argument('-sk', '--sample_key', help='path/sample_key.csv w/ directory names and conditions (for utils_prepend)', action=SM) # cstats --groups <group1> <group2> - parser.add_argument('--groups', help='List of group prefixes. 2 groups --> t-test. >2 --> Tukey\'s tests (The first 2 groups reflect the main comparison for validation rates; for cstats)', nargs='*', action=SM) - parser.add_argument('-cp', '--condition_prefixes', help='Condition prefixes to group related data (optional for cstats)', nargs='*', default=None, action=SM) - parser.add_argument('-hg', '--higher_group', help='Specify the group that is expected to have a higher mean based on the direction of the p value map', required=True) + cstats = parser.add_argument_group('Optional rgs for cstats') + cstats.add_argument('--groups', help='List of group prefixes. 2 groups --> t-test. >2 --> Tukey\'s tests (The first 2 groups reflect the main comparison for validation rates; for cstats)', nargs='*', action=SM) + cstats.add_argument('-cp', '--condition_prefixes', help='Condition prefixes to group related data (optional for cstats)', nargs='*', default=None, action=SM) + cstats.add_argument('-hg', '--higher_group', help='Specify the group that is expected to have a higher mean based on the direction of the p value map', required=True) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ return parser.parse_args()
    @@ -442,6 +448,8 @@

    Source code for unravel.cluster_stats.summary

    # TODO: Add a reset option to delete all output files and directories from the current working directory # TODO: Aggregate CSVs for valid cluster sunburst plots # TODO: Sort the overall valid cluster sunburst csv +# TODO: Check if irrelevant directories are present in the current working directory and warn the user +# TODO: Replace this (find . -name "valid_clusters_sunburst.csv" -exec sh -c 'cp {} ./$(basename $(dirname $(dirname {})))_$(basename {})' \;) w/ example of utils_agg_files_rec
    @@ -467,9 +475,9 @@

    Source code for unravel.cluster_stats.summary

    cfg = load_config(args.config) # Run cstats_org_data - if args.exp_paths and args.cluster_val_dirs and args.vstats_path: + if args.dirs and args.cluster_val_dirs and args.vstats_path: org_data_args = [ - '-e', *args.exp_paths, + '-d', *args.dirs, '-p', cfg.org_data.pattern, '-cvd', args.cluster_val_dirs, '-vd', args.vstats_path, diff --git a/_modules/unravel/cluster_stats/sunburst.html b/_modules/unravel/cluster_stats/sunburst.html index 0faf73bd..6522d0e0 100644 --- a/_modules/unravel/cluster_stats/sunburst.html +++ b/_modules/unravel/cluster_stats/sunburst.html @@ -354,31 +354,30 @@

    Source code for unravel.cluster_stats.sunburst

    """ Use ``cstats_sunburst`` from UNRAVEL to generate a sunburst plot of regional volumes across all levels of the ABA hierarchy. -Usage: ------- - cstats_sunburst -i path/rev_cluster_index.nii.gz -a path/atlas.nii.gz -v - Prereqs: - - ``cstats_validation`` generates a rev_cluster_index.nii.gz (clusters of significant voxels) and validates them. - - Optional: ``cstats_index`` generates a rev_cluster_index.nii.gz w/ valid clusters. + - ``cstats_summary`` generates a valid rev_cluster_index.nii.gz (clusters of significant voxels) via ``cstats_index``. + +Inputs: + - path/rev_cluster_index.nii.gz (e.g., with valid clusters or a labeled image) + - path/atlas.nii.gz (Default: atlas/atlas_CCFv3_2020_30um.nii.gz) for applying region IDs to the input image Outputs: - path/input_sunburst.csv and [input_path/sunburst_RGBs.csv] + - path/input_sunburst.csv and [input_path/sunburst_RGBs.csv] -Plot region volumes (https://app.flourish.studio/) +Note: + - Default sunburst csv location: UNRAVEL/unravel/core/csvs/sunburst_IDPath_Abbrv.csv + - Region info csv: CCFv3-2020_info.csv (or use CCFv3-2017_info.csv or provide a custom CSV with the same columns) -Data tab: - Paste in data from csv, categories columns = Depth_<asterisk> columns, Size by = Volumes column - -Preview tab: - Hierarchy -> Depth to 10, Colors -> paste RGB codes into Custom overrides +Next steps: + - Use input_sunburst.csv to make a sunburst plot or regional volumes in Flourish Studio (https://app.flourish.studio/) + - It can be pasted into the Data tab (categories columns = Depth_`*` columns, Size by = Volumes column) + - Preview tab: Hierarchy -> Depth to 10, Colors -> paste RGB codes from sunburst_RGBs.csv into Custom overrides -Note: - - Default csv: UNRAVEL/unravel/core/csvs/sunburst_IDPath_Abbrv.csv - - CCFv3-2020_info.csv or CCFv3-2017_info.csv +Usage: +------ + cstats_sunburst -i path/rev_cluster_index.nii.gz [-a atlas/atlas_CCFv3_2020_30um.nii.gz] [-rgb] [-scsv sunburst_IDPath_Abbrv.csv] [-icsv CCFv3-2020_info.csv] [-v] """ -import argparse import nibabel as nib import numpy as np import pandas as pd @@ -386,7 +385,8 @@

    Source code for unravel.cluster_stats.sunburst

    from rich import print from rich.traceback import install -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg @@ -394,14 +394,20 @@

    Source code for unravel.cluster_stats.sunburst

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input', help='path/rev_cluster_index.nii.gz (e.g., with valid clusters)', required=True, action=SM) - parser.add_argument('-a', '--atlas', help='path/atlas.nii.gz (Default: atlas/atlas_CCFv3_2020_30um.nii.gz)', default='atlas/atlas_CCFv3_2020_30um.nii.gz', action=SM) - parser.add_argument('-rgb', '--output_rgb_lut', help='Output sunburst_RGBs.csv if flag provided (for Allen brain atlas coloring)', action='store_true') - parser.add_argument('-scsv', '--sunburst_csv_path', help='CSV name or path/name.csv. Default: sunburst_IDPath_Abbrv.csv', default='sunburst_IDPath_Abbrv.csv', action=SM) - parser.add_argument('-icsv', '--info_csv_path', help='CSV name or path/name.csv. Default: CCFv3-2020_info.csv', default='CCFv3-2020_info.csv', action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='path/rev_cluster_index.nii.gz (e.g., with valid clusters)', required=True, action=SM) + + opts = parser.add_argument_group('Optional args') + opts.add_argument('-a', '--atlas', help='path/atlas.nii.gz (Default: atlas/atlas_CCFv3_2020_30um.nii.gz)', default='atlas/atlas_CCFv3_2020_30um.nii.gz', action=SM) + opts.add_argument('-rgb', '--output_rgb_lut', help='Output sunburst_RGBs.csv if flag provided (for Allen brain atlas coloring)', action='store_true') + opts.add_argument('-scsv', '--sunburst_csv_path', help='CSV name or path/name.csv. Default: sunburst_IDPath_Abbrv.csv', default='sunburst_IDPath_Abbrv.csv', action=SM) + opts.add_argument('-icsv', '--info_csv_path', help='CSV name or path/name.csv. Default: CCFv3-2020_info.csv', default='CCFv3-2020_info.csv', action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()

    diff --git a/_modules/unravel/cluster_stats/table.html b/_modules/unravel/cluster_stats/table.html index 5c08fab2..5fa1ebab 100644 --- a/_modules/unravel/cluster_stats/table.html +++ b/_modules/unravel/cluster_stats/table.html @@ -354,12 +354,16 @@

    Source code for unravel.cluster_stats.table

     """
     Use ``cstats_table`` from UNRAVEL to summarize volumes of the top x regions and collapsing them into parent regions until a criterion is met.
     
    -Usage:
    -------
    -    cstats_table
    -
     Prereqs:
    -    ``cstats_index`` has been run. Run this command from the valid_clusters dir. <asterisk>cluster_info.txt in working dir.
    +    - This command is usually run via ``cstats_summary``.
    +
    +Inputs:
    +    - CSVs with sunburst data for each cluster (e.g., cluster_`*`_sunburst.csv).
    +    - `*`cluster_info.txt in the parent dir (made by ``cstats_fdr`` and copied by ``cstats_org_data``).
    +
    +Outputs:
    +    - A color-coded xlsx table summarizing the top regions and their volumes for each cluster.
    +    - A hierarchically sorted CSV with regional volumes for each cluster.
     
     Sorting by hierarchy and volume:
     --------------------------------
    @@ -376,11 +380,14 @@ 

    Source code for unravel.cluster_stats.table

     Note: 
         - CCFv3-2020_info.csv is in UNRAVEL/unravel/core/csvs/
         - It has columns: structure_id_path,very_general_region,collapsed_region_name,abbreviation,collapsed_region,other_abbreviation,other_abbreviation_defined,layer,sunburst
    -    - Alternatively, use CCFv3-2017_info.csv or provide a custom CSV with the same columns.   
    +    - Alternatively, use CCFv3-2017_info.csv or provide a custom CSV with the same columns.
    +
    +Usage:
    +------
    +    cstats_table [-vcd <val_clusters_dir>] [-t <number of top regions>] [-pv <perecent volume criterion>] [-csv CCFv3-2020_info.csv] [-rgb sunburst_RGBs.csv] [-v]
     """
     
     
    -import argparse
     import openpyxl
     import math
     import numpy as np
    @@ -394,7 +401,8 @@ 

    Source code for unravel.cluster_stats.table

     from rich import print
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
    +
     from unravel.core.config import Configuration
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg
     
    @@ -402,14 +410,18 @@ 

    Source code for unravel.cluster_stats.table

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-vcd', '--val_clusters_dir', help='Path to the valid_clusters dir output from unravel.cluster_stats.index (else cwd)', action=SM) - parser.add_argument('-t', '--top_regions', help='Number of top regions to output. Default: 4', default=4, type=int, action=SM) - parser.add_argument('-pv', '--percent_vol', help='Percentage of the total volume the top regions must comprise [after collapsing]. Default: 0.8', default=0.8, type=float, action=SM) - parser.add_argument('-csv', '--info_csv_path', help='CSV name or path/name.csv. Default: CCFv3-2020_info.csv', default='CCFv3-2020_info.csv', action=SM) - parser.add_argument('-rgb', '--sunburst_rgbs', help='CSV name or path/name.csv. Default: sunburst_RGBs.csv', default='sunburst_RGBs.csv', action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + opts = parser.add_argument_group('Optional args') + opts.add_argument('-vcd', '--val_clusters_dir', help='Path to the valid_clusters dir output from unravel.cluster_stats.index (else cwd)', action=SM) + opts.add_argument('-t', '--top_regions', help='Number of top regions to output. Default: 4', default=4, type=int, action=SM) + opts.add_argument('-pv', '--percent_vol', help='Percentage of the total volume the top regions must comprise [after collapsing]. Default: 0.8', default=0.8, type=float, action=SM) + opts.add_argument('-csv', '--info_csv_path', help='CSV name or path/name.csv. Default: CCFv3-2020_info.csv', default='CCFv3-2020_info.csv', action=SM) + opts.add_argument('-rgb', '--sunburst_rgbs', help='CSV name or path/name.csv. Default: sunburst_RGBs.csv', default='sunburst_RGBs.csv', action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/cluster_stats/validation.html b/_modules/unravel/cluster_stats/validation.html index ac1b2889..62a32912 100644 --- a/_modules/unravel/cluster_stats/validation.html +++ b/_modules/unravel/cluster_stats/validation.html @@ -354,25 +354,32 @@

    Source code for unravel.cluster_stats.validation

    """ Use ``cstats_validation`` from UNRAVEL to warp a cluster index from atlas space to tissue space, crop clusters, apply a segmentation mask, and quantify cell/label densities. -Usage: ------- - cstats_validation -e <experiment paths> -m <path/rev_cluster_index_to_warp_from_atlas_space.nii.gz> -s cfos_seg_ilastik_1 -v +Prereqs: + - ``cstats_fdr`` to generate a cluster index in atlas space (a map of clusters of significant voxels) + - ``seg_ilastik`` to generate a segmentation mask in tissue space (e.g., to label c-Fos+ cells) -cluster_index_dir = Path(args.moving_img).name w/o "_rev_cluster_index" and ".nii.gz" +Inputs: + - path/rev_cluster_index.nii.gz to warp from atlas space (rev = reverse, i.e., cluster IDs are from large to small) + - rel_path/seg_img.nii.gz. 1st glob match processed Outputs: - ./sample??/clusters/<cluster_index_dir>/outer_bounds.txt - ./sample??/clusters/<cluster_index_dir>/<args.density>_data.csv + - cluster_index_dir = Path(args.moving_img).name w/o "_rev_cluster_index" and ".nii.gz" -For -s, if a dir name is provided, the command will load ./sample??/seg_dir/sample??_seg_dir.nii.gz. -If a relative path is provided, the command will load the image at the specified path. +Note: + - For -s, if a dir name is provided, the command will load ./sample??/seg_dir/sample??_seg_dir.nii.gz. + - If a relative path is provided, the command will load the image at the specified path. Next command: ``cstats_summary`` + +Usage: +------ + cstats_validation -m <path/rev_cluster_index_to_warp_from_atlas_space.nii.gz> -s <rel_path/seg_img.nii.gz> [-de cell_density | label_density] [-o rel_path/cluster_data.csv] [-c 1 3 4] [optional output: -n rel_path/native_cluster_index.zarr] [-fri autofl_50um_masked_fixed_reg_input.nii.gz] [-inp nearestNeighbor] [-ro reg_outputs] [-r 50] [-md parameters/metadata.txt] [-zo 0] [-mi] [-cc 6] [-d list of paths] [-p sample??] [-v] """ -import argparse import concurrent.futures import cc3d import numpy as np @@ -383,7 +390,8 @@

    Source code for unravel.cluster_stats.validation

    from rich.live import Live from rich.traceback import install -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.img_io import load_3D_img, load_image_metadata_from_txt, load_nii_subset, resolve_path from unravel.core.img_tools import cluster_IDs @@ -394,39 +402,47 @@

    Source code for unravel.cluster_stats.validation

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-e', '--exp_paths', help='List of experiment dir paths w/ sample?? dirs to process.', nargs='*', default=None, action=SM) - parser.add_argument('-p', '--pattern', help='Pattern for sample?? dirs. Use cwd if no matches.', default='sample??', action=SM) - parser.add_argument('-d', '--dirs', help='List of sample?? dir names or paths to dirs to process', nargs='*', default=None, action=SM) - - # Key args - parser.add_argument('-m', '--moving_img', help='path/*_rev_cluster_index.nii.gz to warp from atlas space', required=True, action=SM) - parser.add_argument('-s', '--seg', help='rel_path/seg_img.nii.gz. 1st glob match processed', required=True, action=SM) - parser.add_argument('-c', '--clusters', help='Clusters to process: all or list of clusters (e.g., 1 3 4). Default: all', nargs='*', default='all', action=SM) - parser.add_argument('-de', '--density', help='Density to measure: cell_density (default) or label_density', default='cell_density', choices=['cell_density', 'label_density'], action=SM) - parser.add_argument('-o', '--output', help='rel_path/clusters_info.csv (Default: clusters/<cluster_index_dir>/cluster_data.csv)', default=None, action=SM) + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-m', '--moving_img', help='path/*_rev_cluster_index.nii.gz to warp from atlas space', required=True, action=SM) + reqs.add_argument('-s', '--seg', help='rel_path/seg_img.nii.gz. 1st glob match processed', required=True, action=SM) + + opts = parser.add_argument_group('Optional args') + opts.add_argument('-de', '--density', help='Density to measure: cell_density (default) or label_density', default='cell_density', choices=['cell_density', 'label_density'], action=SM) + opts.add_argument('-o', '--output', help='rel_path/clusters_info.csv. Default: clusters/<cluster_index_dir>/cluster_data.csv', default=None, action=SM) + opts.add_argument('-c', '--clusters', help='Clusters to process: all or list of clusters (e.g., 1 3 4). Processes all clusters by default', nargs='*', default='all', action=SM) # Optional to_native() args - parser.add_argument('-n', '--native_idx', help='Load/save native cluster index from/to rel_path/native_image.zarr (fast) or rel_path/native_image.nii.gz if provided', default=None, action=SM) - parser.add_argument('-fri', '--fixed_reg_in', help='Fixed input for registration (unravel.register.reg). Default: autofl_50um_masked_fixed_reg_input.nii.gz', default="autofl_50um_masked_fixed_reg_input.nii.gz", action=SM) - parser.add_argument('-inp', '--interpol', help='Interpolator for ants.apply_transforms (nearestNeighbor [default], multiLabel [slow])', default="nearestNeighbor", action=SM) - parser.add_argument('-ro', '--reg_outputs', help="Name of folder w/ outputs from unravel.register.reg (e.g., transforms). Default: reg_outputs", default="reg_outputs", action=SM) - parser.add_argument('-r', '--reg_res', help='Resolution of registration inputs in microns. Default: 50', default='50',type=int, action=SM) - parser.add_argument('-md', '--metadata', help='path/metadata.txt. Default: parameters/metadata.txt', default="parameters/metadata.txt", action=SM) - parser.add_argument('-zo', '--zoom_order', help='SciPy zoom order for scaling to full res. Default: 0 (nearest-neighbor)', default='0',type=int, action=SM) - parser.add_argument('-mi', '--miracl', help='Mode for compatibility (accounts for tif to nii reorienting)', action='store_true', default=False) + opts_to_native = parser.add_argument_group('Optional args for to_native()') + opts_to_native.add_argument('-n', '--native_idx', help='Load/save native cluster index from/to rel_path/native_image.zarr (fast) or rel_path/native_image.nii.gz if provided', default=None, action=SM) + opts_to_native.add_argument('-fri', '--fixed_reg_in', help='Fixed input for registration (unravel.register.reg). Default: autofl_50um_masked_fixed_reg_input.nii.gz', default="autofl_50um_masked_fixed_reg_input.nii.gz", action=SM) + opts_to_native.add_argument('-inp', '--interpol', help='Interpolator for ants.apply_transforms (nearestNeighbor [default], multiLabel [slow])', default="nearestNeighbor", action=SM) + opts_to_native.add_argument('-ro', '--reg_outputs', help="Name of folder w/ outputs from unravel.register.reg (e.g., transforms). Default: reg_outputs", default="reg_outputs", action=SM) + opts_to_native.add_argument('-r', '--reg_res', help='Resolution of registration inputs in microns. Default: 50', default='50',type=int, action=SM) + opts_to_native.add_argument('-md', '--metadata', help='path/metadata.txt. Default: parameters/metadata.txt', default="parameters/metadata.txt", action=SM) + opts_to_native.add_argument('-zo', '--zoom_order', help='SciPy zoom order for scaling to full res. Default: 0 (nearest-neighbor)', default='0',type=int, action=SM) + + # Compatability args + compatability = parser.add_argument_group('Compatability options for to_native()') + compatability.add_argument('-mi', '--miracl', help='Mode for compatibility (accounts for tif to nii reorienting)', action='store_true', default=False) # Optional arg for count_cells() - parser.add_argument('-cc', '--connect', help='Connected component connectivity (6, 18, or 26). Default: 6', type=int, default=6, action=SM) + opts_cell_counts = parser.add_argument_group('Optional args for count_cells()') + opts_cell_counts.add_argument('-cc', '--connect', help='Connected component connectivity (6, 18, or 26). Default: 6', type=int, default=6, action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-d', '--dirs', help='Paths to sample?? dirs and/or dirs containing them (space-separated) for batch processing. Default: current dir', nargs='*', default=None, action=SM) + general.add_argument('-p', '--pattern', help='Pattern for directories to process. Default: sample??', default='sample??', action=SM) + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ return parser.parse_args()
    -# TODO: QC. Aggregate .csv results for all samples if args.exp_dirs, script to load image subset. +# TODO: QC. Aggregate .csv results for all samples if args.dirs, script to load image subset. # TODO: Make config file for defaults or a command_generator.py script -# TODO: Consider adding an option to quantify mean IF intensity in each cluster in segmented voxels. Also make a script for mean IF intensity in clusters in atlas space. +# TODO: Consider adding an option to quantify mean IF intensity in each cluster in segmented voxels. Also make a script for mean IF intensity in clusters in atlas space. +# TODO: Use glob for -s to load the first match. If no match, print a message and continue to the next sample. Afterwards, update in help: "For -s, if a dir name is provided, the command will load ./sample??/seg_dir/sample??_seg_dir.nii.gz."
    [docs] @@ -576,13 +592,11 @@

    Source code for unravel.cluster_stats.validation

    Configuration.verbose = args.verbose verbose_start_msg() - samples = get_samples(args.dirs, args.pattern, args.exp_paths) - - progress, task_id = initialize_progress_bar(len(samples), "[red]Processing samples...") - with Live(progress): - for sample in samples: + sample_paths = get_samples(args.dirs, args.pattern, args.verbose) - sample_path = Path(sample).resolve() if sample != Path.cwd().name else Path.cwd() + progress, task_id = initialize_progress_bar(len(sample_paths), "[red]Processing samples...") + with Live(progress): + for sample_path in sample_paths: # Define final output and check if it exists cluster_index_dir = str(Path(args.moving_img).name).replace(".nii.gz", "").replace("_rev_cluster_index_", "_") diff --git a/_modules/unravel/core/argparse_utils.html b/_modules/unravel/core/argparse_utils.html deleted file mode 100644 index 0fcc1b42..00000000 --- a/_modules/unravel/core/argparse_utils.html +++ /dev/null @@ -1,523 +0,0 @@ - - - - - - - - - - unravel.core.argparse_utils — UNRAVEL docs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - -
    -
    -
    -
    -
    - -
    - -
    - - - - - -
    -
    - - - - - -
    - - - - - - - - - - - -
    - -
    - - -
    -
    - -
    -
    - -
    - -
    - - - - -
    - -
    - - -
    -
    - - - - - -
    - -

    Source code for unravel.core.argparse_utils

    -#!/usr/bin/env python3
    -
    -"""
    -This script defines custom classes to enhance the formatting and handling of argparse arguments,
    -with a focus on suppressing metavar display and improving help message readability.
    -
    -Classes:
    -    - SuppressMetavar: A custom HelpFormatter class that suppresses the display of metavar for
    -                       arguments and customizes the epilog formatting.
    -    - SM: A custom argparse.Action class that suppresses the display of metavar and manages
    -          argument values.
    -
    -Usage:
    -    Import the classes and use them in an argparse-based script to suppress metavar and format help
    -    messages for improved readability.
    -
    -Example:
    -    import argparse
    -    from path.to.this.script import SuppressMetavar, SM
    -
    -    parser = argparse.ArgumentParser(formatter_class=SuppressMetavar)
    -    parser.add_argument('-e', '--example', help='Example argument', action=SM)
    -    args = parser.parse_args()
    -
    -Classes:
    -    SuppressMetavar
    -        - Inherits from argparse.HelpFormatter to modify the formatting of action invocations and epilog text.
    -        - Methods:
    -            - _format_action_invocation: Customizes the formatting of argument options.
    -            - _fill_text: Formats the epilog text with specified indentation and width.
    -
    -    SM
    -        - Inherits from argparse.Action to suppress metavar display and manage argument values.
    -        - Methods:
    -            - __init__: Initializes the custom action and sets the metavar to an empty string or tuple.
    -            - __call__: Sets the argument values in the namespace, handling both single and multiple values.
    -
    -Note:
    -    - This script relies on the argparse library for command-line argument parsing.
    -    - The SuppressMetavar class is designed to improve the readability of help messages by suppressing
    -      metavar display and customizing the formatting of epilog text.
    -    - nargs='``+``' with action=SM: This combination causes issues when the terminal window is small. 
    -    - Use nargs='``*``' with action=SM if zero arguments are acceptable, or drop action=SM to avoid conflicts.
    -    - Difference:
    -    - nargs='``+``' requires at least one argument.
    -    - nargs='``*``' allows zero or more arguments, providing more flexibility but no guarantee of input.
    -"""
    -
    -import argparse
    -import textwrap
    -
    -
    -[docs] -class SuppressMetavar(argparse.HelpFormatter): - def _format_action_invocation(self, action): - if not action.option_strings: - metavar, = self._metavar_formatter(action, action.dest)(1) - return metavar - else: - parts = [] - if action.nargs == 0: - parts.extend(action.option_strings) - else: - for option_string in action.option_strings: - parts.append(option_string) - return ', '.join(parts) - - def _fill_text(self, text, width, indent): - # This method formats the epilog. Override it to split the text into lines and format each line individually. - text_lines = text.splitlines() - formatted_lines = [textwrap.fill(line, width, initial_indent=indent, subsequent_indent=indent) for line in text_lines] - return '\n'.join(formatted_lines)
    - - - -#Suppress metavar -
    -[docs] -class SM(argparse.Action): - def __init__(self, option_strings, dest, nargs=None, **kwargs): - if nargs is not None: - kwargs.setdefault('metavar', '') - super(SM, self).__init__(option_strings, dest, nargs=nargs, **kwargs) - - def __call__(self, parser, namespace, values, option_string=None): - # If this action is for a single value (not expecting multiple values) - if self.nargs is None or self.nargs == 0: - setattr(namespace, self.dest, values) # Set the single value directly - else: - # If the action expects multiple values, handle it as a list - if isinstance(values, list): - setattr(namespace, self.dest, values) - else: - current_values = getattr(namespace, self.dest, []) - if not isinstance(current_values, list): - current_values = [current_values] - current_values.append(values) - setattr(namespace, self.dest, current_values)
    - -
    - -
    - - - - - -
    - -
    -
    -
    - -
    - - - - -
    -
    - -
    - -
    -
    -
    - - - - - -
    - - -
    - - \ No newline at end of file diff --git a/_modules/unravel/core/argparse_utils_rich.html b/_modules/unravel/core/argparse_utils_rich.html deleted file mode 100644 index d64eee4b..00000000 --- a/_modules/unravel/core/argparse_utils_rich.html +++ /dev/null @@ -1,525 +0,0 @@ - - - - - - - - - - unravel.core.argparse_utils_rich — UNRAVEL docs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - -
    -
    -
    -
    -
    - -
    - -
    - - - - - -
    -
    - - - - - -
    - - - - - - - - - - - -
    - -
    - - -
    -
    - -
    -
    - -
    - -
    - - - - -
    - -
    - - -
    -
    - - - - - -
    - -

    Source code for unravel.core.argparse_utils_rich

    -#!/usr/bin/env python3
    -
    -"""
    -This script defines custom classes to enhance the formatting and handling of argparse arguments
    -using the Rich library for beautiful terminal output.
    -
    -Classes:
    -    - SuppressMetavar: A custom RichHelpFormatter class that suppresses the display of metavar for
    -                       arguments and customizes the epilog formatting.
    -    - SM: A custom argparse.Action class that suppresses the display of metavar across all nargs 
    -          configurations and manages argument values.
    -
    -Usage:
    -    Import the classes and use them in an argparse-based script to suppress metavar and format help
    -    messages with Rich's styled output.
    -
    -Example:
    -    import argparse
    -    from rich_argparse import RichHelpFormatter
    -    from path.to.this.script import SuppressMetavar, SM
    -
    -    parser = argparse.ArgumentParser(formatter_class=SuppressMetavar)
    -    parser.add_argument('-e', '--example', help='Example argument', action=SM)
    -    args = parser.parse_args()
    -
    -Classes:
    -    SuppressMetavar
    -        - Inherits from RichHelpFormatter to modify the formatting of action invocations and epilog text.
    -        - Methods:
    -            - _format_action_invocation: Customizes the formatting of argument options.
    -            - _fill_text: Formats the epilog text with specified indentation and width.
    -
    -    SM
    -        - Inherits from argparse.Action to suppress metavar display and manage argument values.
    -        - Methods:
    -            - __init__: Initializes the custom action and sets the metavar to an empty string or tuple.
    -            - __call__: Sets the argument values in the namespace, handling both single and multiple values.
    -
    -Note:
    -    - This script relies on the rich and argparse libraries for enhanced help message formatting.
    -    - The SuppressMetavar class is specifically designed to work with Rich's RichHelpFormatter for styled terminal output.
    -    - nargs='``+``' with action=SM: This combination causes issues when the terminal window is small. 
    -    - Use nargs='``*``' with action=SM if zero arguments are acceptable, or drop action=SM to avoid conflicts.
    -    - Difference:
    -    - nargs='``+``' requires at least one argument.
    -    - nargs='``*``' allows zero or more arguments, providing more flexibility but no guarantee of input.
    -"""
    -
    -import argparse
    -from rich_argparse import RichHelpFormatter
    -import textwrap
    -
    -
    -[docs] -class SuppressMetavar(RichHelpFormatter): - def _format_action_invocation(self, action): - if not action.option_strings: - metavar, = self._metavar_formatter(action, action.dest)(1) - return metavar - else: - parts = [] - if action.nargs == 0: - parts.extend(action.option_strings) - else: - for option_string in action.option_strings: - parts.append(option_string) - return ', '.join(parts) - - def _fill_text(self, text, width, indent): - # This method formats the epilog. Override it to split the text into lines and format each line individually. - text_lines = text.splitlines() - formatted_lines = [textwrap.fill(line, width, initial_indent=indent, subsequent_indent=indent) for line in text_lines] - return '\n'.join(formatted_lines)
    - - -# Custom action class to suppress metavar across all nargs configurations -
    -[docs] -class SM(argparse.Action): - def __init__(self, option_strings, dest, nargs=None, **kwargs): - # Forcefully suppress metavar display by setting it to an empty string or an appropriate tuple - if nargs is not None: - # Use an empty tuple with a count matching nargs when nargs is a specific count or '+' - kwargs['metavar'] = tuple('' for _ in range(nargs if isinstance(nargs, int) else 1)) - else: - # Default single metavar suppression - kwargs['metavar'] = '' - super(SM, self).__init__(option_strings, dest, nargs=nargs, **kwargs) - - def __call__(self, parser, namespace, values, option_string=None): - # Simply set the value(s) in the namespace - if self.nargs is None or self.nargs == 0: - setattr(namespace, self.dest, values) # Directly set the value - else: - # Handle multiple values as a list - current_values = getattr(namespace, self.dest, []) - if not isinstance(current_values, list): - current_values = [current_values] # Ensure it is a list - current_values.append(values) - setattr(namespace, self.dest, current_values) # Append new values
    - -
    - -
    - - - - - -
    - -
    -
    -
    - -
    - - - - -
    -
    - -
    - -
    -
    -
    - - - - - -
    - - -
    - - \ No newline at end of file diff --git a/_modules/unravel/core/config.html b/_modules/unravel/core/config.html index 00ec71d7..a5d15dd9 100644 --- a/_modules/unravel/core/config.html +++ b/_modules/unravel/core/config.html @@ -389,7 +389,7 @@

    Source code for unravel.core.config

             - Attributes:
                 - verbose: A boolean flag to control verbosity of the application.
     
    -Notes:
    +Note:
         - The Config class uses the RawConfigParser from the configparser module to parse the configuration file.
         - The AttrDict class allows for convenient attribute access to dictionary keys.
         - The Configuration class can be extended to hold additional global settings as needed.
    diff --git a/_modules/unravel/core/help_formatter.html b/_modules/unravel/core/help_formatter.html
    new file mode 100644
    index 00000000..1b67434e
    --- /dev/null
    +++ b/_modules/unravel/core/help_formatter.html
    @@ -0,0 +1,840 @@
    +
    +
    +
    +
    +
    +
    +  
    +    
    +    
    +    unravel.core.help_formatter — UNRAVEL docs
    +  
    +  
    +  
    +  
    +  
    +  
    +  
    +
    +
    +
    +  
    +  
    +  
    +
    +
    +
    +    
    +    
    +    
    +    
    +  
    +  
    +  
    +
    +  
    +
    +    
    +    
    +    
    +    
    +    
    +    
    +    
    +    
    +    
    +    
    +    
    +    
    +    
    +    
    +    
    +    
    +  
    +  
    +  
    +  
    +  
    +  
    +
    +  
    +  
    +  
    +  
    +  
    + + + + + + + + + + +
    +
    +
    +
    +
    + +
    + +
    + + + + + +
    +
    + + + + + +
    + + + + + + + + + + + +
    + +
    + + +
    +
    + +
    +
    + +
    + +
    + + + + +
    + +
    + + +
    +
    + + + + + +
    + +

    Source code for unravel.core.help_formatter

    +#!/usr/bin/env python3
    +
    +"""
    +This script enhances the formatting and handling of argparse arguments by defining custom classes that improve 
    +the readability and usability of help messages, with a focus on suppressing metavar display and leveraging 
    +the Rich library for styled terminal output.
    +
    +Classes:
    +    - SuppressMetavar: A custom HelpFormatter class that suppresses the display of metavar for arguments and 
    +                       customizes the formatting of action invocations and epilog text.
    +    - SM: A custom argparse.Action class that manages argument values while suppressing metavar display across 
    +          all nargs configurations.
    +    - RichArgumentParser: An enhanced ArgumentParser that integrates custom help message formatting and 
    +                            handling, including filtering and styling of argparse help text.
    +    - CustomHelpAction: An argparse Action that displays a richly formatted help message, integrating the script’s 
    +                        docstring.
    +
    +Functions:
    +    - format_argparse_help: Processes and applies custom styles to argparse help text, highlighting flags, 
    +                            default values, and section headers with specific colors and styles.
    +    - format_docstring_for_terminal: Formats the script's docstring with Rich's styled output, improving readability 
    +                                     by highlighting sections, command names, and other key elements.
    +
    +Usage:
    +    The custom classes and functions can be used in any argparse-based script to suppress metavar display, 
    +    format help messages with Rich's styled output, and enhance the overall user experience.
    +
    +Example:
    +    import argparse
    +    from unravel.core.help_formatter import SuppressMetavar, SM, CustomArgumentRich
    +
    +    parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__)
    +
    +    reqs = parser.add_argument_group('Required arguments')
    +    parser.add_argument('-e', '--example', help='Example argument', action=SM)
    +    args = parser.parse_args()
    +
    +Note:
    +    - The `SuppressMetavar` class is designed to suppress metavar display and improve the formatting of epilog text.
    +    - The `SM` action ensures that metavar is consistently suppressed across different nargs configurations.
    +    - The `CustomArgumentRich` and `CustomHelpAction` provide enhanced help message handling, integrating 
    +      formatted docstrings and filtering out unwanted lines.
    +    - nargs='``+``' with action=SM: This combination causes issues when the terminal window is small. 
    +    - Use nargs='``*``' with action=SM if zero arguments are acceptable, or drop action=SM to avoid conflicts.
    +"""
    +
    +import argparse
    +import re
    +from rich import print
    +from rich.console import Console
    +from rich.text import Text
    +
    +
    +[docs] +class SuppressMetavar(argparse.HelpFormatter): + def __init__(self, prog): + super().__init__(prog, max_help_position=52) + + def _format_action_invocation(self, action): + if not action.option_strings: + metavar, = self._metavar_formatter(action, action.dest)(1) + return metavar + else: + parts = [] + if action.nargs == 0: + parts.extend(action.option_strings) + else: + for option_string in action.option_strings: + parts.append(option_string) + return ', '.join(parts)
    + + +
    +[docs] +class CustomHelpAction(argparse.Action): + def __init__(self, option_strings, dest=argparse.SUPPRESS, default=argparse.SUPPRESS, help=None, docstring=None): + self.docstring = docstring + super().__init__(option_strings=option_strings, dest=dest, default=default, nargs=0, help=help) + + def __call__(self, parser, namespace, values, option_string=None): + parser.print_help() + parser.exit()
    + + +
    +[docs] +class RichArgumentParser(argparse.ArgumentParser): + def __init__(self, *args, docstring=None, **kwargs): + super().__init__(*args, **kwargs) + self.docstring = docstring + # Automatically add the custom help action with the provided docstring + self.add_argument('-h', '--help', action=CustomHelpAction, docstring=self.docstring) + +
    +[docs] + def print_help(self, file=None): + # Print the __doc__ string if available + if self.docstring: + print(format_docstring_for_terminal(self.docstring)) + + # Capture the help output + help_output = self.format_help().strip() # Strip extra newlines from the raw help output + + # Filter out unwanted lines + filtered_output = self.filter_help_output(help_output) + + # Apply custom styling to the help text + styled_help_text = format_argparse_help(filtered_output) + + # Print the styled help text + console = Console() + console.print(styled_help_text) # No need to call .strip() on styled_help_text since it's a Text object
    + + +
    +[docs] + def filter_help_output(self, help_output): + lines = help_output.splitlines() + + # Filter out lines that start with 'usage:', 'options:', or contain '-h, --help' + filtered_lines = [ + line for line in lines if not line.startswith('usage:') and '-h, --help' not in line and not line.startswith('options:') + ] + + return '\n'.join(filtered_lines)
    + + +
    +[docs] + def format_usage(self): + # Override to suppress the usage line + return ''
    +
    + + +# Custom action class to suppress metavar across all nargs configurations +
    +[docs] +class SM(argparse.Action): + def __init__(self, option_strings, dest, nargs=None, **kwargs): + if nargs is not None: + kwargs.setdefault('metavar', '') + super(SM, self).__init__(option_strings, dest, nargs=nargs, **kwargs) + + def __call__(self, parser, namespace, values, option_string=None): + # If this action is for a single value (not expecting multiple values) + if self.nargs is None or self.nargs == 0: + setattr(namespace, self.dest, values) # Set the single value directly + else: + # If the action expects multiple values, handle it as a list + if isinstance(values, list): + setattr(namespace, self.dest, values) + else: + current_values = getattr(namespace, self.dest, []) + if not isinstance(current_values, list): + current_values = [current_values] + current_values.append(values) + setattr(namespace, self.dest, current_values)
    + + +
    +[docs] +def format_argparse_help(help_text): + """ + Apply rich formatting to the argparse help message. + + This function processes the help text generated by argparse and applies + custom styles using the Rich library. It colors the flags according to the + section they belong to (e.g., purple3 for "Required arguments:"). + + grey50 style is applied to lines containing "Default:" to make them less prominent. + + Parameters + ---------- + help_text : str + The help text generated by argparse. + + Returns + ------- + Text + A `rich.text.Text` object containing the formatted help text. + """ + # Regex to find flags (like -i, --input) + flag_pattern = r"(\s--[\w-]+|\s-\w+)" + + # Regex to identify lines with unwanted patterns + unwanted_pattern = r"\[-\w+|\[-\w+" + + # Split the help text into lines + lines = help_text.splitlines() + + # Initialize the final formatted text + final_text = Text() + + current_style = None + + for line in lines: + # Skip unwanted lines + if re.search(unwanted_pattern, line): + continue + + # Style "Required arguments:" with purple3 + if line.strip().startswith("Required arguments:"): + current_style = "purple3" + styled_line = Text(line, style="bold purple3") + elif line.strip().startswith("Optional"): + current_style = "bright_blue" + styled_line = Text(line, style="bold bright_blue") + elif line.strip().startswith("General"): + current_style = "green" + styled_line = Text(line, style="bold green") + elif "Default:" in line: + # Apply grey50 style to lines with "Default:" + line = re.sub(flag_pattern, fr"[{current_style}]\1[/]", line) + # Make "Default:" and the entire following text bold + line = re.sub(r"(Default:\s*.*)", r"[bold]\1[/]", line) + styled_line = Text.from_markup(line, style="grey50") + else: + # Apply the current style to the flags using regex + if current_style: + line = re.sub(flag_pattern, fr"[{current_style}]\1[/]", line) + # Default styling for other lines + styled_line = Text.from_markup(line) + + # Append the styled line to the final text + final_text.append(styled_line) + final_text.append("\n") + + return final_text
    + + +
    +[docs] +def format_docstring_for_terminal(docstring): + """ + Apply rich formatting to a docstring for enhanced terminal display. + + This function processes a docstring by applying various formatting styles + using the Rich library. It handles sections like script descriptions, + usage examples, command arguments, and specific keywords like "Input:", + "Output", "Note", "Prereq", and "Next". Additionally, it applies + special styles to text enclosed in double backticks and command-line flags. + + Parameters + ---------- + docstring : str + The original docstring to be formatted. + + Returns + ------- + Text + A `rich.text.Text` object containing the formatted text. + + Notes + ----- + The function applies the following styles: + - "UNRAVEL" is styled with a custom multi-colored format. + - Script description lines are styled as bold. + - Section headers starting with "Prereq", "Input", "Output", "Note", "Next", and "Usage" are colored. + - Command names enclosed in double backticks or appearing in usage examples are styled as bold bright magenta. + - Required arguments (before the first optional argument) are styled as purple3. + - Optional arguments (within square brackets) are styled as bright blue. + - Required command-line flags (e.g., `-m`, `--input`) are styled as bold in the required arg section. + - General arguments like `[-d list of paths]`, `[-p sample??]`, and `[-v]` in the Usage section are styled as green. + - The Usage section should be last and is separated by a horizontal line. + """ + + # Replace ``*`` or `*` with a plain asterisk * + docstring = re.sub(r'``\*``', '*', docstring) + docstring = re.sub(r'`\*`', '*', docstring) + + # Replace <asterisk> with a plain asterisk * + docstring = docstring.replace('<asterisk>', '*') + + def apply_section_style(line): + """Apply the appropriate style based on the section header.""" + if line.strip().startswith("Prereqs:"): + return Text(line, style="red") + elif line.strip().startswith("Input"): + return Text(line, style="dark_orange") + elif line.strip().startswith("Output"): + return Text(line, style="gold1") + elif line.strip().startswith("Note"): + return Text(line, style="green") + elif line.strip().startswith("Next"): + return Text(line, style="grey50") + elif line.strip().startswith("Usage"): + return Text(line, style="bold cyan") + return Text(line) # Return the line as is if no match is found + + # Regex to find text enclosed in double backticks, excluding cases like ``*`` + command_pattern = r"``(?!\*)(.*?)``" + + # Regex to find flags (like -m, --input, -abc) + flag_pattern = r"(\s-\w[\w-]*|\s--\w[\w-]*)" + + # Regex to find general arguments in usage + general_arg_pattern = r"(\[-d list of paths\]|\[-p sample\?\?\]|\[-v\])" + + # Prepare the final formatted text + final_text = Text() + + # Split the docstring into lines for processing + lines = docstring.splitlines() + + # Extract the first command in the docstring + command = None + for line in lines: + match = re.search(command_pattern, line) + if match: + command = match.group(1) # group(1) contains the text inside the backticks + break + + # Flags to manage the sections + in_description = True + separator_added = False + processing_usage = False + + for line in lines: + # Skip lines that start with "---" + if line.strip().startswith("---"): + continue + + if in_description: + # Style "UNRAVEL" with custom formatting in the description + line = re.sub(command_pattern, r"[bold bright_magenta]\1[/]", line) + line = line.replace("UNRAVEL", "[red1]U[/][dark_orange]N[/][gold1]R[/][green]A[/][bright_blue]V[/][purple3]E[/][bright_magenta]L[/]") + + # Apply bold style to the script description lines + styled_line = Text.from_markup(line, style="bold") + + # Check if this line is the start of a section + if line.strip().startswith(("Usage", "Input", "Output", "Note", "Prereq", "Next")): + in_description = False + # Process the section header + styled_line = apply_section_style(line) + if line.strip().startswith("Usage"): + processing_usage = True + if not separator_added: + # Add a separator line before the first Usage section + console_width = Console().size.width + separator = Text("─" * console_width, style="dim") + final_text.append(separator) + final_text.append("\n\n") + separator_added = True + + else: + # Apply section styles to headers + if line.strip().startswith(("Input", "Output", "Note", "Prereq", "Next")): + styled_line = apply_section_style(line) + elif line.strip().startswith("Usage"): + processing_usage = True + styled_line = apply_section_style(line) + if not separator_added: + # Add a separator line before the first Usage section + console_width = Console().size.width + separator = Text("─" * console_width, style="dim") + final_text.append(separator) + final_text.append("\n\n") + separator_added = True + elif processing_usage: + # We're in a Usage section and processing subsequent lines + + # Ensure the command name is styled correctly at the start of the line + line = line.replace(f" {command}", f"[bold bright_magenta]{command}[/]") + + # Identify the start of optional arguments + tuple_parts = re.split(r'(\s\[-\w|\s\[--\w)', line, 1) + if len(tuple_parts) == 3: + required_part, optional_start, optional_part = tuple_parts + required_part = required_part.strip() + optional_part = (optional_start + optional_part).strip() + else: + required_part = line.strip() + optional_part = "" + + # Style the flags as bold + required_part = re.sub(flag_pattern, r"[bold]\1[/]", required_part) + optional_part = re.sub(flag_pattern, r"[bold]\1[/]", optional_part) + + # Split the optional part into general arguments and others + general_args = re.findall(general_arg_pattern, optional_part) + non_general_args = re.sub(general_arg_pattern, '', optional_part).strip() + + # Style the required arguments (before the bracket) as purple3 + styled_required = Text.from_markup(f"[purple3]{required_part}[/]") if required_part else Text() + + # Style the non-general optional arguments as bright_blue + styled_optional = Text.from_markup(f"[bright_blue]{non_general_args}[/]") if non_general_args else Text() + + # Style the general arguments as green + styled_general = Text() + for arg in general_args: + styled_general.append(Text.from_markup(f"[green]{arg}[/] ")) + styled_general.rstrip() # Remove the trailing space + + # Combine the styled parts together + styled_line = Text() + styled_line.append(styled_required) + if styled_optional: + styled_line.append(" ") + styled_line.append(styled_optional) + if styled_general: + styled_line.append(" ") + styled_line.append(styled_general) + else: + # Apply command formatting within the section + line = re.sub(command_pattern, r"[bold bright_magenta]\1[/]", line) + styled_line = Text.from_markup(line) + + # Add the processed line to the final text + final_text.append(styled_line) + final_text.append("\n") + + return final_text
    + +
    + +
    + + + + + +
    + +
    +
    +
    + +
    + + + + +
    +
    + +
    + +
    +
    +
    + + + + + +
    + + +
    + + \ No newline at end of file diff --git a/_modules/unravel/core/img_tools.html b/_modules/unravel/core/img_tools.html index 8a595f67..cb9932b2 100644 --- a/_modules/unravel/core/img_tools.html +++ b/_modules/unravel/core/img_tools.html @@ -462,27 +462,6 @@

    Source code for unravel.core.img_tools

         return flipped_img
    -# @print_func_name_args_times() -# def pixel_classification(tif_dir, ilastik_project, output_dir, ilastik_log=None): -# """Segment tif series with Ilastik.""" -# tif_dir = str(tif_dir) -# tif_list = sorted(glob(f"{tif_dir}/*.tif")) -# ilastik_project = str(ilastik_project) -# output_dir_ = str(output_dir) -# cmd = [ -# 'run_ilastik.sh', -# '--headless', -# '--project', ilastik_project, -# '--export_source', 'Simple Segmentation', -# '--output_format', 'tif', -# '--output_filename_format', f'{output_dir}/{{nickname}}.tif', -# ] + tif_list -# if not Path(output_dir_).exists(): -# if ilastik_log == None: -# subprocess.run(cmd) -# else: -# subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) -
    [docs] @print_func_name_args_times() @@ -506,14 +485,12 @@

    Source code for unravel.core.img_tools

             '--output_format', 'tif',
             '--output_filename_format', f'{str(output_dir)}/{{nickname}}.tif'
         ] + tif_list
    -
    -    print("\n    Running Ilastik with command:\n", ' '.join(cmd))
    -    # result = subprocess.run(cmd, capture_output=True, text=True)
    +    print("\n    Running Ilastik with command:\n", ' '.join(cmd[:10]), ' '.join(tif_list[:3]), f'[default bold]...\n')
         result = subprocess.run(cmd, capture_output=True, text=True, shell=(os.name == 'nt'))
         if result.returncode != 0:
             print("\n    Ilastik failed with error:\n", result.stderr)
         else:
    -        print("\n    Ilastik completed successfully.\n")
    + print(" Ilastik completed successfully.")
    diff --git a/_modules/unravel/core/utils.html b/_modules/unravel/core/utils.html index d1acb2ae..be0d2d4c 100644 --- a/_modules/unravel/core/utils.html +++ b/_modules/unravel/core/utils.html @@ -377,10 +377,17 @@

    Source code for unravel.core.utils

         Import the functions and decorators to enhance your scripts.
     
     Examples:
    -    - from unravel.core.utils import load_config, get_samples, initialize_progress_bar, print_func_name_args_times, load_text_from_file copy_files
    -    - config = load_config("path/to/config.ini")
    -    - samples = get_samples(exp_dir_paths=["/path/to/exp1", "/path/to/exp2"])
    -    - progress, task_id = initialize_progress_bar(len(samples), task_message="[red]Processing samples...")
    +    >>> # Import the functions and decorators
    +    >>> from unravel.core.utils import load_config, get_samples, initialize_progress_bar, print_func_name_args_times, load_text_from_file, copy_files
    +
    +    >>> # Load the configuration from a file
    +    >>> config = load_config("path/to/config.ini")
    +
    +    >>> # Get a list of sample directories
    +    >>> samples = get_samples(["path/to/dir1", "path/to/dir2"], dir_pattern="sample??", verbose=True)
    +    
    +    >>> # Initialize a progress bar
    +    >>> progress, task_id = initialize_progress_bar(len(samples), task_message="[red]Processing samples...")
     
     """
     
    @@ -402,7 +409,7 @@ 

    Source code for unravel.core.utils

     
     from unravel.core.config import Configuration, Config
     
    -# TODO: Also output commands with default args to .verbose_command_log.txt or .command_log.txt.
    +# TODO: Also output commands with default args to .verbose_command_log.txt or .command_log.txt. Rename to unravel_command_log.txt
     
     
     # Configuration loading
    @@ -421,64 +428,103 @@ 

    Source code for unravel.core.utils

     # Sample list 
     
    [docs] -def get_samples(sample_dir_list=None, sample_dir_pattern="sample??", exp_dir_paths=None): +def get_samples(dir_list=None, dir_pattern="sample??", verbose=False): """ - Return a list of full paths to sample directories (dirs) based on the dir list, pattern, and/or experiment dirs. - - This function searches for dirs matching a specific pattern (default "sample??") within the given experiment dirs. - If a sample_dir_list is provided, it uses the full paths from the list or resolves them if necessary. - If an exp_dir_paths list is provided, it searches for sample dirs within each experiment directory. - If both sample_dir_list and exp_dir_paths are provided, paths are added to the list from both sources. - - Parameters: - - sample_dir_list (list of str or None): Explicit list of dirs to include. Can be dir names or absolute paths. - - sample_dir_pattern (str): Pattern to match dirs within experiment dirs. Defaults to "sample??". - - exp_dir_paths (list of str or None): List of paths to experiment dirs where subdirs matching the sample_dir_pattern will be searched for. - - Returns: - - list of pathlib.Path: Full paths to all found sample dirs. + Finds and returns paths to directories matching a specified pattern within given directories + or, if none are provided, the current working directory. + + Parameters + ---------- + dir_list : list of Path or str, or Path or str, optional + A list of paths (as Path objects or strings) to sample?? directories + or directories that may contain subdirectories matching the `dir_pattern`. + + dir_pattern : str, optional + A pattern to match directory names, default is "sample??", where "?" is a wildcard matching a + single character. This pattern is used to identify directories of interest. + + dir_pattern : str, optional + A Unix shell-style wildcard pattern used by `fnmatch` to match directory names. + Default is "sample??", where each "?" matches a single character. + + verbose : bool, optional + If True, prints the found directories, grouped by their parent directories. + Default is False. + + Returns + ------- + samples : list of Path + A list of resolved Path objects pointing to directories that match the `dir_pattern`. + + Notes + ----- + - If no directories are provided via `dir_list`, the function searches the current working directory. + - If a directory (e.g., the current dir) matches the `dir_pattern`, + it is included in the results and not searched for subdirectories. + + Examples + -------- + >>> sample_paths = get_samples() # Search the current working directory for sample?? directories + >>> sample_paths = get_samples([path1, path2], dir_pattern="sample???") # Search path1 and path2 for sample??? directories """ samples = [] - # Ensure sample_dir_list is a list - if isinstance(sample_dir_list, str): - sample_dir_list = [sample_dir_list] # Convert string to list + if isinstance(dir_list, (str, Path)): + dir_list = [Path(dir_list)] + + if dir_list: + for dir_name in dir_list: + dir_path = Path(dir_name).resolve() - # Add full paths of dirs from sample_dir_list that exist - if sample_dir_list: - for dir_name in sample_dir_list: - dir_path = Path(dir_name) - dir_path = dir_path if dir_path.is_absolute() else dir_path.resolve() if dir_path.is_dir(): - samples.append(dir_path) - - # Search for sample folders within each experiment directory in exp_dir_paths and add their full paths - if exp_dir_paths: - for exp_dir in exp_dir_paths: - exp_path = Path(exp_dir).resolve() - if exp_path.is_dir(): - found_samples = [ - d.resolve() for d in exp_path.iterdir() - if d.is_dir() and fnmatch(d.name, sample_dir_pattern) - ] - samples.extend(found_samples) - - # If no dirs have been added yet, search the current working directory for dirs matching the pattern - if not samples: - cwd_samples = [ - d.resolve() for d in Path.cwd().iterdir() - if d.is_dir() and fnmatch(d.name, sample_dir_pattern) - ] - samples.extend(cwd_samples) - - # Use the current working directory as the fallback if no samples found - if not samples: - samples.append(Path.cwd()) + # Check if the provided path itself matches the pattern + if fnmatch(dir_path.name, dir_pattern): + samples.append(dir_path) + else: + # Search for subdirectories matching the pattern + sample_dirs = sorted([d.resolve() for d in dir_path.iterdir() if d.is_dir() and fnmatch(d.name, dir_pattern)]) + samples.extend(sample_dirs) + else: + print(f"\n [red1]Directory {dir_path} does not exist or is not a directory\n") + else: + # If the cwd matches the pattern, add it to the list of samples + cwd = Path.cwd() + if fnmatch(cwd.name, dir_pattern): + samples.append(cwd.resolve()) + else: + # Search the current working directory for matching dirs + cwd_samples = sorted([d.resolve() for d in cwd.iterdir() if d.is_dir() and fnmatch(d.name, dir_pattern)]) + samples.extend(cwd_samples) + + # Final fallback to add the CWD if nothing else was found + if not samples: + samples.append(cwd.resolve()) + + if verbose: + # Create an ordered list of unique parent directories + uniq_parent_dirs = [] + for dir_name in dir_list or [Path.cwd()]: + dir_path = Path(dir_name).resolve() + parent_dir = dir_path.parent if fnmatch(dir_path.name, dir_pattern) else dir_path + if parent_dir not in uniq_parent_dirs: + uniq_parent_dirs.append(parent_dir) + + for sample_dir in samples: + sample_parent = sample_dir.parent if sample_dir.parent != parent_dir else parent_dir + if sample_parent not in uniq_parent_dirs: + uniq_parent_dirs.append(sample_parent) + + # Print the found directories grouped by their parent directories in order + for parent_dir in uniq_parent_dirs: + print(f"\n [bold gold1]get_samples[/]() found these directories in [bright_black bold]{parent_dir}[/]:\n") + for sample_dir in samples: + if sample_dir.parent == parent_dir: + print(f" [bold orange_red1]{sample_dir.name}") + print() return samples
    - # Progress bar functions
    [docs] diff --git a/_modules/unravel/image_io/h5_to_tifs.html b/_modules/unravel/image_io/h5_to_tifs.html index 6ec57ba0..9ab1c381 100644 --- a/_modules/unravel/image_io/h5_to_tifs.html +++ b/_modules/unravel/image_io/h5_to_tifs.html @@ -356,23 +356,19 @@

    Source code for unravel.image_io.h5_to_tifs

     """
     Use ``io_h5_to_tifs`` from UNRAVEL to load a h5/hdf5 image and save it as tifs.
     
    -Usage:
    -------
    -    io_h5_to_tifs -i path/image.h5 -t autofl
    -
     Inputs:
    -    - image.h5 either from -i path/image.h5 or largest <asterisk>.h5 in cwd
    +    - image.h5 either from -i path/image.h5 or largest `*`.h5 in cwd
         - This assumes that the first dataset in the hdf5 file has the highest resolution.
     
     Outputs:
    -    - ./<tif_dir_out>/slice_<asterisk>.tif series
    +    - ./<tif_dir_out>/slice_`*`.tif series
         - ./parameters/metadata (text file)
     
    -Next command:
    -    - ``reg_prep`` for registration
    +Usage:
    +------
    +    io_h5_to_tifs -i path/image.h5 -t autofl [-v]
     """
     
    -import argparse
     import glob
     import os
     import h5py
    @@ -382,7 +378,8 @@ 

    Source code for unravel.image_io.h5_to_tifs

     from rich.traceback import install
     from tifffile import imwrite 
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
    +
     from unravel.core.config import Configuration
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg
     
    @@ -390,11 +387,15 @@ 

    Source code for unravel.image_io.h5_to_tifs

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input', help='path/image.h5', action=SM) - parser.add_argument('-t', '--tif_dir', help='Name of output folder for outputting tifs', action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='path/image.h5', required=True, action=SM) + reqs.add_argument('-t', '--tif_dir', help='Name of output folder for outputting tifs', required=True, action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/image_io/img_to_npy.html b/_modules/unravel/image_io/img_to_npy.html index 53673590..9e70be33 100644 --- a/_modules/unravel/image_io/img_to_npy.html +++ b/_modules/unravel/image_io/img_to_npy.html @@ -358,14 +358,14 @@

    Source code for unravel.image_io.img_to_npy

     
     Usage: 
     ------
    -    io_img_to_npy -i path/to/image.czi -o path/to/image.npy
    +    io_img_to_npy -i path/to/image.czi -o path/to/image.npy [-ao zyx] [-v]
     """
     
    -import argparse
     import numpy as np
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
    +
     from unravel.core.config import Configuration
     from unravel.core.img_io import load_3D_img
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg
    @@ -373,12 +373,18 @@ 

    Source code for unravel.image_io.img_to_npy

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input', required=True, help='Input image file path (.czi, .nii.gz, .tif)', action=SM) - parser.add_argument('-o', '--output', required=True, help='Output HDF5 file path', action=SM) - parser.add_argument('-ao', '--axis_order', help='Axis order for the image (default: zyx)', default='zyx', action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity.', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', required=True, help='Input image file path (.czi, .nii.gz, .tif)', action=SM) + reqs.add_argument('-o', '--output', required=True, help='Output HDF5 file path', action=SM) + + opts = parser.add_argument_group('Optional args') + opts.add_argument('-ao', '--axis_order', help='Axis order for the image (default: zyx)', default='zyx', action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/image_io/img_to_points.html b/_modules/unravel/image_io/img_to_points.html index 36e321f3..6a253228 100644 --- a/_modules/unravel/image_io/img_to_points.html +++ b/_modules/unravel/image_io/img_to_points.html @@ -356,27 +356,27 @@

    Source code for unravel.image_io.img_to_points

    """ Use `io_img_to_points` from UNRAVEL to convert non-zero voxels in a 3D image to a set of points, accounting for voxel intensity (e.g., number of detections). -Usage: ------- - io_img_to_points -i path/image [-o path/points.csv] [-a path/atlas_image.nii.gz] [-v] - Input image types: - .czi, .nii.gz, .ome.tif series, .tif series, .h5, .zarr + - .czi, .nii.gz, .ome.tif series, .tif series, .h5, .zarr Output: - A CSV file where each row represents a point corresponding to a detection in the 3D image. - The coordinates (x, y, z) are derived from the voxel locations in the image, with multiple points generated for voxels with intensities greater than 1. - An optional 'Region_ID' column is added based on the corresponding atlas image. + +Usage: +------ + io_img_to_points -i path/image [-a path/atlas_image.nii.gz] [-o path/points.csv] [-v] """ -import argparse from pathlib import Path import numpy as np import pandas as pd from rich import print from rich.traceback import install -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.img_io import load_3D_img from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg @@ -384,12 +384,18 @@

    Source code for unravel.image_io.img_to_points

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input', help='Path to the input 3D image.', required=True, action=SM) - parser.add_argument('-a', '--atlas_img', help="Path to the atlas image matching -i for adding a 'Region_ID' column to the CSV.", action=SM) - parser.add_argument('-o', '--output', help='Path to save the output points (CSV format). Default: path/input_points.csv', default=None, action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity.', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='Path to the input 3D image.', required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-a', '--atlas_img', help="Path to the atlas image matching -i for adding a 'Region_ID' column to the CSV.", action=SM) + opts.add_argument('-o', '--output', help='Path to save the output points (CSV format). Default: path/input_points.csv', default=None, action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()

    diff --git a/_modules/unravel/image_io/io_img.html b/_modules/unravel/image_io/io_img.html index b73bfb15..fa78d083 100644 --- a/_modules/unravel/image_io/io_img.html +++ b/_modules/unravel/image_io/io_img.html @@ -356,21 +356,21 @@

    Source code for unravel.image_io.io_img

     """
     Use ``io_img`` from UNRAVEL to load a 3D image, [get metadata], and save as the specified image type.
     
    -Usage: 
    -------
    -    io_img -i path/to/image.czi -o path/to/tif_dir
    -
     Input image types:
         .czi, .nii.gz, .ome.tif series, .tif series, .h5, .zarr
     
     Output image types: 
         .nii.gz, .tif series, .zarr, .h5
    +
    +Usage: 
    +------
    +    io_img -i path/to/image.czi -x 3.5232 -z 6 [-c 0] [-o path/to/tif_dir] [-d np.uint8] [-r path/to/reference.nii.gz] [-ao zyx] [-v]
     """
     
    -import argparse
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
    +
     from unravel.core.config import Configuration
     from unravel.core.img_io import load_3D_img, save_3D_img
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg
    @@ -378,17 +378,23 @@ 

    Source code for unravel.image_io.io_img

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input', help='path/image .czi, path/img.nii.gz, or path/tif_dir', required=True, action=SM) - parser.add_argument('-x', '--xy_res', help='xy resolution in um', required=True, type=float, action=SM) - parser.add_argument('-z', '--z_res', help='z resolution in um', required=True, type=float, action=SM) - parser.add_argument('-c', '--channel', help='.czi channel number. Default: 0 for autofluo', default=0, type=int, action=SM) - parser.add_argument('-o', '--output', help='Output path (image type determined by extension). Default: None', default=None, action=SM) - parser.add_argument('-d', '--dtype', help='Data type for .nii.gz. Default: None. Options: np.uint8, np.uint16, np.float32.', default=None, action=SM) - parser.add_argument('-r', '--reference', help='Reference image for .nii.gz metadata. Default: None', default=None, action=SM) - parser.add_argument('-ao', '--axis_order', help='Default: xyz. (other option: zyx)', default='xyz', action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='path/image .czi, path/img.nii.gz, or path/tif_dir', required=True, action=SM) + reqs.add_argument('-x', '--xy_res', help='xy resolution in um', required=True, type=float, action=SM) + reqs.add_argument('-z', '--z_res', help='z resolution in um', required=True, type=float, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-c', '--channel', help='.czi channel number. Default: 0 for autofluo', default=0, type=int, action=SM) + opts.add_argument('-o', '--output', help='Output path (image type determined by extension). Default: None', default=None, action=SM) + opts.add_argument('-d', '--dtype', help='Data type for .nii.gz. Default: None. Options: np.uint8, np.uint16, np.float32.', default=None, action=SM) + opts.add_argument('-r', '--reference', help='Reference image for .nii.gz metadata. Default: None', default=None, action=SM) + opts.add_argument('-ao', '--axis_order', help='Default: xyz. (other option: zyx)', default='xyz', action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/image_io/io_nii.html b/_modules/unravel/image_io/io_nii.html index 6d4d8077..318b3970 100644 --- a/_modules/unravel/image_io/io_nii.html +++ b/_modules/unravel/image_io/io_nii.html @@ -356,32 +356,35 @@

    Source code for unravel.image_io.io_nii

     """
     Use ``io_nii`` from UNRAVEL to convert the data type of a .nii.gz image and optionally scale the data.
     
    -Usage:
    -------
    -    io_nii -i path/img.nii.gz -d float32
    +Inputs:
    +    - .nii.gz image
     
    -Usage for z-score scaling (if 8 bit is needed):
    ------------------------------------------------
    -    io_nii -i path/img.nii.gz -d uint8 -z
    +Outputs:
    +    - .nii.gz image with the specified data type and scaling.
     
     Possible numpy data types: 
         - Unsigned Integer: uint8, uint16, uint32, uint64
         - Signed Integer: int8, int16, int32, int64
         - Floating Point: float32, float64
     
    -With --scale, the min intensity becomes dtype min and max intensity becomes dtype max. Every other intensity is scaled accordingly.
    -With --binary, the image is binarized (0 or 1).
    -With --zscore, the range of z-scored data from -3 to 3 is converted to 0 to 255.
    -With --fixed_scale, the data is scaled using the provided min and max values.
    +Note:
    +    - With --scale, the min intensity becomes dtype min and max intensity becomes dtype max. Every other intensity is scaled accordingly.
    +    - With --binary, the image is binarized (0 or 1).
    +    - With --zscore, the range of z-scored data from -3 to 3 is converted to 0 to 255.
    +    - With --fixed_scale, the data is scaled using the provided min and max values.
    +
    +Usage:
    +------
    +    io_nii -i path/img.nii.gz -d float32 [-o path/new_img.nii.gz] [-f min,max | -s | -b | -z] [-v]
     """
     
    -import argparse
     import nibabel as nib
     import numpy as np
     from rich import print
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
    +
     from unravel.core.config import Configuration 
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, print_func_name_args_times
     
    @@ -389,16 +392,22 @@ 

    Source code for unravel.image_io.io_nii

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input', help='path/img.nii.gz', required=True, action=SM) - parser.add_argument('-d', '--data_type', help='Data type of output. For example: uint16 (numpy conventions)', required=True, action=SM) - parser.add_argument('-o', '--output', help='path/new_img.nii.gz. Default: path/img_dtype.nii.gz', action=SM) - parser.add_argument('-f', '--fixed_scale', help='Scale data using fixed min and max values. Supply as "min,max"', default=None) - parser.add_argument('-s', '--scale', help='Scale the data to the range of the new data type', action='store_true', default=False) - parser.add_argument('-b', '--binary', help='Convert to binary image.', action='store_true', default=False) - parser.add_argument('-z', '--zscore', help='Convert the range of z-scored data (use uint8 data type).', action='store_true', default=False) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='path/img.nii.gz', required=True, action=SM) + reqs.add_argument('-d', '--data_type', help='Data type of output. For example: uint16 (numpy conventions)', required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-o', '--output', help='path/new_img.nii.gz. Default: path/img_dtype.nii.gz', action=SM) + opts.add_argument('-f', '--fixed_scale', help='Scale data using fixed min and max values. Supply as "min,max"', default=None) + opts.add_argument('-s', '--scale', help='Scale the data to the range of the new data type', action='store_true', default=False) + opts.add_argument('-b', '--binary', help='Convert to binary image.', action='store_true', default=False) + opts.add_argument('-z', '--zscore', help='Convert the range of z-scored data (use uint8 data type).', action='store_true', default=False) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/image_io/metadata.html b/_modules/unravel/image_io/metadata.html index 3fc0ceca..a5b89cbb 100644 --- a/_modules/unravel/image_io/metadata.html +++ b/_modules/unravel/image_io/metadata.html @@ -356,33 +356,37 @@

    Source code for unravel.image_io.metadata

     """
     Use ``io_metadata`` from UNRAVEL to save x/y and z voxel sizes in microns as well as image dimensions to a metadata file in each sample directory.
     
    -Run this command from an experiment, sample?? folder, or provide -e/--exp_paths and -d/--dirs arguments to specify the experiment and sample directories.
    -
    -Usage for when metadata is extractable:
    ----------------------------------------
    -    io_metadata -i rel_path/full_res_img (can use glob patterns)
    -
    -Usage for when metadata is not extractable:
    --------------------------------------------
    -    io_metadata -i tif_dir -x 3.5232 -z 6  # Use if metadata not extractable
    -
     Inputs:
         - .czi, .nii.gz, .h5, or TIF series (path should be relative to ./sample??)
     
     Outputs:
         - ./parameters/metadata.txt (path should be relative to ./sample??)
     
    +Note:
    +    - If -d is not provided, the current directory is used to search for sample?? dirs to process. 
    +    - If the current dir is a sample?? dir, it will be processed.
    +    - If -d is provided, the specified dirs and/or dirs containing sample?? dirs will be processed.
    +    - If -p is not provided, the default pattern for dirs to process is 'sample??'.
    +
     Next command:
    -    - ``reg_prep`` for registration
    +    - ``reg_prep`` for prepping autofluo images for registration
    +
    +Usage for when metadata is extractable:
    +---------------------------------------
    +    io_metadata -i rel_path/full_res_img [-m parameters/metadata.txt] [-d space-separated list of paths] [-p pattern] [-v]
    +
    +Usage for when metadata is not extractable:
    +-------------------------------------------
    +    io_metadata -i tif_dir -x 3.5232 -z 6 [-m parameters/metadata.txt] [-d space-separated list of paths] [-p pattern] [-v]
     """
     
    -import argparse
     from pathlib import Path
     import cv2
     from rich.live import Live
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
    +
     from unravel.core.config import Configuration
     from unravel.core.img_io import load_3D_img, resolve_path, save_metadata_to_file
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, get_samples, initialize_progress_bar
    @@ -391,16 +395,21 @@ 

    Source code for unravel.image_io.metadata

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-e', '--exp_paths', help='List of experiment dir paths w/ sample?? dirs to process.', nargs='*', default=None, action=SM) - parser.add_argument('-p', '--pattern', help='Pattern for sample?? dirs. Use cwd if no matches.', default='sample??', action=SM) - parser.add_argument('-d', '--dirs', help='List of sample?? dir names or paths to dirs to process', nargs='*', default=None, action=SM) - parser.add_argument('-i', '--input', help='path/full_res_img (path relative to ./sample??)', required=True, action=SM) - parser.add_argument('-m', '--metad_path', help='path/metadata.txt. Default: parameters/metadata.txt', default="parameters/metadata.txt", action=SM) - parser.add_argument('-x', '--xy_res', help='xy resolution in um', type=float, default=None, action=SM) - parser.add_argument('-z', '--z_res', help='z resolution in um', type=float, default=None, action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='path/full_res_img (path relative to ./sample??). Can use glob patterns.', required=True, action=SM) + + opts = parser.add_argument_group('Optional args') + opts.add_argument('-m', '--metad_path', help='path/metadata.txt. Default: parameters/metadata.txt', default="parameters/metadata.txt", action=SM) + opts.add_argument('-x', '--xy_res', help='xy resolution in um', type=float, default=None, action=SM) + opts.add_argument('-z', '--z_res', help='z resolution in um', type=float, default=None, action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-d', '--dirs', help='Paths to sample?? dirs and/or dirs containing them (space-separated) for batch processing. Default: current dir', nargs='*', default=None, action=SM) + general.add_argument('-p', '--pattern', help='Pattern for directories to process. Default: sample??', default='sample??', action=SM) + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    @@ -434,11 +443,11 @@

    Source code for unravel.image_io.metadata

         Configuration.verbose = args.verbose
         verbose_start_msg()
     
    -    samples = get_samples(args.dirs, args.pattern, args.exp_paths)
    +    sample_paths = get_samples(args.dirs, args.pattern, args.verbose)
     
    -    progress, task_id = initialize_progress_bar(len(samples), "[red]Processing samples...")
    +    progress, task_id = initialize_progress_bar(len(sample_paths), "[red]Processing samples...")
         with Live(progress):
    -        for sample_path in samples:
    +        for sample_path in sample_paths:
     
                 # Resolve path to image
                 img_path = resolve_path(sample_path, path_or_pattern=args.input)
    diff --git a/_modules/unravel/image_io/nii_hd.html b/_modules/unravel/image_io/nii_hd.html
    index 4133456d..8a796fa3 100644
    --- a/_modules/unravel/image_io/nii_hd.html
    +++ b/_modules/unravel/image_io/nii_hd.html
    @@ -358,26 +358,30 @@ 

    Source code for unravel.image_io.nii_hd

     
     Usage:
     ------
    -    io_nii_hd -i path/img.nii.gz
    +    io_nii_hd -i path/img.nii.gz [-v]
     """
     
    -import argparse
     import nibabel as nib
     import numpy as np
     from rich import print
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
    +
     from unravel.core.config import Configuration
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg
     
     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input', help='path/img.nii.gz', required=True, action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='path/img.nii.gz', required=True, action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/image_io/nii_info.html b/_modules/unravel/image_io/nii_info.html index 3c759e38..b467a372 100644 --- a/_modules/unravel/image_io/nii_info.html +++ b/_modules/unravel/image_io/nii_info.html @@ -358,16 +358,15 @@

    Source code for unravel.image_io.nii_info

     
     Usage:
     ------
    -    io_nii_info -i path/img.nii.gz
    +    io_nii_info -i path/img.nii.gz [-v]
     """
     
    -import argparse
     import nibabel as nib
     import numpy as np
     from rich import print
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SM, SuppressMetavar
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
     from unravel.core.config import Configuration
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg
     
    @@ -375,10 +374,14 @@ 

    Source code for unravel.image_io.nii_info

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input', help='path/img.nii.gz', action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity.', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='path/img.nii.gz', action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/image_io/nii_to_tifs.html b/_modules/unravel/image_io/nii_to_tifs.html index 6129bc69..11114d82 100644 --- a/_modules/unravel/image_io/nii_to_tifs.html +++ b/_modules/unravel/image_io/nii_to_tifs.html @@ -358,18 +358,17 @@

    Source code for unravel.image_io.nii_to_tifs

    Usage:
     ------
    -    io_nii_to_tifs -i path/image.nii.gz -o path/output_dir
    -
    +    io_nii_to_tifs -i path/image.nii.gz -o path/output_dir [-v]
     """
     
    -import argparse
     import os
     import nibabel as nib
     import numpy as np
     import tifffile as tif
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
    +
     from unravel.core.config import Configuration
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg
     
    @@ -377,11 +376,15 @@ 

    Source code for unravel.image_io.nii_to_tifs

     [docs]
     def parse_args():
    -    parser = argparse.ArgumentParser(formatter_class=SuppressMetavar)
    -    parser.add_argument('-i', '--input', help='image.nii.gz', action=SM)
    -    parser.add_argument('-o', '--output_dir', help='Name of output folder', action=SM)
    -    parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False)
    -    parser.epilog = __doc__
    +    parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__)
    +
    +    reqs = parser.add_argument_group('Required arguments')
    +    reqs.add_argument('-i', '--input', help='image.nii.gz', required=True, action=SM)
    +    reqs.add_argument('-o', '--output_dir', help='Name of output folder', required=True, action=SM)
    +
    +    general = parser.add_argument_group('General arguments')
    +    general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False)
    +
         return parser.parse_args()
    @@ -414,7 +417,9 @@

    Source code for unravel.image_io.nii_to_tifs

    Configuration.verbose = args.verbose
         verbose_start_msg()
         
    -    nii_to_tifs(args.input, args.output_dir)
    + nii_to_tifs(args.input, args.output_dir) + + verbose_end_msg()
    diff --git a/_modules/unravel/image_io/nii_to_zarr.html b/_modules/unravel/image_io/nii_to_zarr.html index 49affc7a..99d60d40 100644 --- a/_modules/unravel/image_io/nii_to_zarr.html +++ b/_modules/unravel/image_io/nii_to_zarr.html @@ -358,17 +358,17 @@

    Source code for unravel.image_io.nii_to_zarr

    Usage:
     ------
    -    io_nii_to_zarr -i path/img.nii.gz -o path/img.zarr
    +    io_nii_to_zarr -i path/img.nii.gz -o path/img.zarr [-v]
     """
     
    -import argparse
     import dask.array as da
     import nibabel as nib
     import numpy as np
     import zarr
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
    +
     from unravel.core.config import Configuration
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, print_func_name_args_times
     
    @@ -376,11 +376,17 @@ 

    Source code for unravel.image_io.nii_to_zarr

     [docs]
     def parse_args():
    -    parser = argparse.ArgumentParser(formatter_class=SuppressMetavar)
    -    parser.add_argument('-i', '--input', help='path/image.nii.gz', required=True, action=SM)
    -    parser.add_argument('-o', '--output', help='path/image.zarr', default=None, action=SM)
    -    parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False)
    -    parser.epilog = __doc__
    +    parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__)
    +
    +    reqs = parser.add_argument_group('Required arguments')
    +    reqs.add_argument('-i', '--input', help='path/image.nii.gz', required=True, action=SM)
    +
    +    opts = parser.add_argument_group('Optional arguments')
    +    opts.add_argument('-o', '--output', help='path/image.zarr', default=None, action=SM)
    +
    +    general = parser.add_argument_group('General arguments')
    +    general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False)
    +
         return parser.parse_args()
    diff --git a/_modules/unravel/image_io/points_to_img.html b/_modules/unravel/image_io/points_to_img.html index 2e5ec4ed..79130681 100644 --- a/_modules/unravel/image_io/points_to_img.html +++ b/_modules/unravel/image_io/points_to_img.html @@ -356,10 +356,6 @@

    Source code for unravel.image_io.points_to_img

    """ Use `io_points_to_img` from UNRAVEL to convert a set of points (coordinates) to a 3D image, accounting for the number of detections at each voxel. -Usage: ------- - io_points_to_img -i path/points.csv -ri path/ref_image [-o path/image] [-thr 20000 or -uthr 20000] [-v] - Input: - A CSV file where each row represents a point corresponding to a detection in the 3D image. - The columns should include 'x', 'y', 'z', and 'Region_ID' (e.g., from ``rstats`` or ``io_img_to_points``). @@ -367,19 +363,22 @@

    Source code for unravel.image_io.points_to_img

    Output image types: .nii.gz, .tif series, .h5, .zarr -Notes: +Note: - Points outside the brain (i.e., 'Region_ID' == 0) are excluded. - If the input CSV has a 'count' column, use ``utils_points_compressor`` to unpack the points before running this script. + +Usage: +------ + io_points_to_img -i path/points.csv -ri path/ref_image [-o path/image] [-thr 20000 or -uthr 20000] [-v] """ -import argparse from pathlib import Path import numpy as np import pandas as pd from rich import print from rich.traceback import install -from unravel.core.argparse_utils import SM, SuppressMetavar +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM from unravel.core.config import Configuration from unravel.core.img_io import load_3D_img, save_3D_img from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, print_func_name_args_times @@ -388,14 +387,20 @@

    Source code for unravel.image_io.points_to_img

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input', help='path/input.csv w/ columns: x, y, z, Region_ID', required=True, action=SM) - parser.add_argument('-ri', '--ref_img', help='Path to a reference image for output image shape and saving.', required=True, action=SM) - parser.add_argument('-o', '--output', help='Path to save the output image. Default: path/input.nii.gz', default=None, action=SM) - parser.add_argument('-thr', '--thresh', help='Exclude region IDs below this threshold (e.g., 20000 to obtain left hemisphere data)', type=float, action=SM) - parser.add_argument('-uthr', '--upper_thr', help='Exclude region IDs above this threshold (e.g., 20000 to obtain right hemisphere data)', type=float, action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity.', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='path/input.csv w/ columns: x, y, z, Region_ID', required=True, action=SM) + reqs.add_argument('-ri', '--ref_img', help='Path to a reference image for output image shape and saving.', required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-o', '--output', help='Path to save the output image. Default: path/input.nii.gz', default=None, action=SM) + opts.add_argument('-thr', '--thresh', help='Exclude region IDs below this threshold (e.g., 20000 to obtain left hemisphere data)', type=float, action=SM) + opts.add_argument('-uthr', '--upper_thr', help='Exclude region IDs above this threshold (e.g., 20000 to obtain right hemisphere data)', type=float, action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()

    @@ -489,8 +494,8 @@

    Source code for unravel.image_io.points_to_img

    img : numpy.ndarray A 3D image created from the input points. Each voxel's value represents the number of points that fall within that voxel. - Notes: - ------ + Note: + ----- - If the point coordinates are in physical or resampled space, ensure that they are appropriately scaled and aligned with the desired image grid before calling this function. - If the count in a voxel exceeds the maximum value for `uint8` (255), the image's data type is diff --git a/_modules/unravel/image_io/reorient_nii.html b/_modules/unravel/image_io/reorient_nii.html index d0b17080..b4a343da 100644 --- a/_modules/unravel/image_io/reorient_nii.html +++ b/_modules/unravel/image_io/reorient_nii.html @@ -356,12 +356,11 @@

    Source code for unravel.image_io.reorient_nii

    """ Use ``io_reorient_nii`` from UNRAVEL to set the orientation of a .nii.gz or its affine matrix. -Usage: ------- - io_reorient_nii -i image.nii.gz -t PIR -a -z +Input: + - path/input_image.nii.gz Output: - - The new .nii.gz file with the new orientation (e.g., image_PIR.nii.gz or image_PIR_applied.nii.gz) + - A .nii.gz images with the new orientation (e.g., image_PIR.nii.gz or image_PIR_applied.nii.gz) The axis codes are: R: Right / L: Left @@ -413,16 +412,20 @@

    Source code for unravel.image_io.reorient_nii

    Third letter determination: -The 3rd column has a non-zero value at the 1st row, so the 3rd letter is either R or L (1st letter of the default 'RAS' orientation code). -Since the value is positive, the 3rd letter is R + +Usage: +------ + io_reorient_nii -i image.nii.gz -t PIR [-o image_PIR.nii.gz] [-z] [-a] [-fc 2] [-v] """ -import argparse import nibabel as nib import numpy as np from nibabel.orientations import axcodes2ornt, ornt_transform, io_orientation, aff2axcodes, apply_orientation from rich import print from rich.traceback import install -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg @@ -430,15 +433,21 @@

    Source code for unravel.image_io.reorient_nii

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input', help='path/img.nii.gz', required=True, action=SM) - parser.add_argument('-o', '--output', help='path/img.nii.gz', required=True, action=SM) - parser.add_argument('-t', '--target_ort', help='Target orientation axis codes (e.g., RAS)', required=True, action=SM) - parser.add_argument('-z', '--zero_origin', help='Provide flag to zero the origin of the affine matrix.', action='store_true', default=False) - parser.add_argument('-a', '--apply', help='Provide flag to apply the new orientation to the ndarray data.', action='store_true', default=False) - parser.add_argument('-fc', '--form_code', help='Set the sform and qform codes for spatial coordinate type (1 = scanner; 2 = aligned)', type=int, default=None) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='path/img.nii.gz', required=True, action=SM) + reqs.add_argument('-t', '--target_ort', help='Target orientation axis codes (e.g., RAS)', required=True, action=SM) + + opts = parser.add_argument_group('Optional args') + reqs.add_argument('-o', '--output', help='path/img.nii.gz', required=True, action=SM) + opts.add_argument('-z', '--zero_origin', help='Provide flag to zero the origin of the affine matrix.', action='store_true', default=False) + opts.add_argument('-a', '--apply', help='Provide flag to apply the new orientation to the ndarray data.', action='store_true', default=False) + opts.add_argument('-fc', '--form_code', help='Set the sform and qform codes for spatial coordinate type (1 = scanner; 2 = aligned)', type=int, default=None) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/image_io/tif_to_tifs.html b/_modules/unravel/image_io/tif_to_tifs.html index 86e0f2b9..edf94b0a 100644 --- a/_modules/unravel/image_io/tif_to_tifs.html +++ b/_modules/unravel/image_io/tif_to_tifs.html @@ -356,22 +356,21 @@

    Source code for unravel.image_io.tif_to_tifs

    """
     Use ``io_tif_to_tifs`` from UNRAVEL to load a 3D .tif image and save it as tifs.
     
    -Usage:
    -------
    -    io_tif_to_tifs -i <path/image.tif> -t 488
    -
    -Inputs: 
    -    - image.tif # either from -i path/image.tif or largest <asterisk>.tif in cwd
    +Input: 
    +    - image.tif (either from -i path/image.tif or largest `*`.tif in cwd)
     
     Outputs:
    -    - ./<tif_dir_out>/slice_<asterisk>.tif series
    +    - ./<tif_dir_out>/slice_`*`.tif series
         - ./parameters/metadata (text file)
     
     Next command: 
    -    ``reg_prep`` for registration
    +    ``reg_prep`` to prep autofluo images registration
    +
    +Usage:
    +------
    +    io_tif_to_tifs -i <path/image.tif> -t 488 [-v]
     """
     
    -import argparse
     import glob
     import os
     import numpy as np
    @@ -381,7 +380,8 @@ 

    Source code for unravel.image_io.tif_to_tifs

    from tifffile import imwrite
     import tifffile 
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
    +
     from unravel.core.config import Configuration
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg
     
    @@ -389,14 +389,20 @@ 

    Source code for unravel.image_io.tif_to_tifs

     [docs]
     def parse_args():
    -    parser = argparse.ArgumentParser(formatter_class=SuppressMetavar)
    -    parser.add_argument('-i', '--input', help='path/image.tif', action=SM)
    -    parser.add_argument('-t', '--tif_dir', help='Name of output folder for outputting tifs', action=SM)
    -    parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False)
    -    parser.epilog = __doc__
    +    parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__)
    +
    +    reqs = parser.add_argument_group('Required arguments')
    +    reqs.add_argument('-i', '--input', help='path/image.tif', required=True, action=SM)
    +    reqs.add_argument('-t', '--tif_dir', help='Name of output folder for outputting tifs', required=True, action=SM)
    +
    +    general = parser.add_argument_group('General arguments')
    +    general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False)
    +
         return parser.parse_args()
    +# TODO: Could remove find_largest_tif_file() and use glob matching only. +# TODO: Could keep metadata functions specific to io_metadata and the img_io module.
    [docs] @@ -511,11 +517,7 @@

    Source code for unravel.image_io.tif_to_tifs

    file.write(f"Voxel size: {xy_res:.4f}x{xy_res:.4f}x{z_res:.4f} µm^3")
     
         # Save as tifs 
    -    if args.tif_dir is None:
    -        print("    [red1]The tif_dir argument was not provided. Please specify the directory.")
    -        import sys ; sys.exit()
    -    else:
    -        tifs_output_path = Path(".", args.tif_dir)
    +    tifs_output_path = Path(args.tif_dir)
         
         save_as_tifs(img, tifs_output_path)
     
    diff --git a/_modules/unravel/image_io/zarr_to_nii.html b/_modules/unravel/image_io/zarr_to_nii.html
    index af889c4a..94c2992a 100644
    --- a/_modules/unravel/image_io/zarr_to_nii.html
    +++ b/_modules/unravel/image_io/zarr_to_nii.html
    @@ -356,22 +356,22 @@ 

    Source code for unravel.image_io.zarr_to_nii

    """
     Use ``io_zarr_to_nii`` from UNRAVEL to convert an image.zarr to an image.nii.gz.
     
    +Note:
    +    - Outputs RAS orientation w/o respect to anatomical orientation
    +    - Scaling not preserved
    +
     Usage:
     ------
    -    io_zarr_to_nii -i path/img.zarr -o path/img.nii.gz
    -
    -Notes:
    -    - Outputs RAS orientation
    -    - Scaling not preserved
    +    io_zarr_to_nii -i path/img.zarr -o path/img.nii.gz [-v]    
     """
     
    -import argparse
     import nibabel as nib
     import numpy as np
     import zarr
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
    +
     from unravel.core.config import Configuration
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, print_func_name_args_times
     
    @@ -379,11 +379,17 @@ 

    Source code for unravel.image_io.zarr_to_nii

     [docs]
     def parse_args():
    -    parser = argparse.ArgumentParser(formatter_class=SuppressMetavar)
    -    parser.add_argument('-i', '--input', help='path/image.zarr', required=True, action=SM)
    -    parser.add_argument('-o', '--output', help='path/image.nii.gz', action=SM)
    -    parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False)
    -    parser.epilog = __doc__
    +    parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__)
    +
    +    reqs = parser.add_argument_group('Required arguments')
    +    reqs.add_argument('-i', '--input', help='path/image.zarr', required=True, action=SM)
    +
    +    opts = parser.add_argument_group('Optional arguments')
    +    opts.add_argument('-o', '--output', help='path/image.nii.gz', action=SM)
    +
    +    general = parser.add_argument_group('General arguments')
    +    general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False)
    +
         return parser.parse_args()
    diff --git a/_modules/unravel/image_tools/DoG.html b/_modules/unravel/image_tools/DoG.html index 68619db7..7154995a 100644 --- a/_modules/unravel/image_tools/DoG.html +++ b/_modules/unravel/image_tools/DoG.html @@ -356,10 +356,6 @@

    Source code for unravel.image_tools.DoG

     """
     Use ``img_DoG`` from UNRAVEL to apply Difference of Gaussians to a single image.
     
    -Usage: 
    -------
    -    img_DoG -i input.tif -g1 1.0 -g2 2.0
    -
     Difference of Gaussians:
         - Sigma1 and sigma2 are the standard deviations for the first and second Gaussian blurs
         - Simga2 (the larger blur) should be ~ 1.0 to 1.5 times the radius of these features of interest
    @@ -373,15 +369,19 @@ 

    Source code for unravel.image_tools.DoG

         - 2D DoG is not implemented in vstats_prep. 
         - DoG could be added to vstats_prep in the future if needed. 
         - 3D spatial averaging and 2D rolling ball background subtraction are used in vstats_prep instead.
    +
    +Usage: 
    +------
    +    img_DoG -i input.tif -g1 1.0 -g2 2.0 [-o output.tif] [-v]
     """
     
    -import argparse
     import cv2
     import numpy as np
     from rich import print
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
    +
     from unravel.core.config import Configuration
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg
     
    @@ -389,13 +389,19 @@ 

    Source code for unravel.image_tools.DoG

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input', help='Path to the input TIFF file.', required=True, action=SM) - parser.add_argument('-o', '--output', help='Path to save the output TIFF file.', default=None, action=SM) - parser.add_argument('-g1', '--sigma1', help='Sigma for the first Gaussian blur in DoG (targets noise)', default=None, required=True, type=float) - parser.add_argument('-g2', '--sigma2', help='Sigma for the second Gaussian blur in DoG (targets signal).', default=None, required=True, type=float) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='Path to the input TIFF file.', required=True, action=SM) + reqs.add_argument('-g1', '--sigma1', help='Sigma for the first Gaussian blur in DoG (targets noise)', default=None, required=True, type=float) + reqs.add_argument('-g2', '--sigma2', help='Sigma for the second Gaussian blur in DoG (targets signal).', default=None, required=True, type=float) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-o', '--output', help='Path to save the output TIFF file.', default=None, action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/image_tools/atlas/relabel_nii.html b/_modules/unravel/image_tools/atlas/relabel_nii.html index 2cfbfe54..55d9dd17 100644 --- a/_modules/unravel/image_tools/atlas/relabel_nii.html +++ b/_modules/unravel/image_tools/atlas/relabel_nii.html @@ -356,12 +356,20 @@

    Source code for unravel.image_tools.atlas.relabel_nii

    """ Use ``atlas_relabel`` from UNRAVEL to convert intensities (e.g., atlas label IDs) based on a CSV. +Inputs: + - old_image.nii.gz: Lable image with original intensities. + - input.csv: CSV with old IDs in column 1 and new IDs in column 2. + +Outputs: + - new_image.nii.gz: Image with relabeled intensities. + - relabel_nii_volume_summary_old_labels.csv: Summary of the volume for each label before the replacement. + - relabel_nii_volume_summary_new_labels.csv: Summary of the volume for each label after the replacement. + Usage: ------ - atlas_relabel -i path/old_image.nii.gz -o path/new_image.nii.gz -ic path/input.csv -oc volume_summary -odt uint16 + atlas_relabel -i path/old_image.nii.gz -o path/new_image.nii.gz -ci path/input.csv [-vols] [-odt uint16] [-v] """ -import argparse import numpy as np import nibabel as nib import pandas as pd @@ -370,21 +378,28 @@

    Source code for unravel.image_tools.atlas.relabel_nii

    from rich.traceback import install from unravel.core.config import Configuration -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input', help='path/old_image.nii.gz', required=True, action=SM) - parser.add_argument('-o', '--output', help='path/new_image.nii.gz', required=True, action=SM) - parser.add_argument('-ic', '--csv_input', help='path/input.csv w/ old IDs in column 1 and new IDs in column 2', required=True, action=SM) - parser.add_argument('-oc', '--csv_output', help='Optionally provide prefix to output label volume summaries (e.g., volume_summary)', default=None, action=SM) - parser.add_argument('-odt', '--data_type', help='Output data type. Default: uint16', default="uint16", action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='path/old_image.nii.gz', required=True, action=SM) + reqs.add_argument('-ci', '--csv_input', help='path/input.csv w/ old IDs in column 1 and new IDs in column 2', required=True, action=SM) + reqs.add_argument('-o', '--output', help='path/new_image.nii.gz', required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-vols', '--volumes', help='Provide flag to output label volume summaries', default=None, action=SM) + opts.add_argument('-odt', '--data_type', help='Output data type. Default: uint16', default="uint16", action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    @@ -435,8 +450,8 @@

    Source code for unravel.image_tools.atlas.relabel_nii

    new_labels, counts_new_labels = np.unique(new_img_array, return_counts=True) volume_summary_old_labels = pd.DataFrame({columns[0]: old_labels, 'voxel_count': counts_old_labels}) volume_summary_new_labels = pd.DataFrame({columns[1]: new_labels, 'voxel_count': counts_new_labels}) - volume_summary_old_labels.to_csv(f'{args.csv_output}_old_labels.csv', index=False) - volume_summary_new_labels.to_csv(f'{args.csv_output}_new_labels.csv', index=False) + volume_summary_old_labels.to_csv(f'relabel_nii_volume_summary_old_labels.csv', index=False) + volume_summary_new_labels.to_csv(f'relabel_nii_volume_summary_new_labels.csv', index=False) verbose_end_msg()
    diff --git a/_modules/unravel/image_tools/atlas/wireframe.html b/_modules/unravel/image_tools/atlas/wireframe.html index a79c8f29..0ad2837b 100644 --- a/_modules/unravel/image_tools/atlas/wireframe.html +++ b/_modules/unravel/image_tools/atlas/wireframe.html @@ -356,19 +356,19 @@

    Source code for unravel.image_tools.atlas.wireframe

    """ Use ``atlas_wireframe`` from UNRAVEL to generate a thin wireframe image from an atlas NIfTI file. -Usage: ------- - atlas_wireframe -i path.atlas.nii.gz +Outputs: + - path/atlas_img_W.nii.gz (Wireframe image) + - path/atlas_img_W_IDs.nii.gz (Wireframe image with region IDs) -Outlines are generated outside the regions and not inside smaller regions. -For regions at the surface of the brain, the outlines are internalized. +Note: + - Outlines are generated outside the regions and not inside smaller regions. + - For regions at the surface of the brain, the outlines are internalized. -Outputs: - - path/atlas_img_W.nii.gz # Wireframe image - - path/atlas_img_W_IDs.nii.gz # Wireframe image with region IDs +Usage: +------ + atlas_wireframe -i path.atlas.nii.gz [-wo path/atlas_img_W.nii.gz] [-id path/atlas_img_W_IDs.nii.gz] [-v] """ -import argparse import nibabel as nib import numpy as np import pandas as pd @@ -376,7 +376,8 @@

    Source code for unravel.image_tools.atlas.wireframe

    from rich.traceback import install from scipy.ndimage import binary_dilation, binary_erosion -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg @@ -384,12 +385,18 @@

    Source code for unravel.image_tools.atlas.wireframe

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input', help='path/atlas_img.nii.gz', required=True, action=SM) - parser.add_argument('-wo', '--wire_output', help='Wireframe image output path. Default: path/atlas_img_W.nii.gz', action=SM) - parser.add_argument('-id', '--id_output', help='Wireframe image with atlas IDs output path. Default: path/atlas_img_W_IDs.nii.gz', action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='path/atlas_img.nii.gz', required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-wo', '--wire_output', help='Wireframe image output path. Default: path/atlas_img_W.nii.gz', action=SM) + opts.add_argument('-id', '--id_output', help='Wireframe image with atlas IDs output path. Default: path/atlas_img_W_IDs.nii.gz', action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/image_tools/avg.html b/_modules/unravel/image_tools/avg.html index ac32fb6f..7de54c5d 100644 --- a/_modules/unravel/image_tools/avg.html +++ b/_modules/unravel/image_tools/avg.html @@ -358,17 +358,17 @@

    Source code for unravel.image_tools.avg

     
     Usage:
     ------
    -    img_avg -i "<asterisk>.nii.gz" -o avg.nii.gz
    +    img_avg -i "<asterisk>.nii.gz" -o avg.nii.gz [-v]
     """
     
    -import argparse
     import numpy as np
     import nibabel as nib
     from pathlib import Path
     from rich import print
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
    +
     from unravel.core.config import Configuration
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg
     
    @@ -376,11 +376,15 @@ 

    Source code for unravel.image_tools.avg

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--inputs', help='Input file(s) or pattern(s) to process. Default is "*.nii.gz".', nargs='*', default=['*.nii.gz'], action=SM) - parser.add_argument('-o', '--output', help='Output file name. Default is "avg.nii.gz".', default='avg.nii.gz', action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-i', '--inputs', help='Input file(s) or pattern(s) to process. Default is "*.nii.gz".', nargs='*', default=['*.nii.gz'], action=SM) + opts.add_argument('-o', '--output', help='Output file name. Default is "avg.nii.gz".', default='avg.nii.gz', action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/image_tools/bbox.html b/_modules/unravel/image_tools/bbox.html index 494e35e9..b3987986 100644 --- a/_modules/unravel/image_tools/bbox.html +++ b/_modules/unravel/image_tools/bbox.html @@ -358,14 +358,14 @@

    Source code for unravel.image_tools.bbox

     
     Usage:
     ------
    -    img_bbox -i path/img -o path/bounding_boxes
    +    img_bbox -i path/img [-o path/outer_bbox.txt] [-c cluster_ID] [-v]
     """
     
    -import argparse
     from pathlib import Path
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
    +
     from unravel.core.config import Configuration
     from unravel.core.img_io import load_3D_img
     from unravel.core.img_tools import find_bounding_box, cluster_IDs
    @@ -375,13 +375,19 @@ 

    Source code for unravel.image_tools.bbox

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input', help='path/img.czi, path/img.nii.gz, or path/tif_dir', action=SM, required=True) - parser.add_argument('-o', '--output', help='path to output dir. Default: bounding_boxes', action=SM) - parser.add_argument('-ob', '--outer_bbox', help='path/outer_bbox.txt (bbox for voxels > 0)', action=SM) - parser.add_argument('-c', '--cluster', help='Cluster intensity to get bbox and crop', action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='path/img.czi, path/img.nii.gz, or path/tif_dir', action=SM, required=True) + + opts = parser.add_argument_group('Optional args') + opts.add_argument('-o', '--output', help='path to output dir. Default: bounding_boxes', action=SM) + opts.add_argument('-ob', '--outer_bbox', help='path/outer_bbox.txt (bbox for voxels > 0)', action=SM) + opts.add_argument('-c', '--cluster', help='Cluster intensity to get bbox and crop', action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/image_tools/extend.html b/_modules/unravel/image_tools/extend.html index 00f10aff..54f0be51 100644 --- a/_modules/unravel/image_tools/extend.html +++ b/_modules/unravel/image_tools/extend.html @@ -357,17 +357,17 @@

    Source code for unravel.image_tools.extend

     Use ``img_extend`` from UNRAVEL to load a 3D image, extend one side, and save it as tifs
     
     Usage:
    -    img_extend -i ochann -o ochann_extended -e 100 -s back -v
    +    img_extend -i ochann -o ochann_extended -s front -e 100 [-d list of paths] [-p sample??] [-v]
     """
     
    -import argparse
     from pathlib import Path
     import numpy as np
     from rich import print
     from rich.live import Live
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
    +
     from unravel.core.config import Configuration
     from unravel.core.img_io import load_3D_img, save_as_tifs
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, print_func_name_args_times, initialize_progress_bar, get_samples
    @@ -376,15 +376,19 @@ 

    Source code for unravel.image_tools.extend

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-p', '--pattern', help='Pattern for folders to process. If no matches, use current dir. Default: sample??', default='sample??', action=SM) - parser.add_argument('--dirs', help='List of folders to process. Overrides --pattern', nargs='*', default=None, action=SM) - parser.add_argument('-i', '--input', help='path/image or path/image_dir', default=None, action=SM) - parser.add_argument('-o', '--out_dir_name', help="Output folder name.", required=True, action=SM) - parser.add_argument('-s', '--side', help="Side to extend. Options: 'front', 'back', 'left', 'right', 'top', 'bottom'. Default: 'front'", default='front', action=SM) - parser.add_argument('-e', '--extension', help="Number of voxels to extend", type=int, action=SM) - parser.add_argument('-v', '--verbose', help='Enable verbose mode', action='store_true') - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='path/image or path/image_dir', required=True, action=SM) + reqs.add_argument('-o', '--out_dir_name', help="Output folder name.", required=True, action=SM) + reqs.add_argument('-s', '--side', help="Side to extend. Options: 'front', 'back', 'left', 'right', 'top', 'bottom'.", required=True, action=SM) + reqs.add_argument('-e', '--extension', help="Number of voxels to extend", type=int, required=True, action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-d', '--dirs', help='Paths to sample?? dirs and/or dirs containing them (space-separated) for batch processing. Default: current dir', nargs='*', default=None, action=SM) + general.add_argument('-p', '--pattern', help='Pattern for directories to process. Default: sample??', default='sample??', action=SM) + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    @@ -436,24 +440,13 @@

    Source code for unravel.image_tools.extend

         Configuration.verbose = args.verbose
         verbose_start_msg()
     
    -    samples = get_samples(args.dirs, args.pattern)
    +    sample_paths = get_samples(args.dirs, args.pattern, args.verbose)
     
    -    if samples == ['.']:
    -        samples[0] = Path.cwd().name
    -
    -    progress, task_id = initialize_progress_bar(len(samples), "[red]Processing samples...")
    +    progress, task_id = initialize_progress_bar(len(sample_paths), "[red]Processing samples...")
         with Live(progress):
    -        for sample in samples:
    -
    -            # Resolve path to tif directory
    -            cwd = Path(".").resolve()
    -
    -            sample_path = Path(sample).resolve() if sample != cwd.name else Path().resolve()
    +        for sample_path in sample_paths:
     
    -            if args.input:
    -                input_path = Path(args.input).resolve()
    -            else:
    -                input_path = Path(sample_path, args.chann_name).resolve()
    +            input_path = Path(args.input).resolve()
     
                 # Load image
                 img = load_3D_img(input_path, return_res=False)
    diff --git a/_modules/unravel/image_tools/max.html b/_modules/unravel/image_tools/max.html
    index 9afe95e4..c47337ca 100644
    --- a/_modules/unravel/image_tools/max.html
    +++ b/_modules/unravel/image_tools/max.html
    @@ -358,16 +358,16 @@ 

    Source code for unravel.image_tools.max

     
     Usage: 
     ------
    -    img_max -i path/image.nii.gz
    +    img_max -i path/image.nii.gz [-v]
     """
     
    -import argparse
     import nibabel as nib
     import numpy as np
     from rich import print
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
    +
     from unravel.core.config import Configuration
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg
     
    @@ -375,9 +375,14 @@ 

    Source code for unravel.image_tools.max

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input', help='path/image.nii.gz', default=None, action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='path/image.nii.gz', required=True, action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/image_tools/pad.html b/_modules/unravel/image_tools/pad.html index 8af298d8..30f39750 100644 --- a/_modules/unravel/image_tools/pad.html +++ b/_modules/unravel/image_tools/pad.html @@ -358,17 +358,16 @@

    Source code for unravel.image_tools.pad

     
     Usage:
     ------
    -    img_pad -i reg_inputs/autofl_50um.nii.gz
    +    img_pad -i reg_inputs/autofl_50um.nii.gz [-ort RAS] [-r reg_inputs/autofl_50um.nii.gz] [-o reg_inputs/autofl_50um_pad.nii.gz] [-zero] [-v]
     """
     
    -import argparse
     import nibabel as nib
     import numpy as np
     from rich.traceback import install
     
     from unravel.image_io.nii_info import nii_axis_codes
     from unravel.image_io.reorient_nii import reorient_nii
    -from unravel.core.argparse_utils import SM, SuppressMetavar
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
     from unravel.core.config import Configuration
     from unravel.core.img_tools import pad
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg
    @@ -377,14 +376,20 @@ 

    Source code for unravel.image_tools.pad

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input', help='path/img.nii.gz', required=True, action=SM) - parser.add_argument('-ort', '--ort_code', help='3 letter orientation code of fixed image if not set in fixed_img (e.g., RAS)', action=SM) - parser.add_argument('-r', '--ref_nii', help='Reference image for setting the orientation code', action=SM) - parser.add_argument('-o', '--output', help='path/img.nii.gz. Default: None (saves as path/img_pad.nii.gz) ', default=None, action=SM) - parser.add_argument('-zero', '--zero_origin', help='Set the origin to zero in the affine matrix. Default: False', action='store_true', default=False) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='path/img.nii.gz', required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-ort', '--ort_code', help='3 letter orientation code of fixed image if not set in fixed_img (e.g., RAS)', action=SM) + opts.add_argument('-r', '--ref_nii', help='Reference image for setting the orientation code', action=SM) + opts.add_argument('-o', '--output', help='path/img.nii.gz. Default: None (saves as path/img_pad.nii.gz) ', default=None, action=SM) + opts.add_argument('-zero', '--zero_origin', help='Set the origin to zero in the affine matrix. Default: False', action='store_true', default=False) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/image_tools/rb.html b/_modules/unravel/image_tools/rb.html index 33efd39b..2fc7eff1 100644 --- a/_modules/unravel/image_tools/rb.html +++ b/_modules/unravel/image_tools/rb.html @@ -356,26 +356,23 @@

    Source code for unravel.image_tools.rb

     """
     Use ``img_rb`` from UNRAVEL to perform rolling ball background subtraction on a TIFF file.
     
    -Usage:
    -------
    -    img_rb -i input.tif -rb 4 
    -
    -Rolling ball subtraction:
    -    - Radius should be ~ 1.0 to 2.0 times the size of the features of interest
    +Note:
    +    - Radius for rolling ball subtraction should be ~ 1.0 to 2.0 times the size of the features of interest
         - Larger radii will remove more background, but may also remove some of the features of interest
         - Smaller radii will remove less background, but may leave some background noise
     
    -To do: 
    -    - Add support for other image types and 3D images
    +Usage:
    +------
    +    img_rb -i input.tif -rb 4 [-o output.tif] [-v]
     """
     
    -import argparse
     import cv2
     import numpy as np
     from rich import print
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
    +
     from unravel.core.config import Configuration
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg
     
    @@ -383,12 +380,18 @@ 

    Source code for unravel.image_tools.rb

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input', help='Path to the input TIFF file.', required=True, action=SM) - parser.add_argument('-o', '--output', help='Path to save the output TIFF file.', default=None, action=SM) - parser.add_argument('-rb', '--rb_radius', help='Radius of rolling ball in pixels.', default=None, type=int, action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='Path to the input TIFF file.', required=True, action=SM) + reqs.add_argument('-rb', '--rb_radius', help='Radius of rolling ball in pixels.', required=True, type=int, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-o', '--output', help='Path to save the output TIFF file.', default=None, action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/image_tools/resample.html b/_modules/unravel/image_tools/resample.html index decfd9ff..90edd467 100644 --- a/_modules/unravel/image_tools/resample.html +++ b/_modules/unravel/image_tools/resample.html @@ -358,14 +358,13 @@

    Source code for unravel.image_tools.resample

    Usage:
     ------
    -    img_resample -i input_image.nii.gz -res target_res [-zo zoom_order] [-o output_image.nii.gz] [-v]
    +    img_resample -i image.nii.gz -tr 50 [-zo 0] [-o image_resampled.nii.gz] [-v]
     """
     
    -import argparse
     import nibabel as nib
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SM, SuppressMetavar
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
     from unravel.core.config import Configuration
     from unravel.core.img_tools import resample_nii
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg
    @@ -374,13 +373,19 @@ 

    Source code for unravel.image_tools.resample

     [docs]
     def parse_args():
    -    parser = argparse.ArgumentParser(formatter_class=SuppressMetavar)
    -    parser.add_argument('-i', '--input', help='path/input_image.nii.gz', required=True, action=SM)
    -    parser.add_argument('-tr', '--target_res', help='Target resolution in microns for resampling', required=True, type=float, action=SM)
    -    parser.add_argument('-zo', '--zoom_order', help='SciPy zoom order. Default: 0 (nearest-neighbor). Use 1 for linear interpolation.', default=0, type=int, action=SM)
    -    parser.add_argument('-o', '--output', help='path/output_image.nii.gz. Default: None (saves as path/input_image_resampled.nii.gz)', default=None, action=SM)
    -    parser.add_argument('-v', '--verbose', help='Increase verbosity.', action='store_true', default=False)
    -    parser.epilog = __doc__
    +    parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__)
    +
    +    reqs = parser.add_argument_group('Required arguments')
    +    reqs.add_argument('-i', '--input', help='path/input_image.nii.gz', required=True, action=SM)
    +    reqs.add_argument('-tr', '--target_res', help='Target resolution in microns for resampling', required=True, type=float, action=SM)
    +
    +    opts = parser.add_argument_group('Optional arguments')
    +    opts.add_argument('-zo', '--zoom_order', help='SciPy zoom order. Default: 0 (nearest-neighbor). Use 1 for linear interpolation.', default=0, type=int, action=SM)
    +    opts.add_argument('-o', '--output', help='path/output_image.nii.gz. Default: None (saves as path/input_image_resampled.nii.gz)', default=None, action=SM)
    +
    +    general = parser.add_argument_group('General arguments')
    +    general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False)
    +
         return parser.parse_args()
    diff --git a/_modules/unravel/image_tools/resample_points.html b/_modules/unravel/image_tools/resample_points.html index b68a8b72..341d89e1 100644 --- a/_modules/unravel/image_tools/resample_points.html +++ b/_modules/unravel/image_tools/resample_points.html @@ -356,22 +356,19 @@

    Source code for unravel.image_tools.resample_points

    """ Use `img_resample_points` from UNRAVEL to resample a set of points (coordinates) and optionally convert them to an image, accounting for the number of detections at each voxel. -Usage: ------- - img_resample_points -i path/points.csv -ri path/ref_image.nii.gz -cr 3.52 3.52 6 -tr 50 [-co path/resampled_points.csv] [-io path/resampled_image.nii.gz] [-thr 20000 or -uthr 20000] [-v] - Input image types: .czi, .nii.gz, .ome.tif series, .tif series, .h5, .zarr -Output image types: - .nii.gz, .tif series, .h5, .zarr - Outputs: + - Output image types: .nii.gz, .tif series, .h5, .zarr - A CSV file where each row represents a resampled point corresponding to a detection in the 3D image. - A 3D image where each voxel contains the number of detections at that location. + +Usage: +------ + img_resample_points -i path/points.csv -ri path/ref_image.nii.gz -cr 3.52 3.52 6 -tr 50 [-co path/resampled_points.csv] [-io path/resampled_image.nii.gz] [-thr 20000 or -uthr 20000] [-v] """ -import argparse import numpy as np import pandas as pd from pathlib import Path @@ -379,7 +376,8 @@

    Source code for unravel.image_tools.resample_points

    from rich.traceback import install -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.img_io import load_3D_img, save_3D_img from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg @@ -389,17 +387,23 @@

    Source code for unravel.image_tools.resample_points

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input', help='CSV w/ columns: x, y, z, Region_ID (e.g., from ``rstats``)', required=True, action=SM) - parser.add_argument('-ri', '--ref_img', help='Path to a reference image .nii.gz for setting the output image resolution and shape [and saving if .nii.gz output].', required=True, action=SM) - parser.add_argument('-cr', '--current_res', help="Current resolution in micrometers (e.g., 3.52 3.52 6 for anisotropic or 10 for isotropic).", nargs='*', required=True, type=float, action=SM) - parser.add_argument('-tr', '--target_res', help="Target resolution in micrometers (e.g., 50 for isotropic).", required=True, type=float, action=SM) - parser.add_argument('-co', '--csv_output', help="Optional: Path to save resampled points in a CSV.", action=SM) - parser.add_argument('-io', '--img_output', help="Optional: Path to save resampled points as an image.", action=SM) - parser.add_argument('-thr', '--thresh', help='Exclude region IDs below this threshold (e.g., 20000 to obtain left hemisphere data)', type=float, action=SM) - parser.add_argument('-uthr', '--upper_thr', help='Exclude region IDs above this threshold (e.g., 20000 to obtain right hemisphere data)', type=float, action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity.', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='CSV w/ columns: x, y, z, Region_ID (e.g., from ``rstats``)', required=True, action=SM) + reqs.add_argument('-ri', '--ref_img', help='Path to a reference image .nii.gz for setting the output image resolution and shape [and saving if .nii.gz output].', required=True, action=SM) + reqs.add_argument('-cr', '--current_res', help="Current resolution in micrometers (e.g., 3.52 3.52 6 for anisotropic or 10 for isotropic).", nargs='*', required=True, type=float, action=SM) + reqs.add_argument('-tr', '--target_res', help="Target resolution in micrometers (e.g., 50 for isotropic).", required=True, type=float, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-co', '--csv_output', help="Optional: Path to save resampled points in a CSV.", action=SM) + opts.add_argument('-io', '--img_output', help="Optional: Path to save resampled points as an image.", action=SM) + opts.add_argument('-thr', '--thresh', help='Exclude region IDs below this threshold (e.g., 20000 to obtain left hemisphere data)', type=float, action=SM) + opts.add_argument('-uthr', '--upper_thr', help='Exclude region IDs above this threshold (e.g., 20000 to obtain right hemisphere data)', type=float, action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/image_tools/spatial_averaging.html b/_modules/unravel/image_tools/spatial_averaging.html index 109a2134..afc9aee7 100644 --- a/_modules/unravel/image_tools/spatial_averaging.html +++ b/_modules/unravel/image_tools/spatial_averaging.html @@ -356,13 +356,12 @@

    Source code for unravel.image_tools.spatial_averaging

    """ Use ``img_spatial_avg`` from UNRAVEL to load an image and apply 3D spatial averaging. -Usage: ------- - img_spatial_avg -i <tif_dir> -o spatial_avg.zarr -d 2 -v - Input image types: - .czi, .nii.gz, .ome.tif series, .tif series, .h5, .zarr +Outputs: + - .nii.gz, .tif series, or .zarr depending on the output path extension. + 3D spatial averaging: - Apply a 3D spatial averaging filter to a 3D numpy array. - Default kernel size is 3x3x3, for the current voxel and its 26 neighbors. @@ -383,18 +382,19 @@

    Source code for unravel.image_tools.spatial_averaging

    - The xy and z resolutions are required for saving the output as .nii.gz. - The output is saved as .nii.gz, .tif series, or .zarr. -Outputs: - - .nii.gz, .tif series, or .zarr depending on the output path extension. +Usage: +------ + img_spatial_avg -i <tif_dir> -o spatial_avg.zarr -d 2 [-k 3] [-c 0] [-x 3.5232] [-z 6] [-dt uint16] [-r metadata_referenece.nii.gz] [-ao xyz] [-v] """ -import argparse import cv2 import numpy as np from concurrent.futures import ThreadPoolExecutor from rich.traceback import install from scipy.ndimage import uniform_filter -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.img_io import load_3D_img, save_as_nii, save_as_tifs, save_as_zarr from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, print_func_name_args_times @@ -403,19 +403,25 @@

    Source code for unravel.image_tools.spatial_averaging

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input', help='path/image .czi, path/img.nii.gz, or path/tif_dir', required=True, action=SM) - parser.add_argument('-o', '--output', help='Output path. Default: None', required=True, action=SM) - parser.add_argument('-d', '--dimensions', help='2D or 3D spatial averaging. (2 or 3)', required=True, type=int, action=SM) - parser.add_argument('-k', '--kernel_size', help='Size of the kernel for spatial averaging. Default: 3', default=3, type=int, action=SM) - parser.add_argument('-c', '--channel', help='.czi channel number. Default: 0 for autofluo', default=0, type=int, action=SM) - parser.add_argument('-x', '--xy_res', help='xy resolution in um', default=None, type=float, action=SM) - parser.add_argument('-z', '--z_res', help='z resolution in um', default=None, type=float, action=SM) - parser.add_argument('-dt', '--dtype', help='Output data type. Default: uint16', default='uint16', action=SM) - parser.add_argument('-r', '--reference', help='Reference image for .nii.gz metadata. Default: None', default=None, action=SM) - parser.add_argument('-ao', '--axis_order', help='Default: xyz. (other option: zyx)', default='xyz', action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='path/image .czi, path/img.nii.gz, or path/tif_dir', required=True, action=SM) + reqs.add_argument('-o', '--output', help='Output path. Default: None', required=True, action=SM) + reqs.add_argument('-d', '--dimensions', help='2D or 3D spatial averaging. (2 or 3)', required=True, type=int, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-k', '--kernel_size', help='Size of the kernel for spatial averaging. Default: 3', default=3, type=int, action=SM) + opts.add_argument('-c', '--channel', help='.czi channel number. Default: 0 for autofluo', default=0, type=int, action=SM) + opts.add_argument('-x', '--xy_res', help='xy resolution in um', default=None, type=float, action=SM) + opts.add_argument('-z', '--z_res', help='z resolution in um', default=None, type=float, action=SM) + opts.add_argument('-dt', '--dtype', help='Output data type. Default: uint16', default='uint16', action=SM) + opts.add_argument('-r', '--reference', help='Reference image for .nii.gz metadata. Default: None', default=None, action=SM) + opts.add_argument('-ao', '--axis_order', help='Default: xyz. (other option: zyx)', default='xyz', action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/image_tools/transpose_axes.html b/_modules/unravel/image_tools/transpose_axes.html index 611e95a1..8db55c0c 100644 --- a/_modules/unravel/image_tools/transpose_axes.html +++ b/_modules/unravel/image_tools/transpose_axes.html @@ -358,14 +358,14 @@

    Source code for unravel.image_tools.transpose_axes

    Usage: ------ - img_transpose -i path/img + img_transpose -i path/img [-xa 0] [-ya 1] [-za 2] [-o path/img_transposed.nii.gz] [-c 0] [-ao xyz] [-rr] """ -import argparse from pathlib import Path from rich.traceback import install -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.img_io import load_3D_img, save_as_nii from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, print_func_name_args_times @@ -374,17 +374,23 @@

    Source code for unravel.image_tools.transpose_axes

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input', help='path/img.czi, path/img.nii.gz, or path/tif_dir', action=SM) - parser.add_argument('-xa', '-x_axis', help='Enter 0, 1, or 2. Default: 0', default=0, type=int, action=SM) - parser.add_argument('-ya', '-y_axis', help='Default: 1', default=1, type=int, action=SM) - parser.add_argument('-za', '-z_axis', help='Default: 2', default=2, type=int, action=SM) - parser.add_argument('-o', '--output', help='path/img.nii.gz', action=SM) - parser.add_argument('-c', '--channel', help='.czi channel number. Default: 0 for autofluo', default=0, type=int, action=SM) - parser.add_argument('-ao', '--axis_order', help='Axis order for loading image. Default: xyz. (other option: zyx)', default='xyz', action=SM) - parser.add_argument('-rr', '--return_res', help='Default: True. If false, enter a float for xy_res and z_res (in um) in prompts', action='store_true', default=True) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='path/img.czi, path/img.nii.gz, or path/tif_dir', action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-xa', '-x_axis', help='Enter 0, 1, or 2. Default: 0', default=0, type=int, action=SM) + opts.add_argument('-ya', '-y_axis', help='Default: 1', default=1, type=int, action=SM) + opts.add_argument('-za', '-z_axis', help='Default: 2', default=2, type=int, action=SM) + opts.add_argument('-o', '--output', help='path/img.nii.gz', action=SM) + opts.add_argument('-c', '--channel', help='.czi channel number. Default: 0 for autofluo', default=0, type=int, action=SM) + opts.add_argument('-ao', '--axis_order', help='Axis order for loading image. Default: xyz. (other option: zyx)', default='xyz', action=SM) + opts.add_argument('-rr', '--return_res', help='Default: True. If false, enter a float for xy_res and z_res (in um) in prompts', action='store_true', default=True) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/image_tools/unique_intensities.html b/_modules/unravel/image_tools/unique_intensities.html index b11f03c8..488abb1a 100644 --- a/_modules/unravel/image_tools/unique_intensities.html +++ b/_modules/unravel/image_tools/unique_intensities.html @@ -358,24 +358,24 @@

    Source code for unravel.image_tools.unique_intensities

    Usage for printing all non-zero intensities: -------------------------------------------- - img_unique -i path/input_img.nii.gz + img_unique -i path/input_img.nii.gz [-v] Usage for printing the number of voxels for each intensity that is present: --------------------------------------------------------------------------- - img_unique -i path/input_img.nii.gz -s + img_unique -i path/input_img.nii.gz -s [-v] Usage for printing unique intensities w/ a min cluster size > 100 voxels: ------------------------------------------------------------------------- - img_unique -i path/input_img.nii.gz -m 100 + img_unique -i path/input_img.nii.gz -m 100 [-v] """ -import argparse import nibabel as nib import numpy as np from rich import print from rich.traceback import install -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.img_io import load_3D_img from unravel.core.img_tools import cluster_IDs @@ -385,12 +385,18 @@

    Source code for unravel.image_tools.unique_intensities

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input', help='path/input_img.nii.gz', required=True, action=SM) - parser.add_argument('-m', '--min_extent', help='Min cluster size in voxels (Default: 1)', default=1, action=SM, type=int) - parser.add_argument('-s', '--print_sizes', help='Print cluster IDs and sizes. Default: False', default=False, action='store_true') - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='path/input_img.nii.gz', required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-m', '--min_extent', help='Min cluster size in voxels (Default: 1)', default=1, action=SM, type=int) + opts.add_argument('-s', '--print_sizes', help='Print cluster IDs and sizes. Default: False', default=False, action='store_true') + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/region_stats/rstats.html b/_modules/unravel/region_stats/rstats.html index d92c15cb..cc195deb 100644 --- a/_modules/unravel/region_stats/rstats.html +++ b/_modules/unravel/region_stats/rstats.html @@ -356,13 +356,12 @@

    Source code for unravel.region_stats.rstats

     """
     Use ``rstats`` from UNRAVEL to quantify cell or label densities for all regions in an atlas.
     
    -Usage if the atlas is already in native space from ``warp_to_native``:
    -----------------------------------------------------------------------
    -    rstats -s rel_path/segmentation_image.nii.gz -a rel_path/native_atlas_split.nii.gz -c Saline --dirs sample14 sample36 
    +Prereqs: 
    +    - ``reg_prep``, ``reg``, and ``seg_ilastik``
     
    -Usage if the native atlas is not available; it is not saved (faster):
    ----------------------------------------------------------------------
    -    rstats -s rel_path/segmentation_image.nii.gz -m path/atlas_split.nii.gz -c Saline --dirs sample14 sample36
    +Inputs:
    +    - rel_path/segmentation_image.nii.gz (can be glob pattern)
    +    - rel_path/native_atlas_split.nii.gz (use this -a if this exists from ``warp_to_native``; otherwise, use -m to warp atlas to native space)
     
     Outputs:
         - CSV files in ./sample??/regional_stats/ with cell counts or volumes of segmented voxels, region volumes, and cell or label densities for each region
    @@ -373,15 +372,19 @@ 

    Source code for unravel.region_stats.rstats

         - Default csv: UNRAVEL/unravel/core/csvs/CCFv3-2020__regionID_side_IDpath_region_abbr.csv
         - Columns: Region_ID, Side, ID_path, Region, Abbr
     
    -Prereqs: 
    -    - ``reg_prep``, ``reg``, and ``seg_ilastik``
    -
     Next steps:
         - Use ``utils_agg_files`` to aggregate the CSVs from sample directories to the current directory
         - Use ``rstats_summary`` to summarize the results
    +
    +Usage if the atlas is already in native space from ``warp_to_native``:
    +----------------------------------------------------------------------
    +    rstats -s rel_path/segmentation_image.nii.gz -a rel_path/native_atlas_split.nii.gz -c Saline --dirs sample14 sample36 [-t cell_densities] [-md parameters/metadata.txt] [-cc 6] [-ro reg_outputs] [-fri autofl_50um_masked_fixed_reg_input.nii.gz] [-r 50] [-csv CCFv3-2020__regionID_side_IDpath_region_abbr.csv] [-mi] [-d list of paths] [-p sample??] [-v]
    +
    +Usage if the native atlas is not available; it is not saved (faster):
    +---------------------------------------------------------------------
    +    rstats -s rel_path/segmentation_image.nii.gz -m path/atlas_split.nii.gz -c Saline --dirs sample14 sample36 [-t cell_densities] [-md parameters/metadata.txt] [-cc 6] [-ro reg_outputs] [-fri autofl_50um_masked_fixed_reg_input.nii.gz] [-r 50] [-csv CCFv3-2020__regionID_side_IDpath_region_abbr.csv] [-mi] [-d list of paths] [-p sample??] [-v]
     """
     
    -import argparse
     import cc3d
     import numpy as np
     import os
    @@ -392,7 +395,8 @@ 

    Source code for unravel.region_stats.rstats

     from rich.live import Live
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
    +
     from unravel.core.config import Configuration
     from unravel.core.img_io import load_3D_img, load_image_metadata_from_txt
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, print_func_name_args_times, initialize_progress_bar, get_samples
    @@ -402,24 +406,33 @@ 

    Source code for unravel.region_stats.rstats

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-e', '--exp_paths', help='List of experiment dir paths w/ sample?? dirs to process.', nargs='*', default=None, action=SM) - parser.add_argument('-p', '--pattern', help='Pattern for sample?? dirs. Use cwd if no matches.', default='sample??', action=SM) - parser.add_argument('-d', '--dirs', help='List of sample?? dir names or paths to dirs to process', nargs='*', default=None, action=SM) - parser.add_argument('-t', '--type', help='Type of measurement (options: counts, region_volumes, cell_densities [default], label_volumes, or label_densities)', default='cell_densities', action=SM) - parser.add_argument('-c', '--condition', help='One word name for group (prepended to sample ID for rstats_summary)', required=True, action=SM) - parser.add_argument('-s', '--seg_img_path', help='rel_path/segmentation_image.nii.gz (can be glob pattern)', required=True, action=SM) - parser.add_argument('-a', '--atlas_path', help='rel_path/native_atlas_split.nii.gz (use this -a if this exists from ``warp_to_native``, otherwise use -m ; "split" == left label IDs increased by 20,000)', default=None, action=SM) - parser.add_argument('-m', '--moving_img', help='path/atlas_image.nii.gz to warp from atlas space', default=None, action=SM) - parser.add_argument('-md', '--metadata', help='path/metadata.txt. Default: ./parameters/metadata.txt', default="./parameters/metadata.txt", action=SM) - parser.add_argument('-cc', '--connect', help='Connected component connectivity (6, 18, or 26). Default: 6', type=int, default=6, action=SM) - parser.add_argument('-ro', '--reg_outputs', help="Name of folder w/ outputs from registration. Default: reg_outputs", default="reg_outputs", action=SM) - parser.add_argument('-fri', '--fixed_reg_in', help='Fixed input for registration (reg). Default: autofl_50um_masked_fixed_reg_input.nii.gz', default="autofl_50um_masked_fixed_reg_input.nii.gz", action=SM) - parser.add_argument('-r', '--reg_res', help='Resolution of registration inputs in microns. Default: 50', default='50',type=int, action=SM) - parser.add_argument('-csv', '--csv_path', help='CSV name or path/name.csv. Default: CCFv3-2020__regionID_side_IDpath_region_abbr.csv', default='CCFv3-2020__regionID_side_IDpath_region_abbr.csv', action=SM) - parser.add_argument('-mi', '--miracl', help='Mode for compatibility (accounts for tif to nii reorienting)', action='store_true', default=False) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-c', '--condition', help='One word name for group (prepended to sample ID for rstats_summary)', required=True, action=SM) + reqs.add_argument('-s', '--seg_img_path', help='rel_path/segmentation_image.nii.gz (can be glob pattern)', required=True, action=SM) + + key_opts = parser.add_argument_group('Key options') + key_opts.add_argument('-a', '--atlas_path', help='rel_path/native_atlas_split.nii.gz (use this -a if this exists from ``warp_to_native``, otherwise use -m ; "split" == left label IDs increased by 20,000)', default=None, action=SM) + key_opts.add_argument('-m', '--moving_img', help='path/atlas_image.nii.gz to warp from atlas space', default=None, action=SM) + key_opts.add_argument('-t', '--type', help='Type of measurement (options: counts, region_volumes, cell_densities [default], label_volumes, or label_densities)', default='cell_densities', action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-md', '--metadata', help='path/metadata.txt. Default: parameters/metadata.txt', default="parameters/metadata.txt", action=SM) + opts.add_argument('-cc', '--connect', help='Connected component connectivity (6, 18, or 26). Default: 6', type=int, default=6, action=SM) + opts.add_argument('-ro', '--reg_outputs', help="Name of folder w/ outputs from registration. Default: reg_outputs", default="reg_outputs", action=SM) + opts.add_argument('-fri', '--fixed_reg_in', help='Fixed input for registration (reg). Default: autofl_50um_masked_fixed_reg_input.nii.gz', default="autofl_50um_masked_fixed_reg_input.nii.gz", action=SM) + opts.add_argument('-r', '--reg_res', help='Resolution of registration inputs in microns. Default: 50', default='50',type=int, action=SM) + opts.add_argument('-csv', '--csv_path', help='CSV name or path/name.csv. Default: CCFv3-2020__regionID_side_IDpath_region_abbr.csv', default='CCFv3-2020__regionID_side_IDpath_region_abbr.csv', action=SM) + + compatibility = parser.add_argument_group('Compatibility options') + compatibility.add_argument('-mi', '--miracl', help='Mode for compatibility (accounts for tif to nii reorienting)', action='store_true', default=False) + + general = parser.add_argument_group('General arguments') + general.add_argument('-d', '--dirs', help='Paths to sample?? dirs and/or dirs containing them (space-separated) for batch processing. Default: current dir', nargs='*', default=None, action=SM) + general.add_argument('-p', '--pattern', help='Pattern for directories to process. Default: sample??', default='sample??', action=SM) + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    @@ -630,13 +643,11 @@

    Source code for unravel.region_stats.rstats

         Configuration.verbose = args.verbose
         verbose_start_msg()
     
    -    samples = get_samples(args.dirs, args.pattern, args.exp_paths)
    +    sample_paths = get_samples(args.dirs, args.pattern, args.verbose)
     
    -    progress, task_id = initialize_progress_bar(len(samples), "[red]Processing samples...")
    +    progress, task_id = initialize_progress_bar(len(sample_paths), "[red]Processing samples...")
         with Live(progress):
    -        for sample in samples:
    -
    -            sample_path = Path(sample).resolve() if sample != Path.cwd().name else Path.cwd()
    +        for sample_path in sample_paths:
     
                 # Load resolutions from metadata
                 metadata_path = sample_path / args.metadata
    diff --git a/_modules/unravel/region_stats/rstats_mean_IF.html b/_modules/unravel/region_stats/rstats_mean_IF.html
    index 871e0e76..e01e3c9a 100644
    --- a/_modules/unravel/region_stats/rstats_mean_IF.html
    +++ b/_modules/unravel/region_stats/rstats_mean_IF.html
    @@ -356,26 +356,30 @@ 

    Source code for unravel.region_stats.rstats_mean_IF

    """ Use ``rstats_mean_IF`` from UNRAVEL to measure mean intensity of immunofluorescence staining in brain regions in atlas space. -Usage: ------- - rstats_mean_IF -i '<asterisk>.nii.gz' -a path/atlas +Inputs: + - `*`.nii.gz + - path/atlas.nii.gz Outputs: - - ./rstats_mean_IF/image_name.csv for each image + - ./rstats_mean_IF/image_name.csv with regional mean intensity values for each image Next: - cd rstats_mean_IF - ``rstats_mean_IF_summary`` + +Usage: +------ + rstats_mean_IF -i '<asterisk>.nii.gz' -a path/atlas [--regions 1 2 3] [-v] """ -import argparse import csv import nibabel as nib import numpy as np from pathlib import Path from rich.traceback import install -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg from unravel.image_tools.unique_intensities import uniq_intensities @@ -384,12 +388,18 @@

    Source code for unravel.region_stats.rstats_mean_IF

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input', help="Pattern for NIfTI images to process (e.g., '*.nii.gz')", required=True, action=SM) - parser.add_argument('-a', '--atlas', help='Path/atlas.nii.gz', required=True, action=SM) - parser.add_argument('-r', '--regions', help='Space-separated list of region intensities to process', nargs='*', type=int, action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help="Pattern for NIfTI images to process (e.g., '*.nii.gz')", required=True, action=SM) + reqs.add_argument('-a', '--atlas', help='Path/atlas.nii.gz', required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-r', '--regions', help='Space-separated list of region intensities to process. Default: process all IDs', nargs='*', type=int, action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/region_stats/rstats_mean_IF_in_segmented_voxels.html b/_modules/unravel/region_stats/rstats_mean_IF_in_segmented_voxels.html index d04fa55c..4e536859 100644 --- a/_modules/unravel/region_stats/rstats_mean_IF_in_segmented_voxels.html +++ b/_modules/unravel/region_stats/rstats_mean_IF_in_segmented_voxels.html @@ -356,24 +356,26 @@

    Source code for unravel.region_stats.rstats_mean_IF_in_segmented_voxels

    """ Use ``rstats_mean_IF_in_seg`` from UNRAVEL to measure mean intensity of immunofluorescence (IF) staining in brain regions in segmented voxels. -Run from experiment folder containing sample?? folders. +Inputs: + - rel_path/fluo_image or rel_path/fluo_img_dir + - rel_path/seg_img.nii.gz in tissue space (1st glob match processed) + - path/atlas.nii.gz to warp to tissue space -Usage ------ - rstats_mean_IF_in_seg -i <asterisk>.czi -s seg_dir/sample??_seg_dir.nii.gz -a path/atlas.nii.gz +Output: + - ./sample??/seg_dir/sample??_seg_dir_regional_mean_IF_in_seg.csv Note: This uses full resolution images (i.e., the raw IF image and a segmentation from ``seg_ilastik``) -Default output: - - ./sample??/seg_dir/sample??_seg_dir_regional_mean_IF_in_seg.csv - Next steps: ``utils_agg_files`` -i seg_dir/sample??_seg_dir_regional_mean_IF_in_seg.csv ``rstats_mean_IF_summary`` + +Usage +----- + rstats_mean_IF_in_seg -i `*`.czi -s seg_dir/sample??_seg_dir.nii.gz -a path/atlas.nii.gz [-o seg_dir/sample??_seg_dir_regional_mean_IF_in_seg.csv] [--region_ids 1 2 3] [-c 1] [Optional output: -n rel_path/native_image.zarr] [-fri autofl_50um_masked_fixed_reg_input.nii.gz] [-inp nearestNeighbor] [-ro reg_outputs] [-r 50] [-md parameters/metadata.txt] [-zo 0] [-mi] [-v] """ -import argparse import csv import nibabel as nib import numpy as np @@ -382,7 +384,8 @@

    Source code for unravel.region_stats.rstats_mean_IF_in_segmented_voxels

    from rich.live import Live from rich.traceback import install -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.img_io import load_3D_img from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, print_func_name_args_times, initialize_progress_bar, get_samples @@ -392,30 +395,36 @@

    Source code for unravel.region_stats.rstats_mean_IF_in_segmented_voxels

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-e', '--exp_paths', help='List of experiment dir paths w/ sample?? dirs to process.', nargs='*', default=None, action=SM) - parser.add_argument('-p', '--pattern', help='Pattern for sample?? dirs. Use cwd if no matches.', default='sample??', action=SM) - parser.add_argument('-d', '--dirs', help='List of sample?? dir names or paths to dirs to process', nargs='*', default=None, action=SM) - parser.add_argument('-i', '--input', help='path/fluo_image or path/fluo_img_dir relative to sample?? folder', required=True, action=SM) - parser.add_argument('-c', '--chann_idx', help='.czi channel index. Default: 1', default=1, type=int, action=SM) - parser.add_argument('-s', '--seg', help='rel_path/seg_img.nii.gz. 1st glob match processed', required=True, action=SM) - parser.add_argument('-a', '--atlas', help='path/atlas.nii.gz to warp to native space', required=True, action=SM) - parser.add_argument('-o', '--output', help='path/name.csv relative to ./sample??/', default=None, action=SM) - parser.add_argument('--region_ids', help='Optional: Space-separated list of region intensities to process. Default: Process all regions', default=None, nargs='*', type=int) - - # Optional to_native() args - parser.add_argument('-n', '--native_atlas', help='Load/save native atlasfrom/to rel_path/native_image.zarr (fast) or rel_path/native_image.nii.gz if provided', default=None, action=SM) - parser.add_argument('-fri', '--fixed_reg_in', help='Fixed input for registration (``reg``). Default: autofl_50um_masked_fixed_reg_input.nii.gz', default="autofl_50um_masked_fixed_reg_input.nii.gz", action=SM) - parser.add_argument('-inp', '--interpol', help='Interpolator for ants.apply_transforms (nearestNeighbor [default], multiLabel [slow])', default="nearestNeighbor", action=SM) - parser.add_argument('-ro', '--reg_outputs', help="Name of folder w/ outputs from ``reg`` (e.g., transforms). Default: reg_outputs", default="reg_outputs", action=SM) - parser.add_argument('-r', '--reg_res', help='Resolution of registration inputs in microns. Default: 50', default='50',type=int, action=SM) - parser.add_argument('-md', '--metadata', help='path/metadata.txt. Default: parameters/metadata.txt', default="parameters/metadata.txt", action=SM) - parser.add_argument('-zo', '--zoom_order', help='SciPy zoom order for scaling to full res. Default: 0 (nearest-neighbor)', default='0',type=int, action=SM) - parser.add_argument('-mi', '--miracl', help='Mode for compatibility (accounts for tif to nii reorienting)', action='store_true', default=False) - - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='path/fluo_image or path/fluo_img_dir relative to sample?? folder', required=True, action=SM) + reqs.add_argument('-s', '--seg', help='rel_path/seg_img.nii.gz. 1st glob match processed', required=True, action=SM) + reqs.add_argument('-a', '--atlas', help='path/atlas.nii.gz to warp to native space', required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-o', '--output', help='path/name.csv relative to ./sample??/', default=None, action=SM) + opts.add_argument('--region_ids', help='Optional: Space-separated list of region intensities to process. Default: Process all regions', default=None, nargs='*', type=int) + opts.add_argument('-c', '--chann_idx', help='.czi channel index. Default: 1', default=1, type=int, action=SM) + + # Optional to_native() args + opts_to_native = parser.add_argument_group('Optional to_native() arguments') + opts_to_native.add_argument('-n', '--native_atlas', help='Load/save native atlasfrom/to rel_path/native_image.zarr (fast) or rel_path/native_image.nii.gz if provided', default=None, action=SM) + opts_to_native.add_argument('-fri', '--fixed_reg_in', help='Fixed input for registration (``reg``). Default: autofl_50um_masked_fixed_reg_input.nii.gz', default="autofl_50um_masked_fixed_reg_input.nii.gz", action=SM) + opts_to_native.add_argument('-inp', '--interpol', help='Interpolator for ants.apply_transforms (nearestNeighbor [default], multiLabel [slow])', default="nearestNeighbor", action=SM) + opts_to_native.add_argument('-ro', '--reg_outputs', help="Name of folder w/ outputs from ``reg`` (e.g., transforms). Default: reg_outputs", default="reg_outputs", action=SM) + opts_to_native.add_argument('-r', '--reg_res', help='Resolution of registration inputs in microns. Default: 50', default='50',type=int, action=SM) + opts_to_native.add_argument('-md', '--metadata', help='path/metadata.txt. Default: parameters/metadata.txt', default="parameters/metadata.txt", action=SM) + opts_to_native.add_argument('-zo', '--zoom_order', help='SciPy zoom order for scaling to full res. Default: 0 (nearest-neighbor)', default='0',type=int, action=SM) + + compatability = parser.add_argument_group('Compatability options for to_native()') + compatability.add_argument('-mi', '--miracl', help='Mode for compatibility (accounts for tif to nii reorienting)', action='store_true', default=False) + + general = parser.add_argument_group('General arguments') + general.add_argument('-d', '--dirs', help='Paths to sample?? dirs and/or dirs containing them (space-separated) for batch processing. Default: current dir', nargs='*', default=None, action=SM) + general.add_argument('-p', '--pattern', help='Pattern for directories to process. Default: sample??', default='sample??', action=SM) + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    @@ -492,13 +501,11 @@

    Source code for unravel.region_stats.rstats_mean_IF_in_segmented_voxels

    Configuration.verbose = args.verbose verbose_start_msg() - samples = get_samples(args.dirs, args.pattern, args.exp_paths) + sample_paths = get_samples(args.dirs, args.pattern, args.verbose) - progress, task_id = initialize_progress_bar(len(samples), "[red]Processing samples...") + progress, task_id = initialize_progress_bar(len(sample_paths), "[red]Processing samples...") with Live(progress): - for sample in samples: - - sample_path = Path(sample).resolve() if sample != Path.cwd().name else Path.cwd() + for sample_path in sample_paths: # Load or make the native atlas image native_atlas_path = next(sample_path.glob(str(args.native_atlas)), None) diff --git a/_modules/unravel/region_stats/rstats_mean_IF_summary.html b/_modules/unravel/region_stats/rstats_mean_IF_summary.html index 5d676b0f..12ac5b6c 100644 --- a/_modules/unravel/region_stats/rstats_mean_IF_summary.html +++ b/_modules/unravel/region_stats/rstats_mean_IF_summary.html @@ -356,40 +356,37 @@

    Source code for unravel.region_stats.rstats_mean_IF_summary

    """ Use ``rstats_mean_IF_summary`` from UNRAVEL to output plots of mean IF intensities for each region intensity ID. -Usage for t-tests: ------------------- - rstats_mean_IF_summary --order Control Treatment --labels Control Treatment -t ttest +Prereqs: + - Generate CSV inputs withs ``rstats_IF_mean`` or ``rstats_IF_mean_in_seg`` + - After ``rstats_IF_mean_in_seg``, aggregate CSV inputs with ``utils_agg_files`` + - If needed, add conditions to input CSV file names: ``utils_prepend`` -sk $SAMPLE_KEY -f -Usage for Tukey's tests w/ reordering and renaming of conditions: ------------------------------------------------------------------ - rstats_mean_IF_summary --order group3 group2 group1 --labels Group_3 Group_2 Group_1 +Inputs: + - `*`.csv in the working dir with these columns: 'Region_Intensity', 'Mean_IF_Intensity' -Usage with a custom atlas: --------------------------- - atlas=path/custom_atlas.nii.gz ; rstats_mean_IF_summary --region_ids $(img_unique -i $atlas) --order group2 group1 --labels Group_2 Group_1 -t ttest +Outputs: + - rstats_mean_IF_summary/region_<region_id>_<region_abbr>.pdf for each region + - If significant differences are found, a prefix '_' is added to the filename to sort the files Note: - The first word of the csv inputs is used for the the group names (e.g. Control from Control_sample01_cFos_rb4_atlas_space_z.csv) - Default csv: UNRAVEL/unravel/core/csvs/CCFv3-2020__regionID_side_IDpath_region_abbr.csv - Alternatively, use CCFv3-2017__regionID_side_IDpath_region_abbr.csv or provide a custom CSV with the same columns. + - The look up table (LUT) csv has these columns: 'Region_ID', 'Side', 'Name', 'Abbr' -Inputs: - - <asterisk>.csv in the working dir with these columns: 'Region_Intensity', 'Mean_IF_Intensity' - -Prereqs: - - Generate CSV inputs withs ``rstats_IF_mean`` or ``rstats_IF_mean_in_seg`` - - After ``rstats_IF_mean_in_seg``, aggregate CSV inputs with ``utils_agg_files`` - - If needed, add conditions to input CSV file names: ``utils_prepend`` -sk $SAMPLE_KEY -f +Usage for t-tests: +------------------ + rstats_mean_IF_summary --order Control Treatment --labels Control Treatment -t ttest [-alt two-sided] [--lut CCFv3-2017__regionID_side_IDpath_region_abbr.csv] [-v] -Outputs: - - rstats_mean_IF_summary/region_<region_id>_<region_abbr>.pdf for each region - - If significant differences are found, a prefix '_' is added to the filename to sort the files +Usage for Tukey's tests w/ reordering and renaming of conditions: +----------------------------------------------------------------- + rstats_mean_IF_summary --order group3 group2 group1 --labels Group_3 Group_2 Group_1 [--lut CCFv3-2017__regionID_side_IDpath_region_abbr.csv] [-v] -The look up table (LUT) csv has these columns: - 'Region_ID', 'Side', 'Name', 'Abbr' +Usage with a custom atlas: +-------------------------- + atlas=path/custom_atlas.nii.gz ; rstats_mean_IF_summary --region_ids $(img_unique -i $atlas) --order group2 group1 --labels Group_2 Group_1 -t ttest [-alt two-sided] [--lut CCFv3-2017__regionID_side_IDpath_region_abbr.csv] [-v] """ -import argparse import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np @@ -403,7 +400,8 @@

    Source code for unravel.region_stats.rstats_mean_IF_summary

    from scipy.stats import ttest_ind, dunnett from statsmodels.stats.multicomp import pairwise_tukeyhsd -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg @@ -411,16 +409,21 @@

    Source code for unravel.region_stats.rstats_mean_IF_summary

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('--region_ids', nargs='*', type=int, help='List of region intensity IDs (Default: process all regions from the lut CSV)', action=SM) - parser.add_argument('-l', '--lut', help='LUT csv name (in unravel/core/csvs/). Default: CCFv3-2020__regionID_side_IDpath_region_abbr.csv', default="CCFv3-2020__regionID_side_IDpath_region_abbr.csv", action=SM) - parser.add_argument('--order', nargs='*', help='Group Order for plotting (must match 1st word of CSVs)', action=SM) - parser.add_argument('--labels', nargs='*', help='Group Labels in same order', action=SM) - parser.add_argument('-t', '--test', help='Choose between "tukey", "dunnett", and "ttest" post-hoc tests. (Default: tukey)', default='tukey', choices=['tukey', 'dunnett', 'ttest'], action=SM) - parser.add_argument('-alt', "--alternate", help="Number of tails and direction for Dunnett's test {'two-sided', 'less' (means < ctrl), 'greater'}. Default: two-sided", default='two-sided', action=SM) - parser.add_argument('-s', '--show_plot', help='Show plot if flag is provided', action='store_true') - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('--order', nargs='*', help='Group Order for plotting (must match 1st word of CSVs)', action=SM) + reqs.add_argument('--labels', nargs='*', help='Group Labels in same order', action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-t', '--test', help='Choose between "tukey", "dunnett", and "ttest" post-hoc tests. (Default: tukey)', default='tukey', choices=['tukey', 'dunnett', 'ttest'], action=SM) + opts.add_argument('-alt', "--alternate", help="Number of tails and direction for Dunnett's test {'two-sided', 'less' (means < ctrl), 'greater'}. Default: two-sided", default='two-sided', action=SM) + opts.add_argument('--region_ids', nargs='*', type=int, help='List of region intensity IDs (Default: process all regions from the lut CSV)', action=SM) + opts.add_argument('-l', '--lut', help='LUT csv name (in unravel/core/csvs/). Default: CCFv3-2020__regionID_side_IDpath_region_abbr.csv', default="CCFv3-2020__regionID_side_IDpath_region_abbr.csv", action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    @@ -536,7 +539,7 @@

    Source code for unravel.region_stats.rstats_mean_IF_summary

    [docs] -def plot_data(region_id, order=None, labels=None, csv_path=None, test_type='tukey', show_plot=False, alt='two-sided'): +def plot_data(region_id, order=None, labels=None, csv_path=None, test_type='tukey', alt='two-sided'): df = load_data(region_id) if 'group' not in df.columns: @@ -668,10 +671,7 @@

    Source code for unravel.region_stats.rstats_mean_IF_summary

    file_name = f"{file_prefix}region_{region_id}_{region_abbr}.pdf" plt.savefig(output_folder / file_name) - plt.close() - - if show_plot: - plt.show()
    + plt.close()
    @@ -710,7 +710,7 @@

    Source code for unravel.region_stats.rstats_mean_IF_summary

    # Process each region ID for region_id in region_ids_to_process: - plot_data(region_id, args.order, args.labels, csv_path=lut, test_type=args.test, show_plot=args.show_plot, alt=args.alternate) + plot_data(region_id, args.order, args.labels, csv_path=lut, test_type=args.test, alt=args.alternate) verbose_end_msg()
    diff --git a/_modules/unravel/region_stats/rstats_summary.html b/_modules/unravel/region_stats/rstats_summary.html index 22378c7c..6205d393 100644 --- a/_modules/unravel/region_stats/rstats_summary.html +++ b/_modules/unravel/region_stats/rstats_summary.html @@ -356,13 +356,6 @@

    Source code for unravel.region_stats.rstats_summary

    """ Use ``rstats_summary`` from UNRAVEL to plot cell densensities for each region and summarize results. -Usage: ------- - rstats_summary --groups Saline MDMA Meth -d 10000 -hemi r - -To do: - Add module for Dunnett's tests (don't use this option for now) - Inputs: - CSVs with cell densities for each region (e.g., regional_stats/<condition>_sample??_cell_densities.csv) - Input CSV columns: Region_ID, Side, ID_Path, Region, Abbr, <OneWordCondition>_sample?? @@ -372,15 +365,21 @@

    Source code for unravel.region_stats.rstats_summary

    - Plots and a summary CSV to the current directory. - regional_cell_densities_all.csv (Columns: columns: Region_ID,Side,Name,Abbr,Saline_sample06,Saline_sample07,...,MDMA_sample01,...,Meth_sample23,...) -Example hex code list (flank arg w/ double quotes): ['#2D67C8', '#27AF2E', '#D32525', '#7F25D3'] - Note: + - Example hex code list (flank arg w/ double quotes): ['#2D67C8', '#27AF2E', '#D32525', '#7F25D3'] - Default csv: UNRAVEL/unravel/core/csvs/CCFv3-2020_regional_summary.csv - It has columns: Region_ID, ID_Path, Region, Abbr, General_Region, R, G, B - Alternatively, use CCFv3-2017_regional_summary.csv or provide a custom CSV with the same columns. + +Usage for Tukey tests: +--------------------------- + rstats_summary --groups Saline MDMA Meth -hemi both [-div 10000] [-y cell_density] [-csv CCFv3-2020_regional_summary.csv] [-b ABA] [-s light:white] [-o tukey_plots] [-e pdf] [-v] + +Usage for t-tests: +--------------------------- + rstats_summary --groups Saline MDMA -hemi both -t t-test -c Saline [-alt two-sided] [-div 10000] [-y cell_density] [-csv CCFv3-2020_regional_summary.csv] [-b ABA] [-s light:white] [-o t-test_plots] [-e pdf] [-v] """ -import argparse import ast import os from pathlib import Path @@ -397,7 +396,8 @@

    Source code for unravel.region_stats.rstats_summary

    from scipy.stats import ttest_ind from statsmodels.stats.multicomp import pairwise_tukeyhsd -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, initialize_progress_bar @@ -405,21 +405,27 @@

    Source code for unravel.region_stats.rstats_summary

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('--groups', nargs='*', help='Group prefixes (e.g., saline meth cbsMeth)', action=SM) - parser.add_argument('-t', '--test_type', help="Type of statistical test to use: 'tukey' (default), 'dunnett', or 't-test'", choices=['tukey', 'dunnett', 't-test'], default='tukey', action=SM) - parser.add_argument('-hemi', help="Hemisphere(s) to process (r, l or both)", choices=['r', 'l', 'both'], required=True, action=SM) - parser.add_argument('-c', '--ctrl_group', help="Control group name for t-test or Dunnett's tests", action=SM) - parser.add_argument('-d', '--divide', type=float, help='Divide the cell densities by the specified value for plotting (default is None)', default=None, action=SM) - parser.add_argument('-y', '--ylabel', help='Y-axis label (Default: cell_density)', default='cell_density', action=SM) - parser.add_argument('-csv', '--csv_path', help='CSV name or path/name.csv. Default: CCFv3-2020_regional_summary.csv', default='CCFv3-2020_regional_summary.csv', action=SM) - parser.add_argument('-b', '--bar_color', help="ABA (default), #hex_code, Seaborn palette, or #hex_code list matching # of groups", default='ABA', action=SM) - parser.add_argument('-s', '--symbol_color', help="ABA, #hex_code, Seaborn palette (Default: light:white), or #hex_code lis t matching # of groups", default='light:white', action=SM) - parser.add_argument('-o', '--output', help='Output directory for plots (Default: <args.test_type>_plots)', action=SM) - parser.add_argument('-alt', "--alternate", help="Number of tails and direction for t-tests or Dunnett's tests ('two-sided' [default], 'less' [group1 < group2], or 'greater')", default='two-sided', action=SM) - parser.add_argument('-e', "--extension", help="File extension for plots. Choices: pdf (default), svg, eps, tiff, png)", default='pdf', choices=['pdf', 'svg', 'eps', 'tiff', 'png'], action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('--groups', nargs='*', help='Group prefixes (e.g., saline meth cbsMeth)', required=True, action=SM) + reqs.add_argument('-hemi', help="Hemisphere(s) to process (r, l or both)", choices=['r', 'l', 'both'], required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-t', '--test_type', help="Type of statistical test to use: 'tukey' (default), 't-test'", choices=['tukey', 't-test'], default='tukey', action=SM) # Add 'dunnett' later + opts.add_argument('-c', '--ctrl_group', help="Control group name for t-test or Dunnett's tests", action=SM) # Does the control need to be specified for a t-test? First group could be the control. + opts.add_argument('-alt', "--alternate", help="Number of tails and direction for t-tests or Dunnett's tests ('two-sided' [default], 'less' [group1 < group2], or 'greater')", default='two-sided', action=SM) + opts.add_argument('-d', '--divide', type=float, help='Divide the cell densities by the specified value for plotting (default is None)', default=None, action=SM) + opts.add_argument('-y', '--ylabel', help='Y-axis label (Default: cell_density)', default='cell_density', action=SM) + opts.add_argument('-csv', '--csv_path', help='CSV name or path/name.csv. Default: CCFv3-2020_regional_summary.csv', default='CCFv3-2020_regional_summary.csv', action=SM) + opts.add_argument('-b', '--bar_color', help="ABA (default), #hex_code, Seaborn palette, or #hex_code list matching # of groups", default='ABA', action=SM) + opts.add_argument('-s', '--symbol_color', help="ABA, #hex_code, Seaborn palette (Default: light:white), or #hex_code lis t matching # of groups", default='light:white', action=SM) + opts.add_argument('-o', '--output', help='Output directory for plots (Default: <args.test_type>_plots)', action=SM) + opts.add_argument('-e', "--extension", help="File extension for plots. Choices: pdf (default), svg, eps, tiff, png)", default='pdf', choices=['pdf', 'svg', 'eps', 'tiff', 'png'], action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/register/affine_initializer.html b/_modules/unravel/register/affine_initializer.html index b47a3458..181990f3 100644 --- a/_modules/unravel/register/affine_initializer.html +++ b/_modules/unravel/register/affine_initializer.html @@ -356,10 +356,6 @@

    Source code for unravel.register.affine_initializer

    """ Run ``reg_affine_initializer`` from UNRAVEL as a seperate process to kill it after a time out. This also allows for suppressing error messages. -Usage: ------- - reg_affine_initializer -f reg_outputs/autofl_50um_masked_fixed_reg_input.nii.gz -m atlas/average_template_CCFv3_30um.nii.gz -o reg_outputs/ANTsPy_init_tform.nii.gz -t 10 - Python usage: ------------- >>> import subprocess @@ -367,9 +363,12 @@

    Source code for unravel.register.affine_initializer

    >>> command = ['python', 'reg_affine_initializer', '-f', 'reg_outputs/autofl_50um_masked_fixed_reg_input.nii.gz', '-m', 'atlas/average_template_CCFv3_30um.nii.gz', '-o', 'reg_outputs/ANTsPy_init_tform.nii.gz', '-t', '10' ] >>> with open(os.devnull, 'w') as devnull: >>> subprocess.run(command, stderr=devnull) + +Usage: +------ + reg_affine_initializer -f reg_outputs/autofl_50um_masked_fixed_reg_input.nii.gz -m atlas/average_template_CCFv3_30um.nii.gz -o reg_outputs/ANTsPy_init_tform.nii.gz [-t 10] [-v] """ -import argparse import os import ants from contextlib import redirect_stderr @@ -378,7 +377,7 @@

    Source code for unravel.register.affine_initializer

    from rich import print from rich.traceback import install -from unravel.core.argparse_utils import SM, SuppressMetavar +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM from unravel.core.config import Configuration from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg @@ -386,13 +385,19 @@

    Source code for unravel.register.affine_initializer

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-f', '--fixed_img', help='path/fixed_image.nii.gz (e.g., autofl_50um_masked_fixed_reg_input.nii.gz)', required=True, action=SM) - parser.add_argument('-m', '--moving_img', help='path/moving_image.nii.gz (e.g., template)', required=True, action=SM) - parser.add_argument('-o', '--output', help='path/init_tform_py.nii.gz', required=True, action=SM) - parser.add_argument('-t', '--time_out', help='Duration in seconds to allow this command/module to run. Default: 10', default=10, type=int, action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-f', '--fixed_img', help='path/fixed_image.nii.gz (e.g., autofl_50um_masked_fixed_reg_input.nii.gz)', required=True, action=SM) + reqs.add_argument('-m', '--moving_img', help='path/moving_image.nii.gz (e.g., template)', required=True, action=SM) + reqs.add_argument('-o', '--output', help='path/init_tform_py.nii.gz', required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-t', '--time_out', help='Duration in seconds to allow this command/module to run. Default: 10', default=10, type=int, action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/register/reg.html b/_modules/unravel/register/reg.html index f4d67d3a..0ce65945 100644 --- a/_modules/unravel/register/reg.html +++ b/_modules/unravel/register/reg.html @@ -356,36 +356,42 @@

    Source code for unravel.register.reg

     """
     Use ``reg`` from UNRAVEL to register an average template brain/atlas to a resampled autofl brain. 
     
    -Usage for tissue registration:
    -------------------------------
    -    reg -m <path/template.nii.gz> -bc -sm 0.4 -ort <3 letter orientation code> -m2 atlas/atlas_CCFv3_2020_30um.nii.gz
    +Prereqs: 
    +    ``reg_prep``, [``seg_copy_tifs``], & [``seg_brain_mask``]
     
    -Usage for atlas to atlas registration:
    ---------------------------------------
    -    reg -m <path/atlas1.nii.gz> -f <path/atlas2.nii.gz> -m2 <path/atlas2.nii.gz>
    +Inputs:
    +    - template to register (e.g., gubra_template_CCFv3_30um.nii.gz, an iDISCO/LSFM template in CCFv3 space)
    +    - reg_inputs/autofl_50um_masked.nii.gz (from ``reg_prep``)
    +    - atlas/atlas_CCFv3_2020_30um.nii.gz (default; from Allen Brain Institute)
     
    -Usage for template to template registration:
    ---------------------------------------------
    -    reg -m <path/template1.nii.gz> -f <path/template2.nii.gz> -m2 <path/template2.nii.gz> -inp linear
    +Outputs:
    +    - reg_outputs/autofl_50um_masked_fixed_reg_input.nii.gz (padded fixed image used for registration with ANTsPy)
    +    - reg_outputs/<atlas>_in_tissue_space.nii.gz (warped atlas to tissue space for checking reg)
    +    - transformation matrices and deformation fields in reg_outputs
     
    -ort_code letter options: 
    -    - A/P=Anterior/Posterior
    -    - L/R=Left/Right
    -    - S/I=Superior/Interior
    +Note:
    +    - Images in reg_inputs are not padded.
    +    - Images in reg_outputs have 15% padding.
    +    - ort_code is a 3 letter orientation code of the fixed image if not set in fixed_img (e.g., RAS)
    +    - Letter options: A/P=Anterior/Posterior, L/R=Left/Right, S/I=Superior/Inferior
         - The side of the brain at the positive direction of the x, y, and z axes determines the 3 letters (axis order xyz)
     
    -Prereqs: 
    -    ``reg_prep``, [``seg_copy_tifs``], & [``seg_brain_mask``]
    -
     Next steps: 
         ``reg_check`` and ``vstats_prep``
     
    -Note:
    -    - Images in reg_inputs are not padded.
    -    - Images in reg_outputs have 15% padding.
    +Usage for tissue registration:
    +------------------------------
    +    reg -m <path/template.nii.gz> -bc -sm 0.4 -ort <3 letter orientation code> -m2 atlas/atlas_CCFv3_2020_30um.nii.gz [-f reg_inputs/autofl_50um_masked.nii.gz] [-mas reg_inputs/autofl_50um_brain_mask.nii.gz] [-ro reg_outputs] [-bc] [-sm 0.4] [-m2 atlas/atlas_CCFv3_2020_30um.nii.gz] [-d list of paths] [-p sample??] [-v]
    +
    +Usage for atlas to atlas registration:
    +--------------------------------------
    +    reg -m <path/atlas1.nii.gz> -f <path/atlas2.nii.gz> -m2 <path/atlas2.nii.gz> [-d list of paths] [-p sample??] [-v]
    +
    +Usage for template to template registration:
    +--------------------------------------------
    +    reg -m <path/template1.nii.gz> -f <path/template2.nii.gz> -m2 <path/template2.nii.gz> -inp linear [-d list of paths] [-p sample??] [-v]
     """
     
    -import argparse
     import os
     import subprocess
     import ants
    @@ -399,7 +405,7 @@ 

    Source code for unravel.register.reg

     from scipy.ndimage import gaussian_filter
     
     from unravel.image_io.reorient_nii import reorient_nii
    -from unravel.core.argparse_utils import SM, SuppressMetavar
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
     from unravel.core.config import Configuration
     from unravel.core.img_io import resolve_path
     from unravel.core.img_tools import pad
    @@ -410,30 +416,31 @@ 

    Source code for unravel.register.reg

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-e', '--exp_paths', help='List of experiment dir paths w/ sample?? dirs to process.', nargs='*', default=None, action=SM) - parser.add_argument('-p', '--pattern', help='Pattern for sample?? dirs. Use cwd if no matches.', default='sample??', action=SM) - parser.add_argument('-d', '--dirs', help='List of sample?? dir names or paths to dirs to process', nargs='*', default=None, action=SM) - - # Required arguments: - parser.add_argument('-m', '--moving_img', help='path/moving_img.nii.gz (e.g., average template optimally matching tissue)', required=True, action=SM) - - # Optional arguments: - parser.add_argument('-f', '--fixed_img', help='reg_inputs/autofl_50um_masked.nii.gz (from ``reg_prep``)', default="reg_inputs/autofl_50um_masked.nii.gz", action=SM) - parser.add_argument('-mas', '--mask', help="Brain mask for bias correction. Default: reg_inputs/autofl_50um_brain_mask.nii.gz. or pass in None", default="reg_inputs/autofl_50um_brain_mask.nii.gz", action=SM) - parser.add_argument('-ro', '--reg_outputs', help="Name of folder w/ outputs from ``reg`` (e.g., transforms). Default: reg_outputs", default="reg_outputs", action=SM) - parser.add_argument('-bc', '--bias_correct', help='Perform N4 bias field correction. Default: False', action='store_true', default=False) - parser.add_argument('-sm', '--smooth', help='Sigma value for smoothing the fixed image. Default: 0 for no smoothing. Use 0.4 for autofl', default=0, type=float, action=SM) - parser.add_argument('-ort', '--ort_code', help='3 letter orientation code of fixed image if not set in fixed_img (e.g., RAS)', action=SM) - parser.add_argument('-m2', '--moving_img2', help='path/atlas.nii.gz (outputs <reg_outputs>/<atlas>_in_tissue_space.nii.gz for checking reg; Default: atlas/atlas_CCFv3_2020_30um.nii.gz)', default='atlas/atlas_CCFv3_2020_30um.nii.gz', action=SM) - parser.add_argument('-inp', '--interpol', help='Interpolation method for warping -m2 to padded fixed img space (nearestNeighbor, multiLabel [default], linear, bSpline)', default="multiLabel", action=SM) - parser.add_argument('-it', '--init_time', help='Time in seconds allowed for ``reg_affine_initializer`` to run. Default: 30' , default='30', type=str, action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity.', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-m', '--moving_img', help='path/moving_img.nii.gz (e.g., average template optimally matching tissue)', required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-f', '--fixed_img', help='reg_inputs/autofl_50um_masked.nii.gz (from ``reg_prep``)', default="reg_inputs/autofl_50um_masked.nii.gz", action=SM) + opts.add_argument('-mas', '--mask', help="Brain mask for bias correction. Default: reg_inputs/autofl_50um_brain_mask.nii.gz. or pass in None", default="reg_inputs/autofl_50um_brain_mask.nii.gz", action=SM) + opts.add_argument('-ro', '--reg_outputs', help="Name of folder w/ outputs from ``reg`` (e.g., transforms). Default: reg_outputs", default="reg_outputs", action=SM) + opts.add_argument('-bc', '--bias_correct', help='Perform N4 bias field correction. Default: False', action='store_true', default=False) + opts.add_argument('-sm', '--smooth', help='Sigma value for smoothing the fixed image. Default: 0 for no smoothing. Use 0.4 for autofl', default=0, type=float, action=SM) + opts.add_argument('-ort', '--ort_code', help='3 letter orientation code of fixed image if not set in fixed_img (e.g., RAS)', action=SM) + opts.add_argument('-m2', '--moving_img2', help='path/atlas.nii.gz (outputs <reg_outputs>/<atlas>_in_tissue_space.nii.gz for checking reg; Default: atlas/atlas_CCFv3_2020_30um.nii.gz)', default='atlas/atlas_CCFv3_2020_30um.nii.gz', action=SM) + opts.add_argument('-inp', '--interpol', help='Interpolation method for warping -m2 to padded fixed img space (nearestNeighbor, multiLabel \[default], linear, bSpline)', default="multiLabel", action=SM) + opts.add_argument('-it', '--init_time', help='Time in seconds allowed for ``reg_affine_initializer`` to run. Default: 30' , default='30', type=str, action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-d', '--dirs', help='Paths to sample?? dirs and/or dirs containing them (space-separated) for batch processing. Default: current dir', nargs='*', default=None, action=SM) + general.add_argument('-p', '--pattern', help='Pattern for directories to process. Default: sample??', default='sample??', action=SM) + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    -# TODO: Update padding/unpadding logic to allow for additional padding if needed +# TODO: Update padding/unpadding logic to allow for additional padding if needed.
    @@ -469,13 +476,11 @@

    Source code for unravel.register.reg

         Configuration.verbose = args.verbose
         verbose_start_msg()
     
    -    samples = get_samples(args.dirs, args.pattern, args.exp_paths)
    +    sample_paths = get_samples(args.dirs, args.pattern, args.verbose)
     
    -    progress, task_id = initialize_progress_bar(len(samples), "[red]Processing samples...")
    +    progress, task_id = initialize_progress_bar(len(sample_paths), "[red]Processing samples...")
         with Live(progress):
    -        for sample in samples:
    -            
    -            sample_path = Path(sample).resolve() if sample != Path.cwd().name else Path.cwd()
    +        for sample_path in sample_paths:
     
                 # Directory with outputs (e.g., transforms) from registration
                 reg_outputs_path = resolve_path(sample_path, args.reg_outputs)
    diff --git a/_modules/unravel/register/reg_check.html b/_modules/unravel/register/reg_check.html
    index c2dd95fc..4f4d8b22 100644
    --- a/_modules/unravel/register/reg_check.html
    +++ b/_modules/unravel/register/reg_check.html
    @@ -354,21 +354,23 @@ 

    Source code for unravel.register.reg_check

     #!/usr/bin/env python3
     
     """
    -Use ``reg_check`` from UNRAVEL to check registration QC, copies autofl_<asterisk>um_masked_fixed_reg_input.nii.gz and atlas_in_tissue_space.nii.gz for each sample to a target dir.
    +Use ``reg_check`` from UNRAVEL to check registration QC, copies autofl_`*`um_masked_fixed_reg_input.nii.gz and atlas_in_tissue_space.nii.gz for each sample to a target dir.
     
    -Usage:
    -------
    -    reg_check -e <list of experiment directories> # copies to the current working directory
    -    reg_check -e <list of experiment directories> -td <target_output_dir
    +Usage for copying to the current working directory:
    +---------------------------------------------------
    +    reg_check [-ro reg_outputs] [-fri fixed_reg_in] [-wa warped_atlas] [-d list of paths] [-p sample??] [-v]
    +
    +Usage for copying to a target directory:
    +    reg_check -td <path/target_output_dir> [-ro reg_outputs] [-fri fixed_reg_in] [-wa warped_atlas] [-d list of paths] [-p sample??] [-v]
     """
     
    -import argparse
     from pathlib import Path
     from rich import print
     from rich.live import Live
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
    +
     from unravel.core.config import Configuration 
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, initialize_progress_bar, get_samples, copy_files
     
    @@ -376,16 +378,19 @@ 

    Source code for unravel.register.reg_check

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-e', '--exp_paths', help='List of experiment dir paths w/ sample?? dirs to process.', nargs='*', default=None, action=SM) - parser.add_argument('-p', '--pattern', help='Pattern for sample?? dirs. Use cwd if no matches.', default='sample??', action=SM) - parser.add_argument('-d', '--dirs', help='List of sample?? dir names or paths to dirs to process', nargs='*', default=None, action=SM) - parser.add_argument('-td', '--target_dir', help='path/target_output_dir name for aggregating outputs from all samples (cwd if omitted).', default=None, action=SM) - parser.add_argument('-ro', '--reg_outputs', help="Name of folder w/ outputs from ``reg``. Default: reg_outputs", default="reg_outputs", action=SM) - parser.add_argument('-fri', '--fixed_reg_in', help='Fixed image from registration ``reg``. Default: autofl_50um_masked_fixed_reg_input.nii.gz', default="autofl_50um_masked_fixed_reg_input.nii.gz", action=SM) - parser.add_argument('-wa', '--warped_atlas', help='Warped atlas image from ``reg``. Default: atlas_CCFv3_2020_30um_in_tissue_space.nii.gz', default="atlas_CCFv3_2020_30um_in_tissue_space.nii.gz", action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity.', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-td', '--target_dir', help='path/target_output_dir name for aggregating outputs from all samples (cwd if omitted).', default=None, action=SM) + opts.add_argument('-ro', '--reg_outputs', help="Name of folder w/ outputs from ``reg``. Default: reg_outputs", default="reg_outputs", action=SM) + opts.add_argument('-fri', '--fixed_reg_in', help='Fixed image from registration ``reg``. Default: autofl_50um_masked_fixed_reg_input.nii.gz', default="autofl_50um_masked_fixed_reg_input.nii.gz", action=SM) + opts.add_argument('-wa', '--warped_atlas', help='Warped atlas image from ``reg``. Default: atlas_CCFv3_2020_30um_in_tissue_space.nii.gz', default="atlas_CCFv3_2020_30um_in_tissue_space.nii.gz", action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-d', '--dirs', help='Paths to sample?? dirs and/or dirs containing them (space-separated) for batch processing. Default: current dir', nargs='*', default=None, action=SM) + general.add_argument('-p', '--pattern', help='Pattern for directories to process. Default: sample??', default='sample??', action=SM) + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    @@ -403,14 +408,11 @@

    Source code for unravel.register.reg_check

         target_dir = Path(args.target_dir) if args.target_dir is not None else Path.cwd()
         target_dir.mkdir(exist_ok=True, parents=True)
     
    -    samples = get_samples(args.dirs, args.pattern, args.exp_paths)
    -    
    -    progress, task_id = initialize_progress_bar(len(samples), "[red]Processing samples...")
    -    with Live(progress):
    -        for sample in samples:
    +    sample_paths = get_samples(args.dirs, args.pattern, args.verbose)
     
    -            # Resolve path to sample folder
    -            sample_path = Path(sample).resolve() if sample != Path.cwd().name else Path.cwd()
    +    progress, task_id = initialize_progress_bar(len(sample_paths), "[red]Processing samples...")
    +    with Live(progress):
    +        for sample_path in sample_paths:
     
                 # Define input paths
                 source_path = sample_path / args.reg_outputs
    diff --git a/_modules/unravel/register/reg_check_brain_mask.html b/_modules/unravel/register/reg_check_brain_mask.html
    index 2d6e18e8..52c1faba 100644
    --- a/_modules/unravel/register/reg_check_brain_mask.html
    +++ b/_modules/unravel/register/reg_check_brain_mask.html
    @@ -354,35 +354,41 @@ 

    Source code for unravel.register.reg_check_brain_mask

    #!/usr/bin/env python3 """ -Use ``reg_check_brain_mask`` from UNRAVEL for masking QC, copies autofluo_50um.nii.gz and autofluo_50_masked.nii.gz for each sampled to a target dir +Use ``reg_check_brain_mask`` from UNRAVEL for masking QC, copies autofluo_50um.nii.gz and autofluo_50_masked.nii.gz for each sample to a target directory. -Usage: ------- - reg_check_brain_mask -e <list of experiment directories> # copies to the current working directory - reg_check_brain_mask -e <list of experiment directories> -td <target_output_dir +Usage for copying to the current working directory: +--------------------------------------------------- + reg_check_brain_mask [-d list of paths] [-p sample??] [-v] + +Usage for copying to a target directory: +---------------------------------------- + reg_check_brain_mask -td <target_output_dir> [-d list of paths] [-p sample??] [-v] """ -import argparse from pathlib import Path from rich import print from rich.live import Live from rich.traceback import install -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM from unravel.core.config import Configuration from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, initialize_progress_bar, get_samples, copy_files +
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-e', '--exp_paths', help='List of experiment dir paths w/ sample?? dirs to process.', nargs='*', default=None, action=SM) - parser.add_argument('-p', '--pattern', help='Pattern for sample?? dirs. Use cwd if no matches.', default='sample??', action=SM) - parser.add_argument('-d', '--dirs', help='List of sample?? dir names or paths to dirs to process', nargs='*', default=None, action=SM) - parser.add_argument('-td', '--target_dir', help='path/target_output_dir name for aggregating outputs from all samples. If omitted, uses cwd', default=None, action=SM) - parser.add_argument('-i', '--input', help='Output path. Default: reg_inputs/autofl_50um.nii.gz', default="reg_inputs/autofl_50um.nii.gz", action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity.', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + opts = parser.add_argument_group('Optional args') + opts.add_argument('-td', '--target_dir', help='path/target_output_dir name for aggregating outputs from all samples. If omitted, uses cwd', default=None, action=SM) + opts.add_argument('-i', '--input', help='Input path relative to sample??/. Default: reg_inputs/autofl_50um.nii.gz', default="reg_inputs/autofl_50um.nii.gz", action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-d', '--dirs', help='Paths to sample?? dirs and/or dirs containing them (space-separated) for batch processing. Default: current dir', nargs='*', default=None, action=SM) + general.add_argument('-p', '--pattern', help='Pattern for directories to process. Default: sample??', default='sample??', action=SM) + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    @@ -400,14 +406,11 @@

    Source code for unravel.register.reg_check_brain_mask

    target_dir = Path(args.target_dir) if args.target_dir is not None else Path.cwd() target_dir.mkdir(exist_ok=True, parents=True) - samples = get_samples(args.dirs, args.pattern, args.exp_paths) - - progress, task_id = initialize_progress_bar(len(samples), "[red]Processing samples...") - with Live(progress): - for sample in samples: + sample_paths = get_samples(args.dirs, args.pattern, args.verbose) - # Resolve path to sample folder - sample_path = Path(sample).resolve() if sample != Path.cwd().name else Path.cwd() + progress, task_id = initialize_progress_bar(len(sample_paths), "[red]Processing samples...") + with Live(progress): + for sample_path in sample_paths: # Define input paths source_path = sample_path / Path(args.input).parent diff --git a/_modules/unravel/register/reg_prep.html b/_modules/unravel/register/reg_prep.html index 0a096bdd..dcd5e494 100644 --- a/_modules/unravel/register/reg_prep.html +++ b/_modules/unravel/register/reg_prep.html @@ -356,31 +356,35 @@

    Source code for unravel.register.reg_prep

     """
     Use ``reg_prep`` from UNRAVEL to load a full resolution autofluo image and resamples to a lower resolution for registration.
     
    -Usage:
    -------
    -    reg_prep -i <asterisk>.czi [-e <list of paths to exp dirs>] [-v]
    -
    -Run command from the experiment directory w/ sample?? folder(s), a sample?? folder, or provide -e or -d arguments.
    -
     Input examples (path is relative to ./sample??; 1st glob match processed): 
    -    <asterisk>.czi, autofluo/<asterisk>.tif series, autofluo, <asterisk>.tif, or <asterisk>.h5 
    +    `*`.czi, autofluo/`*`.tif series, autofluo, `*`.tif, or `*`.h5 
     
     Outputs: 
    -    ./sample??/reg_inputs/autofl_<asterisk>um.nii.gz
    -    ./sample??/reg_inputs/autofl_<asterisk>um_tifs/<asterisk>.tif series (used for training ilastik for ``seg_brain_mask``) 
    +    ./sample??/reg_inputs/autofl_`*`um.nii.gz
    +    ./sample??/reg_inputs/autofl_`*`um_tifs/`*`.tif series (used for training ilastik for ``seg_brain_mask``)
    +
    +Note:
    +    - If -d is not provided, the current directory is used to search for sample?? dirs to process. 
    +    - If the current dir is a sample?? dir, it will be processed.
    +    - If -d is provided, the specified dirs and/or dirs containing sample?? dirs will be processed.
    +    - If -p is not provided, the default pattern for dirs to process is 'sample??'.
     
     Next command: 
         ``seg_copy_tifs`` for ``seg_brain_mask`` or ``reg``
    +
    +Usage:
    +------
    +    reg_prep -i `*`.czi [-md path/metadata.txt] [For .czi: --channel 0] [-o reg_inputs/autofl_50um.nii.gz] [--reg_res 50] [--zoom_order 0] [--miracl] [-d list of paths] [-p sample??] [-v]
     """
     
    -import argparse
     import numpy as np
     from pathlib import Path
     from rich import print
     from rich.live import Live
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
    +
     from unravel.core.config import Configuration
     from unravel.core.img_io import load_3D_img, load_image_metadata_from_txt, resolve_path, save_as_tifs, save_as_nii
     from unravel.core.img_tools import resample, reorient_for_raw_to_nii_conv
    @@ -390,19 +394,26 @@ 

    Source code for unravel.register.reg_prep

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-e', '--exp_paths', help='List of experiment dir paths w/ sample?? dirs to process.', nargs='*', default=None, action=SM) - parser.add_argument('-p', '--pattern', help='Pattern for sample?? dirs. Use cwd if no matches.', default='sample??', action=SM) - parser.add_argument('-d', '--dirs', help='List of sample?? dir names or paths to dirs to process', nargs='*', default=None, action=SM) - parser.add_argument('-i', '--input', help='Full res image input path relative (rel_path) to ./sample??', required=True, action=SM) - parser.add_argument('-md', '--metadata', help='path/metadata.txt. Default: parameters/metadata.txt', default="parameters/metadata.txt", action=SM) - parser.add_argument('-c', '--channel', help='.czi channel number. Default: 0 for autofluo', default=0, type=int, action=SM) - parser.add_argument('-o', '--output', help='Output path. Default: reg_inputs/autofl_50um.nii.gz', default="reg_inputs/autofl_50um.nii.gz", action=SM) - parser.add_argument('-r', '--reg_res', help='Resample input to this res in um for reg. Default: 50', default=50, type=int, action=SM) - parser.add_argument('-zo', '--zoom_order', help='Order for resampling (scipy.ndimage.zoom). Default: 1', default=1, type=int, action=SM) - parser.add_argument('-mi', '--miracl', help="Include reorientation step to mimic MIRACL's tif to .nii.gz conversion", action='store_true', default=False) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='Full res image input path relative (rel_path) to ./sample??', required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-md', '--metadata', help='path/metadata.txt. Default: parameters/metadata.txt', default="parameters/metadata.txt", action=SM) + opts.add_argument('-c', '--channel', help='.czi channel number. Default: 0 for autofluo', default=0, type=int, action=SM) + opts.add_argument('-o', '--output', help='Output path. Default: reg_inputs/autofl_50um.nii.gz', default="reg_inputs/autofl_50um.nii.gz", action=SM) + opts.add_argument('-r', '--reg_res', help='Resample input to this res in um for reg. Default: 50', default=50, type=int, action=SM) + opts.add_argument('-zo', '--zoom_order', help='Order for resampling (scipy.ndimage.zoom). Default: 1', default=1, type=int, action=SM) + + compatability = parser.add_argument_group('Compatability options') + compatability.add_argument('-mi', '--miracl', help="Include reorientation step to mimic MIRACL's tif to .nii.gz conversion", action='store_true', default=False) + + general = parser.add_argument_group('General arguments') + general.add_argument('-d', '--dirs', help='Paths to sample?? dirs and/or dirs containing them (space-separated) for batch processing. Default: current dir', nargs='*', default=None, action=SM) + general.add_argument('-p', '--pattern', help='Pattern for directories to process. Default: sample??', default='sample??', action=SM) + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    @@ -444,14 +455,11 @@

    Source code for unravel.register.reg_prep

         Configuration.verbose = args.verbose
         verbose_start_msg()
     
    -    samples = get_samples(args.dirs, args.pattern, args.exp_paths)
    -    
    -    progress, task_id = initialize_progress_bar(len(samples), "[red]Processing samples...")
    -    with Live(progress):
    -        for sample in samples:
    +    sample_paths = get_samples(args.dirs, args.pattern, args.verbose)
     
    -            # Resolve path to sample folder
    -            sample_path = Path(sample).resolve() if sample != Path.cwd().name else Path.cwd()
    +    progress, task_id = initialize_progress_bar(len(sample_paths), "[red]Processing samples...")
    +    with Live(progress):
    +        for sample_path in sample_paths:
     
                 # Define output
                 output = resolve_path(sample_path, args.output, make_parents=True)
    diff --git a/_modules/unravel/segment/brain_mask.html b/_modules/unravel/segment/brain_mask.html
    index 8cc569d5..d082d809 100644
    --- a/_modules/unravel/segment/brain_mask.html
    +++ b/_modules/unravel/segment/brain_mask.html
    @@ -354,37 +354,39 @@ 

    Source code for unravel.segment.brain_mask

     #!/usr/bin/env python3
     
     """
    -Use ``seg_brain_mask`` from UNRAVEL to run a trained ilastik project (pixel classification) to mask the brain (often better registration).
    -
    -Usage:
    -------
    -    seg_brain_mask -ie <path/ilastik_executable> -ilp <path/brain_mask.ilp> [-i reg_inputs/autofl_50um.nii.gz] [-r 50] [-v] 
    +Use ``seg_brain_mask`` from UNRAVEL to use a trained ilastik project (pixel classification) to mask the brain in resampled autofluo images (often improves registration).
     
     Prereqs: 
    -    - Train ilastik (tissue = label 1) w/ tifs from reg_inputs/autofl_<asterisk>um_tifs/<asterisk>.tif (from ``reg_prep``)
    +    - Organize training tif slices (from ``seg_copy_tifs``) into a single folder.
    +    - Train an Ilastik project to segment the brain (https://b-heifets.github.io/UNRAVEL/guide.html#train-an-ilastik-project).
    +    - Train ilastik (tissue = label 1) w/ tifs from reg_inputs/autofl_`*`um_tifs/`*`.tif (from ``reg_prep``)
         - Save brain_mask.ilp in experiment directory of use -ilp
     
     Inputs: 
    -    - reg_inputs/autofl_<asterisk>um.nii.gz
    +    - reg_inputs/autofl_`*`um.nii.gz
         - brain_mask.ilp # in exp dir
     
     Outputs: 
    -    - reg_inputs/autofl_<asterisk>um_tifs_ilastik_brain_seg/slice_<asterisk>.tif series
    -    - reg_inputs/autofl_<asterisk>um_brain_mask.nii.gz (can be used for ``reg`` and ``vstats_z_score``)
    -    - reg_inputs/autofl_<asterisk>um_masked.nii.gz
    +    - reg_inputs/autofl_`*`um_tifs_ilastik_brain_seg/slice_`*`.tif series
    +    - reg_inputs/autofl_`*`um_brain_mask.nii.gz (can be used for ``reg`` and ``vstats_z_score``)
    +    - reg_inputs/autofl_`*`um_masked.nii.gz
     
     Next command: 
         - ``reg``
    +
    +Usage:
    +------
    +    seg_brain_mask -ie <path/ilastik_executable> -ilp <path/brain_mask.ilp> [-i reg_inputs/autofl_50um.nii.gz] [-d list of paths] [-p sample??] [-v]
     """
     
    -import argparse
     import numpy as np
     from pathlib import Path
     from rich import print
     from rich.live import Live
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
    +
     from unravel.core.config import Configuration 
     from unravel.core.img_io import load_3D_img, resolve_path, save_as_nii
     from unravel.core.img_tools import pixel_classification
    @@ -394,15 +396,20 @@ 

    Source code for unravel.segment.brain_mask

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-e', '--exp_paths', help='List of experiment dir paths w/ sample?? dirs to process.', nargs='*', default=None, action=SM) - parser.add_argument('-p', '--pattern', help='Pattern for sample?? dirs. Use cwd if no matches.', default='sample??', action=SM) - parser.add_argument('-d', '--dirs', help='List of sample?? dir names or paths to dirs to process', nargs='*', default=None, action=SM) - parser.add_argument('-ie', '--ilastik_exe', help='path/ilastik_executable.', required=True, action=SM) - parser.add_argument('-ilp', '--ilastik_prj', help='path/brain_mask.ilp. Default: brain_mask.ilp', default='brain_mask.ilp', action=SM) - parser.add_argument('-i', '--input', help='reg_inputs/autofl_50um.nii.gz (from ``reg_prep``)', default="reg_inputs/autofl_50um.nii.gz", action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-ie', '--ilastik_exe', help='path/ilastik_executable.', required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-ilp', '--ilastik_prj', help='path/brain_mask.ilp. Default: brain_mask.ilp', default='brain_mask.ilp', action=SM) + opts.add_argument('-i', '--input', help='Resampled autofluo image. Default: reg_inputs/autofl_50um.nii.gz (from ``reg_prep``)', default="reg_inputs/autofl_50um.nii.gz", action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-d', '--dirs', help='Paths to sample?? dirs and/or dirs containing them (space-separated) for batch processing. Default: current dir', nargs='*', default=None, action=SM) + general.add_argument('-p', '--pattern', help='Pattern for directories to process. Default: sample??', default='sample??', action=SM) + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    @@ -416,13 +423,11 @@

    Source code for unravel.segment.brain_mask

         Configuration.verbose = args.verbose
         verbose_start_msg()
     
    -    samples = get_samples(args.dirs, args.pattern, args.exp_paths)
    +    sample_paths = get_samples(args.dirs, args.pattern, args.verbose)
     
    -    progress, task_id = initialize_progress_bar(len(samples), "[red]Processing samples...")
    +    progress, task_id = initialize_progress_bar(len(sample_paths), "[red]Processing samples...")
         with Live(progress):
    -        for sample in samples:
    -            # Resolve path to sample folder
    -            sample_path = Path(sample).resolve() if sample != Path.cwd().name else Path.cwd()
    +        for sample_path in sample_paths:
     
                 # Define input and output paths
                 autofl_img_path = resolve_path(sample_path, path_or_pattern=args.input)
    diff --git a/_modules/unravel/segment/copy_tifs.html b/_modules/unravel/segment/copy_tifs.html
    index 5a9b30b7..215be2ae 100644
    --- a/_modules/unravel/segment/copy_tifs.html
    +++ b/_modules/unravel/segment/copy_tifs.html
    @@ -358,14 +358,13 @@ 

    Source code for unravel.segment.copy_tifs

     
     Usage to prep for ``seg_brain_mask``:
     -------------------------------------
    -    seg_copy_tifs -i reg_inputs/autofl_50um_tifs -s 0000 0005 0050 -o brain_mask
    +    seg_copy_tifs -s 0000 0005 0050 [-td brain_mask] [-i reg_inputs/autofl_50um_tifs] [-d list of paths] [-p sample??] [-v]
     
     Usage to prep for ``seg_ilastik`` to segment full resolution immunofluorescence images:
     ---------------------------------------------------------------------------------------
    -    seg_copy_tifs -i raw_tif_dir -s 0100 0500 1000 -o ilastik_segmentation
    +    seg_copy_tifs -i <raw_tif_dir> -s 0100 0500 1000 -td ilastik_segmentation [-d list of paths] [-p sample??] [-v]
     """
     
    -import argparse
     import shutil
     from glob import glob
     from pathlib import Path
    @@ -373,23 +372,28 @@ 

    Source code for unravel.segment.copy_tifs

     from rich.live import Live
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
    +
     from unravel.core.config import Configuration 
    -from unravel.core.img_io import resolve_path
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, initialize_progress_bar, get_samples
     
     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-e', '--exp_paths', help='List of experiment dir paths w/ sample?? dirs to process.', nargs='*', default=None, action=SM) - parser.add_argument('-p', '--pattern', help='Pattern for sample?? dirs. Use cwd if no matches.', default='sample??', action=SM) - parser.add_argument('-d', '--dirs', help='List of sample?? dir names or paths to dirs to process', nargs='*', default=None, action=SM) - parser.add_argument('-i', '--input', help='reg_inputs/autofl_50um_tifs (from ``reg_prep``) or name of directory with raw tifs', default=None, action=SM) - parser.add_argument('-o', '--output', help='path/dir to copy TIF files. (e.g., brain_mask or ilastik_segmentation)', required=True, action=SM) - parser.add_argument('-s', '--slices', help='List of slice numbers to copy (4 digits each; space separated)', nargs='*', type=str, default=[]) - parser.add_argument('-v', '--verbose', help='Increase verbosity.', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-s', '--slices', help='List of slice numbers to copy (4 digits each; space separated)', nargs='*', type=str, required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + reqs.add_argument('-td', '--target_dir', help='path/target_dir to copy TIF files to. (e.g., brain_mask or ilastik_segmentation). Default: current dir', action=SM) + opts.add_argument('-i', '--input', help='reg_inputs/autofl_50um_tifs (from ``reg_prep``) or rel_path to dir w/ raw tifs', default=None, action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-d', '--dirs', help='Paths to sample?? dirs and/or dirs containing them (space-separated) for batch processing. Default: current dir', nargs='*', default=None, action=SM) + general.add_argument('-p', '--pattern', help='Pattern for directories to process. Default: sample??', default='sample??', action=SM) + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    @@ -397,20 +401,37 @@

    Source code for unravel.segment.copy_tifs

     
    [docs] def copy_specific_slices(sample_path, source_dir, target_dir, slice_numbers, verbose=False): - """Copy the specified slices to the target directory. + """Copy the specified tif slices from the source directory to the target directory. - Args: - - sample_path (Path): Path to the sample directory. - - source_dir (Path): Path to the source directory containing the .tif files. - - target_dir (Path): Path to the target directory where the selected slices will be copied. - - slice_numbers (list): List of slice numbers to copy.""" + Parameters: + ----------- + sample_path : Path or str + Path to the sample directory. + source_dir : Path or str + Path (relative to sample_path) to the source directory containing the .tif files to copy. + target_dir : Path or str + Path to the target directory where the selected slices will be copied. + slice_numbers : list + List of slice numbers to copy (4 digits each). + verbose : bool + Print verbose output. + """ + source_path = Path(sample_path) / source_dir + target_path = Path(sample_path) / target_dir + + tif_files = list(source_path.glob('*.tif')) + if not tif_files: + print(f"\n [red1]No .tif files found in {source_path}\n") + return - for file_path in source_dir.glob('*.tif'): + target_path.mkdir(exist_ok=True, parents=True) + + for file_path in Path(source_dir).glob('*.tif'): if any(file_path.stem.endswith(f"{slice:04}") for slice in map(int, slice_numbers)): - dest_file = target_dir / f'{sample_path.name}_{file_path.name}' + dest_file = target_path / f'{Path(sample_path).name}_{file_path.name}' shutil.copy(file_path, dest_file) if verbose: - print(f"Copied {file_path} to {dest_file}")
    + print(f" Copied {file_path} to {dest_file}")
    @@ -423,24 +444,15 @@

    Source code for unravel.segment.copy_tifs

         Configuration.verbose = args.verbose
         verbose_start_msg()
     
    -    # Create the target directory for copying the selected slices
    -    target_dir = Path(args.output)
    -    target_dir.mkdir(exist_ok=True, parents=True)
    +    sample_paths = get_samples(args.dirs, args.pattern, args.verbose)
     
    -    samples = get_samples(args.dirs, args.pattern, args.exp_paths)
    -    
    -    progress, task_id = initialize_progress_bar(len(samples), "[red]Processing samples...")
    +    progress, task_id = initialize_progress_bar(len(sample_paths), "[red]Processing samples...")
         with Live(progress):
    -        for sample in samples:
    -
    -            # Resolve path to sample folder
    -            sample_path = Path(sample).resolve() if sample != Path.cwd().name else Path.cwd()
    +        for sample_path in sample_paths:
     
    -            # Define input paths
    -            source_path = resolve_path(sample_path, args.input)
    +            target_dir = Path(sample_path) / args.target_dir if args.target_dir else Path.cwd()
     
    -            # Copy the selected slices to the target directory
    -            copy_specific_slices(sample_path, source_path, target_dir, args.slices, args.verbose)
    +            copy_specific_slices(sample_path, args.input, target_dir, args.slices, args.verbose)
     
                 progress.update(task_id, advance=1)
     
    diff --git a/_modules/unravel/segment/ilastik_pixel_classification.html b/_modules/unravel/segment/ilastik_pixel_classification.html
    index 641817fd..8960895e 100644
    --- a/_modules/unravel/segment/ilastik_pixel_classification.html
    +++ b/_modules/unravel/segment/ilastik_pixel_classification.html
    @@ -354,22 +354,12 @@ 

    Source code for unravel.segment.ilastik_pixel_classification

    #!/usr/bin/env python3 """ -Use ``seg_ilastik`` from UNRAVEL to run a trained ilastik project (pixel classification) to segment features in images. - -Usage if input tifs exist: --------------------------- - seg_ilastik -ie <path/ilastik_executable> -t cfos -o cfos_seg -ilp path/ilastik_project.ilp - -Note: - - This module uses tifs for processing with Ilastik. - - If your raw images are not tifs, use -i to make them from a .czi or another image format. - -Usage if input tifs need to be created: ------------------------------------------------------------------ - seg_ilastik -ie <path/ilastik_executable> -i <asterisk>.czi -o cfos_seg -ilp path/ilastik_project.ilp +Use ``seg_ilastik`` from UNRAVEL to use a trained ilastik project (pixel classification) to segment features (e.g., c-Fos+ cells) in images. Prereqs: - - To train an Ilastik project, organize training slices (tifs) into folder (e.g., 3 slices from 3 samples per condition). + - Organize training tif slices (from ``seg_copy_tifs``) into a single folder. + - Train an Ilastik project with the desired features (https://b-heifets.github.io/UNRAVEL/guide.html#train-an-ilastik-project). + - Add training slices (tifs) into folder (e.g., 3 slices from 3 samples per condition). - ``seg_copy_tifs`` can aggregate these slices into a single folder for training. Ilastik executable files for each OS: @@ -377,11 +367,19 @@

    Source code for unravel.segment.ilastik_pixel_classification

    - Mac: /Applications/Ilastik.app/Contents/ilastik-release/run_ilastik.sh - Windows: C:\\Program Files\\ilastik-1.3.3post3\\run_ilastik.bat -For a guide on training Ilastik, see: - - https://b-heifets.github.io/UNRAVEL/guide.html#train-an-ilastik-project +Note: + - This module uses tifs for processing with Ilastik. + - If your raw images are not tifs, use -i to make them from a .czi or another image format. + +Usage if input tifs exist: +-------------------------- + seg_ilastik -ie path/ilastik_executable -ilp path/ilastik_project.ilp -t cfos -o cfos_seg [-l 1 2 3] [-rmo] [-d path/to/sample??] [-p sample??] [-v] + +Usage if input tifs need to be created: +----------------------------------------------------------------- + seg_ilastik -ie path/ilastik_executable -ilp path/ilastik_project.ilp -i `*`.czi -o cfos_seg [-l 1 2 3] [-rmi] [-rmo] [-d path/to/sample??] [-p sample??] [-v] """ -import argparse import os import nibabel as nib import numpy as np @@ -391,7 +389,8 @@

    Source code for unravel.segment.ilastik_pixel_classification

    from rich.live import Live from rich.traceback import install -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.img_io import load_3D_img, save_as_tifs from unravel.core.img_tools import pixel_classification @@ -401,26 +400,32 @@

    Source code for unravel.segment.ilastik_pixel_classification

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-e', '--exp_paths', help='List of experiment dir paths w/ sample?? dirs to process.', nargs='*', default=None, action=SM) - parser.add_argument('-p', '--pattern', help='Pattern for sample?? dirs. Use cwd if no matches.', default='sample??', action=SM) - parser.add_argument('-d', '--dirs', help='List of sample?? dir names or paths to dirs to process', nargs='*', default=None, action=SM) - parser.add_argument('-ie', '--ilastik_exe', help='path/ilastik_executable.', required=True, action=SM) - parser.add_argument('-ilp', '--ilastik_prj', help='path/ilastik_project.ilp', required=True, action=SM) - parser.add_argument('-t', '--tifs_dir', help='path/input_dir_w_tifs', required=True, action=SM) - parser.add_argument('-i', '--input', help='If path/input_dir_w_tifs does not exist, provide a rel_path/image to make it', action=SM) - parser.add_argument('-c', '--channel', help='.czi channel number. Default: 1', default=1, type=int, metavar='') - parser.add_argument('-o', '--output', help='output dir name', default=None, action=SM) - parser.add_argument('-l', '--labels', help='List of segmetation label IDs to save as binary .nii.gz images. Default: 1', default=1, nargs='*', type=int, action=SM) - parser.add_argument('-rmi', '--rm_in_tifs', help='Delete the dir w/ the input tifs (e.g., if a *.czi was the input)', action='store_true', default=False) - parser.add_argument('-rmo', '--rm_out_tifs', help='Delete the dir w/ the output tifs', action='store_true', default=False) - parser.add_argument('-log', '--ilastik_log', help='Show Ilastik log', action='store_true') - parser.add_argument('-v', '--verbose', help='Increase verbosity.', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-ie', '--ilastik_exe', help='path/ilastik_executable.', required=True, action=SM) + reqs.add_argument('-ilp', '--ilastik_prj', help='path/ilastik_project.ilp', required=True, action=SM) + reqs.add_argument('-t', '--tifs_dir', help='path/input_dir_w_tifs', required=True, action=SM) + reqs.add_argument('-o', '--output', help='output dir name', required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-i', '--input', help='If path/input_dir_w_tifs does not exist, provide a rel_path/image to make it', action=SM) + opts.add_argument('-c', '--channel', help='.czi channel number (if this is the input image type). Default: 1', default=1, type=int, metavar='') + opts.add_argument('-l', '--labels', help='List of segmetation label IDs to save as binary .nii.gz images. Default: 1', default=1, nargs='*', type=int, action=SM) + opts.add_argument('-rmi', '--rm_in_tifs', help='Delete the dir w/ the input tifs (e.g., if a *.czi was the input)', action='store_true', default=False) + opts.add_argument('-rmo', '--rm_out_tifs', help='Delete the dir w/ the output tifs. These have all labels. .nii.gz output(s) are smaller.', action='store_true', default=False) + + general = parser.add_argument_group('General arguments') + general.add_argument('-d', '--dirs', help='Paths to sample?? dirs and/or dirs containing them (space-separated) for batch processing. Default: current dir', nargs='*', default=None, action=SM) + general.add_argument('-p', '--pattern', help='Pattern for directories to process. Default: sample??', default='sample??', action=SM) + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    -# TODO: Consolidate pixel_segmentation() in unravel/core/img_tools.py +# TODO: Group args +# TODO: Test rich formating for help messages +# TODO: Consolidate -i and -t into one arg
    @@ -436,7 +441,8 @@

    Source code for unravel.segment.ilastik_pixel_classification

    def save_labels_as_masks(tif_dir, labels, segmentation_dir, output_name): img = load_3D_img(tif_dir) for label in labels: - print(f"\n Converting label {label} to mask and saving as .nii.gz in {segmentation_dir}\n") + print(f"\n Converting label {label} to binary mask and saving as .nii.gz in {segmentation_dir}\n") + # img == label creates a boolean array where pixels equal to label are True (1) and all others are False (0). label_img = (img == label).astype(np.uint8) nifti_img = nib.Nifti1Image(label_img, np.eye(4)) nib.save(nifti_img, segmentation_dir.joinpath(f"{output_name}_{label}.nii.gz"))
    @@ -452,14 +458,11 @@

    Source code for unravel.segment.ilastik_pixel_classification

    Configuration.verbose = args.verbose verbose_start_msg() - samples = get_samples(args.dirs, args.pattern, args.exp_paths) - - progress, task_id = initialize_progress_bar(len(samples), "[red]Processing samples...") - with Live(progress): - for sample in samples: + sample_paths = get_samples(args.dirs, args.pattern, args.verbose) - # Resolve path to sample folder - sample_path = Path(sample).resolve() if sample != Path.cwd().name else Path.cwd() + progress, task_id = initialize_progress_bar(len(sample_paths), "[red]Processing samples...") + with Live(progress): + for sample_path in sample_paths: # Define output and skip processing if it already exists segmentation_dir = sample_path / args.output diff --git a/_modules/unravel/segment/labels_to_masks.html b/_modules/unravel/segment/labels_to_masks.html index a7bb8bcf..78c3fd42 100644 --- a/_modules/unravel/segment/labels_to_masks.html +++ b/_modules/unravel/segment/labels_to_masks.html @@ -358,11 +358,9 @@

    Source code for unravel.segment.labels_to_masks

    < Usage: ------ - save_labels_as_masks.py -t seg_ilastik_1/IlastikSegmentation -o Ai14_seg_ilasik_1 -v - + save_labels_as_masks.py -i seg_ilastik_1/IlastikSegmentation -o Ai14_seg_ilasik_1 [-l 1 2 3] [-d dirs] [-p pattern] [-v] """ -import argparse import nibabel as nib import numpy as np from glob import glob @@ -371,7 +369,8 @@

    Source code for unravel.segment.labels_to_masks

    < from rich.live import Live from rich.traceback import install -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.img_io import load_3D_img from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, get_samples, print_func_name_args_times, initialize_progress_bar @@ -380,15 +379,20 @@

    Source code for unravel.segment.labels_to_masks

    <
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-e', '--exp_paths', help='List of experiment dir paths w/ sample?? dirs to process.', nargs='*', default=None, action=SM) - parser.add_argument('-p', '--pattern', help='Pattern for sample?? dirs. Use cwd if no matches.', default='sample??', action=SM) - parser.add_argument('-d', '--dirs', help='List of sample?? dir names or paths to dirs to process', nargs='*', default=None, action=SM) - parser.add_argument('-i', '--input', help='rel_path/image (can be glob pattern [e.g., to tif dir or 1st tif])', required=True, action=SM) - parser.add_argument('-o', '--output', help='NIfTI output file name (no extension)', required=True, action=SM) - parser.add_argument('-l', '--labels', help='List of segmetation label IDs to save as binary .nii.gz images. Default: 1', default=1, nargs='*', type=int, action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity.', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='rel_path/image (can be glob pattern [e.g., to tif dir or 1st tif])', required=True, action=SM) + reqs.add_argument('-o', '--output', help='NIfTI output file name (no extension)', required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-l', '--labels', help='List of segmetation label IDs to save as binary .nii.gz images. Default: 1', default=1, nargs='*', type=int, action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-d', '--dirs', help='Paths to sample?? dirs and/or dirs containing them (space-separated) for batch processing. Default: current dir', nargs='*', default=None, action=SM) + general.add_argument('-p', '--pattern', help='Pattern for directories to process. Default: sample??', default='sample??', action=SM) + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    @@ -414,14 +418,11 @@

    Source code for unravel.segment.labels_to_masks

    < Configuration.verbose = args.verbose verbose_start_msg() - samples = get_samples(args.dirs, args.pattern, args.exp_paths) - - progress, task_id = initialize_progress_bar(len(samples), "[red]Processing samples...") - with Live(progress): - for sample in samples: + sample_paths = get_samples(args.dirs, args.pattern, args.verbose) - # Resolve path to sample folder - sample_path = Path(sample).resolve() if sample != Path.cwd().name else Path.cwd() + progress, task_id = initialize_progress_bar(len(sample_paths), "[red]Processing samples...") + with Live(progress): + for sample_path in sample_paths: img_path = next(sample_path.glob(str(args.input)), None) if img_path is None: diff --git a/_modules/unravel/unravel_commands.html b/_modules/unravel/unravel_commands.html index 0d841773..8ff82c58 100644 --- a/_modules/unravel/unravel_commands.html +++ b/_modules/unravel/unravel_commands.html @@ -354,7 +354,16 @@

    Source code for unravel.unravel_commands

     #!/usr/bin/env python3
     
     """
    -Use ``unravel_commands`` or ``uc`` to print a list of commands available in the unravel package. 
    +Use ``unravel_commands`` or ``uc`` to print a list of commands available in the UNRAVEL package. 
    +
    +For help on a ``command``, run: 
    +<command> -h
    +
    +Note: 
    +    - Documentation: https://b-heifets.github.io/UNRAVEL/
    +    - Commands are roughly organized by the order of the workflow and/or the relatedness of the commands.
    +    - Filtering is case-insensitive and matches substrings in the printed lines (regex).
    +    - For example, use of -f with -d will find matches in the command name and/or description, preserving those lines.
     
     Usage to print common commands and descriptions:
     ------------------------------------------------
    @@ -367,17 +376,6 @@ 

    Source code for unravel.unravel_commands

     Usage to print commands matching a specific string:
     ---------------------------------------------------
         unravel_commands -f <string>
    -
    -For help on a command, run: 
    -    <command> -h
    -
    -Note: 
    -    - Commands are roughly organized by the order of the workflow and/or the relatedness of the commands.
    -    - Filtering is case-insensitive and matches substrings in the printed lines (regex).
    -    - For example, use of -f with -d will find matches in the command name and/or description, presering those lines.
    -
    -Documentation:
    -    https://b-heifets.github.io/UNRAVEL/
     """
     
     extended_help = """
    @@ -407,23 +405,25 @@ 

    Source code for unravel.unravel_commands

         - Use the `which` command again to verify that the correct command is being invoked: which unravel_reg  # or which reg if using an alias
     """
     
    -import argparse
     import re
     from rich import print
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
    +
     
     
     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-c', '--common', help='Only print common commands', action='store_true', default=False) - parser.add_argument('-m', '--module', help='Print the module (script name and location in the unravel package) for each command', action='store_true', default=False) - parser.add_argument('-d', '--description', help="Print the description of each command's purpose", action='store_true', default=False) - parser.add_argument('-f', '--filter', help='Filter commands by a string (e.g, -f reg)', type=str, action=SM) - parser.add_argument('--extended-help', help='Help on diagnosing and fixing command conflicts', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + opts = parser.add_argument_group('Optional args') + opts.add_argument('-c', '--common', help='Only print common commands', action='store_true', default=False) + opts.add_argument('-m', '--module', help='Print the module (script name and location in the unravel package) for each command', action='store_true', default=False) + opts.add_argument('-d', '--description', help="Print the description of each command's purpose", action='store_true', default=False) + opts.add_argument('-f', '--filter', help='Filter commands by a string (e.g, -f reg)', type=str, action=SM) + opts.add_argument('--extended-help', help='Help on diagnosing and fixing command conflicts', action='store_true', default=False) + if parser.parse_known_args()[0].extended_help: print(extended_help) import sys ; sys.exit() diff --git a/_modules/unravel/utilities/aggregate_files_from_sample_dirs.html b/_modules/unravel/utilities/aggregate_files_from_sample_dirs.html index b75fee97..449467f0 100644 --- a/_modules/unravel/utilities/aggregate_files_from_sample_dirs.html +++ b/_modules/unravel/utilities/aggregate_files_from_sample_dirs.html @@ -357,23 +357,23 @@

    Source code for unravel.utilities.aggregate_files_from_sample_dirs

    """ Use ``utils_agg_files`` from UNRAVEL to aggregate files from sample?? directories to a target directory. -Usage for when sample?? is already in the name of files being copied: ---------------------------------------------------------------------- - utils_agg_files -g 'atlas_space/<asterisk>_cfos_rb4_30um_CCF_space_z_LRavg.nii.gz' -e $DIRS -v +Usage: +------ + utils_agg_files -g 'atlas_space/<asterisk>_cfos_rb4_30um_CCF_space_z_LRavg.nii.gz' [-td target_output_dir] [-d list of paths] [-p sample??] [-v] -Usage to prepend sample?? to the name of files being copied: ------------------------------------------------------------- - utils_agg_files -g 'atlas_space/cfos_rb4_30um_CCF_space_z_LRavg.nii.gz' -e $DIRS -v -a +Usage to prepend sample folder name to the name of files being copied: +---------------------------------------------------------------------- + utils_agg_files -g 'atlas_space/cfos_rb4_30um_CCF_space_z_LRavg.nii.gz' -a [-td target_output_dir] [-d list of paths] [-p sample??] [-v] """ -import argparse import shutil from pathlib import Path from rich import print from rich.live import Live from rich.traceback import install -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, initialize_progress_bar, get_samples @@ -381,15 +381,20 @@

    Source code for unravel.utilities.aggregate_files_from_sample_dirs

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-e', '--exp_paths', help='List of experiment dir paths w/ sample?? dirs to process.', nargs='*', default=None, action=SM) - parser.add_argument('-p', '--pattern', help='Pattern for sample?? dirs. Use cwd if no matches.', default='sample??', action=SM) - parser.add_argument('-d', '--dirs', help='List of sample?? dir names or paths to dirs to process', nargs='*', default=None, action=SM) - parser.add_argument('-g', '--glob_pattern', help='Glob pattern to match files within sample?? directories', required=True, action=SM) - parser.add_argument('-td', '--target_dir', help='path/target_dir name for gathering files. Default: current working dir', default=None, action=SM) - parser.add_argument('-a', '--add_prefix', help='Add "sample??_" prefix to the output files', action='store_true') - parser.add_argument('-v', '--verbose', help='Increase verbosity.', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-g', '--glob_pattern', help='Glob pattern to match files within sample?? directories', required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-td', '--target_dir', help='path/target_dir name for gathering files. Default: current working dir', default=None, action=SM) + opts.add_argument('-a', '--add_prefix', help='Add "sample??_" prefix to the output files', action='store_true') + + general = parser.add_argument_group('General arguments') + general.add_argument('-d', '--dirs', help='Paths to sample?? dirs and/or dirs containing them (space-separated) for batch processing. Default: current dir', nargs='*', default=None, action=SM) + general.add_argument('-p', '--pattern', help='Pattern for directories to process. Default: sample??', default='sample??', action=SM) + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    @@ -436,13 +441,11 @@

    Source code for unravel.utilities.aggregate_files_from_sample_dirs

    if args.verbose: print(f'\nCopying files to: {target_dir}\n') - samples = get_samples(args.dirs, args.pattern, args.exp_paths) + sample_paths = get_samples(args.dirs, args.pattern, args.verbose) - progress, task_id = initialize_progress_bar(len(samples), "[red]Processing samples...") + progress, task_id = initialize_progress_bar(len(sample_paths), "[red]Processing samples...") with Live(progress): - for sample in samples: - - sample_path = Path(sample).resolve() if sample != Path.cwd().name else Path.cwd() + for sample_path in sample_paths: aggregate_files_from_sample_dirs(sample_path, args.glob_pattern, target_dir, args.add_prefix, args.verbose) diff --git a/_modules/unravel/utilities/aggregate_files_recursively.html b/_modules/unravel/utilities/aggregate_files_recursively.html index 461b0c53..7ac0c907 100644 --- a/_modules/unravel/utilities/aggregate_files_recursively.html +++ b/_modules/unravel/utilities/aggregate_files_recursively.html @@ -358,15 +358,15 @@

    Source code for unravel.utilities.aggregate_files_recursively

    Usage: ------ - utils_agg_files_rec -p '<asterisk>.txt' -s /path/to/source -d /path/to/destination + utils_agg_files_rec -p '<asterisk>.txt' [-s /path/to/source] [-d /path/to/destination] [--move] [-v] """ -import argparse import shutil from pathlib import Path from rich.traceback import install -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg @@ -374,13 +374,19 @@

    Source code for unravel.utilities.aggregate_files_recursively

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-p', '--pattern', help="The pattern to match files, e.g., '*.txt'", required=True, action=SM) - parser.add_argument('-s', '--source', help='The source directory to search files in. Default: current working dir', default='.', action=SM) - parser.add_argument('-d', '--destination', help='The destination directory to copy files to. Default: current working dir', default='.', action=SM) - parser.add_argument('-m', '--move', help='Move files instead of copying. Default: False', action='store_true', default=False) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-p', '--pattern', help="The pattern to match files, e.g., '*.txt'", required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-s', '--source', help='The source directory to search files in. Default: current working dir', default='.', action=SM) + opts.add_argument('-d', '--destination', help='The destination directory to copy files to. Default: current working dir', default='.', action=SM) + opts.add_argument('-m', '--move', help='Move files instead of copying. Default: False', action='store_true', default=False) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/utilities/clean_tif_dirs.html b/_modules/unravel/utilities/clean_tif_dirs.html index bf09e819..b157c90e 100644 --- a/_modules/unravel/utilities/clean_tif_dirs.html +++ b/_modules/unravel/utilities/clean_tif_dirs.html @@ -356,21 +356,23 @@

    Source code for unravel.utilities.clean_tif_dirs

    """ Use ``utils_clean_tifs`` from UNRAVEL to clean directories w/ tif series. -Run command from the experiment directory w/ sample?? folder(s), a sample?? folder, or provide -e or -d arguments. - -Usage: ------- - utils_clean_tifs -t <tif_folder_name> -m -v - Tif directory clean up involves: + - Finding .tif or .ome.tif files in the tif directory - Moving subdirectories to parent dir - Moving non-TIF files to parent dir - Replacing spaces in TIF file names -Assumes that the extension of the TIF files is .tif or .ome.tif. +Note: + - If -d is not provided, the current directory is used to search for sample?? dirs to process. + - If the current dir is a sample?? dir, it will be processed. + - If -d is provided, the specified dirs and/or dirs containing sample?? dirs will be processed. + - If -p is not provided, the default pattern for dirs to process is 'sample??'. + +Usage: +------ + utils_clean_tifs -t <list of tif dir> --move [-d list of paths] [-p sample??] [-v] """ -import argparse import shutil from glob import glob from pathlib import Path @@ -378,7 +380,8 @@

    Source code for unravel.utilities.clean_tif_dirs

    from rich.live import Live from rich.traceback import install -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, initialize_progress_bar, get_samples @@ -386,14 +389,19 @@

    Source code for unravel.utilities.clean_tif_dirs

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-e', '--exp_paths', help='List of experiment dir paths w/ sample?? dirs to process.', nargs='*', default=None, action=SM) - parser.add_argument('-p', '--pattern', help='Pattern for sample?? dirs. Use cwd if no matches.', default='sample??', action=SM) - parser.add_argument('-d', '--dirs', help='List of sample?? dir names or paths to dirs to process', nargs='*', default=None, action=SM) - parser.add_argument('-t', '--tif_dirs', help='List of tif series dirs to check.', nargs='*', required=True, action=SM) - parser.add_argument('-m', '--move', help='Enable moving of subdirs and non-TIF files to parent dir.', action='store_true', default=False) - parser.add_argument('-v', '--verbose', help='Increase verbosity.', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-t', '--tif_dirs', help='List names of folders with tif series to check (or paths relative to sample??/)', nargs='*', required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-m', '--move', help='Enable moving of subdirs and non-TIF files to parent dir.', action='store_true', default=False) + + general = parser.add_argument_group('General arguments') + general.add_argument('-d', '--dirs', help='Paths to sample?? dirs and/or dirs containing them (space-separated) for batch processing. Default: current dir', nargs='*', default=None, action=SM) + general.add_argument('-p', '--pattern', help='Pattern for directories to process. Default: sample??', default='sample??', action=SM) + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    @@ -457,15 +465,11 @@

    Source code for unravel.utilities.clean_tif_dirs

    Configuration.verbose = args.verbose verbose_start_msg() + sample_paths = get_samples(args.dirs, args.pattern, args.verbose) - samples = get_samples(args.dirs, args.pattern, args.exp_paths) - - progress, task_id = initialize_progress_bar(len(samples), "[red]Processing samples...") + progress, task_id = initialize_progress_bar(len(sample_paths), "[red]Processing samples...") with Live(progress): - for sample in samples: - - # Resolve path to sample folder - sample_path = Path(sample).resolve() if sample != Path.cwd().name else Path.cwd() + for sample_path in sample_paths: # Clean TIF directories tif_dirs = [sample_path / tif_dir for tif_dir in args.tif_dirs] diff --git a/_modules/unravel/utilities/points_compressor.html b/_modules/unravel/utilities/points_compressor.html index fdf0f779..e8f4518b 100644 --- a/_modules/unravel/utilities/points_compressor.html +++ b/_modules/unravel/utilities/points_compressor.html @@ -356,33 +356,31 @@

    Source code for unravel.utilities.points_compressor

    """ Use ``utils_points_compressor`` from UNRAVEL to pack or unpack point data in a CSV file or summarize the number of points per region. -Packing: Group points with the same coordinates and `Region_ID`, adding a `count` column. -Unpacking: Expand packed points back to individual rows based on the `count` column. -Summary: Output a CSV summarizing the number of points per region. - -Usage: ------- - utils_points_compressor -i path/<asterisk>_points.csv [-p or -u or -s] [-v] - Input: - CSV file with either unpacked (`x, y, z, Region_ID`) or packed (`x, y, z, Region_ID, count`) format. + - CSV file with either unpacked (`x, y, z, Region_ID`) or packed (`x, y, z, Region_ID, count`) format. Output: - CSV file with the desired packed or unpacked format. - Optionally, a summary CSV with the number of points per region. + - CSV file with the desired packed or unpacked format. + - Or save a summary CSV with the number of points per region. Note: + - Packing: Group points with the same coordinates and `Region_ID`, adding a `count` column. + - Unpacking: Expand packed points back to individual rows based on the `count` column. + - Summary: Output a CSV summarizing the number of points per region. - Use only one of the following options: -p, -u, -s. - The summary option can be used with either packed or unpacked data. + +Usage: +------ + utils_points_compressor -i path/<asterisk>_points.csv [-p or -u or -s] [-v] """ -import argparse import pandas as pd from pathlib import Path from rich import print from rich.traceback import install -from unravel.core.argparse_utils import SM, SuppressMetavar +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM from unravel.core.config import Configuration from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, print_func_name_args_times, process_files_with_glob @@ -390,13 +388,19 @@

    Source code for unravel.utilities.points_compressor

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input', help="Path to the input CSV file or a glob pattern.", required=True, action=SM) - parser.add_argument('-p', '--pack', help="Pack the points by grouping them.", action='store_true') - parser.add_argument('-u', '--unpack', help="Unpack the points by expanding them based on the `count` column.", action='store_true') - parser.add_argument('-s', '--summary', help='Output a CSV summarizing the number of points per region.', action='store_true') - parser.add_argument('-v', '--verbose', help='Increase verbosity.', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help="Path to the input CSV file or a glob pattern.", required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-p', '--pack', help="Pack the points by grouping them.", action='store_true') + opts.add_argument('-u', '--unpack', help="Unpack the points by expanding them based on the `count` column.", action='store_true') + opts.add_argument('-s', '--summary', help='Output a CSV summarizing the number of points per region.', action='store_true') + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/utilities/prepend_conditions.html b/_modules/unravel/utilities/prepend_conditions.html index ea11679c..11593b73 100644 --- a/_modules/unravel/utilities/prepend_conditions.html +++ b/_modules/unravel/utilities/prepend_conditions.html @@ -356,14 +356,11 @@

    Source code for unravel.utilities.prepend_conditions

    """ Use ``utils_prepend`` from UNRAVEL to prepend conditions to filenames based on a CSV key. -Usage: ------- - utils_prepend -sk <path/sample_key.csv> -f -r - -This command renames files in the current directory based on the conditions specified in the CSV file. - -The sample_key.csv should have two columns: 'dir_name' and 'condition'. -The command will prepend the 'condition' to the filenames matching the 'dir_name' prefix. +Note: + - This command renames files in the current directory based on the conditions specified in the CSV file. + - The sample_key.csv should have two columns: 'dir_name' and 'condition'. + - The command will prepend the 'condition' to the filenames matching the 'dir_name' prefix. + - If needed, files and/or folders can be renamed with ``utils_rename``. For example, if the CSV contains the following rows: dir_name,condition @@ -374,16 +371,22 @@

    Source code for unravel.utilities.prepend_conditions

    'sample01_file.csv' --> 'control_sample01_file.csv' 'sample02_file.csv' --> 'treatment_sample02_file.csv'. -If needed, files and/or folders can be renamed with ``utils_rename``. +Usage for files: +---------------- + utils_prepend -sk <path/sample_key.csv> -f [--recursive] [-v] + +Usage for directories: +---------------------- + utils_prepend -sk <path/sample_key.csv> -d [--recursive] [-v] """ -import argparse import pandas as pd from glob import glob from pathlib import Path from rich.traceback import install -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, print_func_name_args_times @@ -391,13 +394,19 @@

    Source code for unravel.utilities.prepend_conditions

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-sk', '--sample_key', help='path/sample_key.csv w/ directory names and conditions', required=True, action=SM) - parser.add_argument('-f', '--file', help='Rename matching files', action='store_true', default=False) - parser.add_argument('-d', '--dirs', help='Rename matching dirs', action='store_true', default=False) - parser.add_argument('-r', '--recursive', help='Recursively rename files/dirs', action='store_true', default=False) - parser.add_argument('-v', '--verbose', help='Increase verbosity.', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-sk', '--sample_key', help='path/sample_key.csv w/ directory names and conditions', required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-f', '--file', help='Rename matching files', action='store_true', default=False) + opts.add_argument('-d', '--dirs', help='Rename matching dirs', action='store_true', default=False) + opts.add_argument('-r', '--recursive', help='Recursively rename files/dirs', action='store_true', default=False) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/utilities/rename.html b/_modules/unravel/utilities/rename.html index ee401def..7031d3e8 100644 --- a/_modules/unravel/utilities/rename.html +++ b/_modules/unravel/utilities/rename.html @@ -356,20 +356,16 @@

    Source code for unravel.utilities.rename

     """
     Use ``utils_rename`` from UNRAVEL to recursively rename files and/or directories by replacing text in filenames.
     
    -Usage for renaming files: 
    --------------------------
    -    utils_rename -o old_text -n new_text -r -t files
    -
    -Usage for renaming directories:
    --------------------------------
    -    utils_rename -o old_text -n new_text -r -t dirs
    +Usage: 
    +------
    +    utils_rename -o old_text -n new_text [-t files or dirs or both] [--recursive] [--dry_run] [-v]
     """
     
    -import argparse
     from pathlib import Path
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
    +
     from unravel.core.config import Configuration
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg
     
    @@ -377,14 +373,20 @@ 

    Source code for unravel.utilities.rename

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-o', '--old_text', type=str, help='Text to be replaced in the filenames', action=SM) - parser.add_argument('-n', '--new_text', type=str, help='Text to replace with in the filenames', action=SM) - parser.add_argument('-t', '--type', help='Specify what to rename: "files", "dirs", or "both" (default: both)', choices=['files', 'dirs', 'both'], default='both', action=SM) - parser.add_argument('-r', '--recursive', help='Perform the renaming recursively', action='store_true', default=False) - parser.add_argument('-d', '--dry_run', help='Print old and new names without performing the renaming', action='store_true', default=False) - parser.add_argument('-v', '--verbose', help='Increase verbosity.', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-o', '--old_text', type=str, help='Text to be replaced in the filenames', action=SM) + reqs.add_argument('-n', '--new_text', type=str, help='Text to replace with in the filenames', action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-t', '--type', help='Specify what to rename: "files", "dirs", or "both" (default: both)', choices=['files', 'dirs', 'both'], default='both', action=SM) + opts.add_argument('-r', '--recursive', help='Perform the renaming recursively', action='store_true', default=False) + opts.add_argument('-d', '--dry_run', help='Print old and new names without performing the renaming', action='store_true', default=False) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/utilities/toggle_samples.html b/_modules/unravel/utilities/toggle_samples.html index 9010944b..21a7502d 100644 --- a/_modules/unravel/utilities/toggle_samples.html +++ b/_modules/unravel/utilities/toggle_samples.html @@ -354,33 +354,34 @@

    Source code for unravel.utilities.toggle_samples

    #!/usr/bin/env python3 """ -Use ``utils_toggle`` from UNRAVEL to inactivate/activate sample?? dirs (i.e., prepend/remove "_" from dir name). +Use ``utils_toggle`` from UNRAVEL to inactivate/activate sample?? dirs for batch processing (i.e., prepend/remove "_" from dir name). -Usage for toggling all sample?? dirs to active: ------------------------------------------------ - utils_toggle -t -e <list_of_exp_dir_paths> - -Usage for activating sample?? dirs for certain conditions: ----------------------------------------------------------- - utils_toggle -c <path/sample_key.csv> -a <Saline MDMA> -v -e <list_of_exp_dir_paths> - -For conditions in the activate list, the command will remove the "_" from the sample?? dir name. -For conditions not in the activate list, the command will prepend "_" to the sample?? dir name. +Note: + - For samples matching conditions in -c, "_" will be removed from the sample?? dir name. + - For sampled not matching conditions in -c, "_" will be prepended to the sample?? dir name. The sample_key.csv file should have the following format: dir_name,condition sample01,control sample02,treatment + +Usage for toggling all sample?? dirs to active: +----------------------------------------------- + utils_toggle [-d list of paths] [-p sample??] [-v] + +Usage for activating sample?? dirs for certain conditions: +---------------------------------------------------------- + utils_toggle -sk <path/sample_key.csv> -c <Saline MDMA> [-d list of paths] [-p sample??] [-v] """ -import argparse import pandas as pd from glob import glob from pathlib import Path from rich import print from rich.traceback import install -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, get_samples @@ -388,15 +389,17 @@

    Source code for unravel.utilities.toggle_samples

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-e', '--exp_paths', help='List of experiment dir paths w/ sample?? dirs to process.', nargs='*', default=None, action=SM) - parser.add_argument('-p', '--pattern', help='Pattern for sample?? dirs. Use cwd if no matches.', default='sample??', action=SM) - parser.add_argument('-d', '--dirs', help='List of sample?? dir names or paths to dirs to process', nargs='*', default=None, action=SM) - parser.add_argument('-t', '--toggle_all', help='Toggle all sample folders to active, ignoring condition checks.', action='store_true', default=False) - parser.add_argument('-sk', '--sample_key', help='path/sample_key.csv w/ directory names and conditions', default=None, action=SM) - parser.add_argument('-a', '--activate', help='Space separated list of conditions to enable processing for (must match sample_key.csv)', default=None, nargs='*', action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity.', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + opts = parser.add_argument_group('Optional arguments for activating sample?? dirs based on conditions') + opts.add_argument('-sk', '--sample_key', help='path/sample_key.csv w/ directory names and conditions (for activating sample?? dirs based on -a)', default=None, action=SM) + opts.add_argument('-c', '--conditions', help='Space separated list of conditions to activate for processing (must match sample_key.csv)', default=None, nargs='*', action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-d', '--dirs', help='Paths to sample?? dirs and/or dirs containing them (space-separated) for batch processing. Default: current dir', nargs='*', default=None, action=SM) + general.add_argument('-p', '--pattern', help='Pattern for directories to process. Default: sample??', default='sample??', action=SM) + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    @@ -410,12 +413,16 @@

    Source code for unravel.utilities.toggle_samples

    Configuration.verbose = args.verbose verbose_start_msg() - active_samples = get_samples(args.dirs, args.pattern, args.exp_paths) - inactive_samples = get_samples(args.dirs, f'_{args.pattern}', args.exp_paths) - samples = active_samples + inactive_samples + active_sample_paths = get_samples(args.dirs, args.pattern, args.verbose) + inactive_sample_paths = get_samples(args.dirs, f'_{args.pattern}', args.verbose) + + if args.verbose: + print(f'\n{active_sample_paths=}\n') + print(f'\n{inactive_sample_paths=}\n') + + sample_paths = active_sample_paths + inactive_sample_paths - for sample in samples: - sample_path = Path(sample).resolve() if sample != Path.cwd().name else Path.cwd() + for sample_path in sample_paths: stripped_sample_name = sample_path.name.lstrip('_') # Strip leading underscore for accurate CSV matching # Get the condition for the current sample @@ -423,14 +430,14 @@

    Source code for unravel.utilities.toggle_samples

    mapping_df = pd.read_csv(args.sample_key) condition_df = mapping_df[mapping_df['dir_name'] == stripped_sample_name]['condition'] - if args.toggle_all: + if args.sample_key is None: new_name = sample_path.parent / stripped_sample_name print(f'{new_name=}') status = "Activated" else: if args.sample_key is not None: condition = condition_df.values[0] - if condition in args.activate: + if condition in args.conditions: new_name = sample_path.parent / stripped_sample_name status = "Activated" else: diff --git a/_modules/unravel/voxel_stats/apply_mask.html b/_modules/unravel/voxel_stats/apply_mask.html index 5adfc667..39dbcb0d 100644 --- a/_modules/unravel/voxel_stats/apply_mask.html +++ b/_modules/unravel/voxel_stats/apply_mask.html @@ -356,22 +356,23 @@

    Source code for unravel.voxel_stats.apply_mask

    """ Use ``vstats_apply_mask`` from UNRAVEL to zeros out voxels in image based on a mask and direction args. +Usage: +------ + vstats_apply_mask -i input_image.nii.gz -mas mask.nii.gz [-dil 0] [--mean] [-tmas brain_mask.nii.gz] [-omas other_mask.nii.gz] [-di less | greater] [-o output_image.nii.gz] [-md parameters/metadata.txt] [--reg_res 50] [-mi] [-d list of paths] [-p sample??] [-v] + Usage to zero out voxels in image where mask > 0 (e.g., to exclude voxels representing artifacts): -------------------------------------------------------------------------------------------------- - vstats_apply_mask -mas 6e10_seg_ilastik_2/sample??_6e10_seg_ilastik_2.nii.gz -i 6e10_rb20 -o 6e10_rb20_wo_artifacts -di greater -v + vstats_apply_mask -mas 6e10_seg_ilastik_2/sample??_6e10_seg_ilastik_2.nii.gz -i 6e10_rb20 -o 6e10_rb20_wo_artifacts -di greater Usage to zero out voxels in image where mask < 1 (e.g., to preserve signal from segmented microglia clusters): -------------------------------------------------------------------------------------------------------------- - vstats_apply_mask -mas iba1_seg_ilastik_2/sample??_iba1_seg_ilastik_2.nii.gz -i iba1_rb20 -o iba1_rb20_clusters -v + vstats_apply_mask -mas iba1_seg_ilastik_2/sample??_iba1_seg_ilastik_2.nii.gz -i iba1_rb20 -o iba1_rb20_clusters Usage to replace voxels in image with the mean intensity in the brain where mask > 0: ------------------------------------------------------------------------------------- - vstats_apply_mask -mas FOS_seg_ilastik/FOS_seg_ilastik_2.nii.gz -i FOS -o FOS_wo_halo.zarr -di greater -m -v - -This version allows for dilatation of the full res seg_mask (slow, but precise) + vstats_apply_mask -mas FOS_seg_ilastik/FOS_seg_ilastik_2.nii.gz -i FOS -o FOS_wo_halo.zarr -di greater -m """ -import argparse import nibabel as nib import numpy as np from pathlib import Path @@ -381,7 +382,8 @@

    Source code for unravel.voxel_stats.apply_mask

    from scipy.ndimage import binary_dilation, zoom from unravel.register.reg_prep import reg_prep -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.img_io import load_3D_img, load_image_metadata_from_txt, resolve_path, save_as_tifs, save_as_nii, save_as_zarr from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, print_func_name_args_times, initialize_progress_bar, get_samples @@ -390,23 +392,30 @@

    Source code for unravel.voxel_stats.apply_mask

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-e', '--exp_paths', help='List of experiment dir paths w/ sample?? folders', nargs='*', default=None, action=SM) - parser.add_argument('-p', '--pattern', help='Pattern (sample??) for dirs to process. Else: use cwd', default='sample??', action=SM) - parser.add_argument('-d', '--dirs', help='List of sample?? dir names or paths to dirs to process', nargs='*', default=None, action=SM) - parser.add_argument('-i', '--input', help='Image input path relative to ./ or ./sample??/', required=True, action=SM) - parser.add_argument('-mas', '--seg_mask', help='rel_path/mask_to_apply.nii.gz (in full res tissue space)', required=True, action=SM) - parser.add_argument("-dil", "--dilation", help="Number of dilation iterations to perform on seg_mask. Default: 0", default=0, type=int, action=SM) - parser.add_argument('-m', '--mean', help='If provided, conditionally replace values w/ the mean intensity in the brain', action='store_true', default=False) - parser.add_argument('-tmas', '--tissue_mask', help='For the mean itensity. rel_path/brain_mask.nii.gz. Default: reg_inputs/autofl_50um_brain_mask.nii.gz', default="reg_inputs/autofl_50um_brain_mask.nii.gz", action=SM) - parser.add_argument('-omas', '--other_mask', help='For restricting application of -mas. E.g., reg_inputs/autofl_50um_brain_mask_outline.nii.gz (from ./UNRAVEL/_other/uncommon_scripts/brain_mask_outline.py)', default=None, action=SM) - parser.add_argument('-di', '--direction', help='"greater" to zero out where mask > 0, "less" (default) to zero out where mask < 1', default='less', choices=['greater', 'less'], action=SM) - parser.add_argument('-o', '--output', help='Image output path relative to ./ or ./sample??/', action=SM) - parser.add_argument('-md', '--metadata', help='path/metadata.txt. Default: ./parameters/metadata.txt', default="./parameters/metadata.txt", action=SM) - parser.add_argument('-r', '--reg_res', help='Resample input to this res in microns for ``reg``. Default: 50', default=50, type=int, action=SM) - parser.add_argument('-mi', '--miracl', help="Include reorientation step to mimic MIRACL's tif to .nii.gz conversion", action='store_true', default=False) - parser.add_argument('-v', '--verbose', help='Increase verbosity.', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='Image input path relative to ./ or ./sample??/', required=True, action=SM) + reqs.add_argument('-mas', '--seg_mask', help='rel_path/mask_to_apply.nii.gz (in full res tissue space)', required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument("-dil", "--dilation", help="Number of dilation iterations to perform on full res seg_mask (slow but precise). Default: 0", default=0, type=int, action=SM) + opts.add_argument('-m', '--mean', help='If provided, conditionally replace values w/ the mean intensity in the brain', action='store_true', default=False) + opts.add_argument('-tmas', '--tissue_mask', help='For the mean itensity. rel_path/brain_mask.nii.gz. Default: reg_inputs/autofl_50um_brain_mask.nii.gz', default="reg_inputs/autofl_50um_brain_mask.nii.gz", action=SM) + opts.add_argument('-omas', '--other_mask', help='For restricting application of -mas. E.g., reg_inputs/autofl_50um_brain_mask_outline.nii.gz (from ./UNRAVEL/_other/uncommon_scripts/brain_mask_outline.py)', default=None, action=SM) + opts.add_argument('-di', '--direction', help='"greater" to zero out where mask > 0, "less" (default) to zero out where mask < 1', default='less', choices=['greater', 'less'], action=SM) + opts.add_argument('-o', '--output', help='Image output path relative to ./ or ./sample??/', action=SM) + opts.add_argument('-md', '--metadata', help='path/metadata.txt. Default: parameters/metadata.txt', default="parameters/metadata.txt", action=SM) + opts.add_argument('-r', '--reg_res', help='Resample input to this res in microns for ``reg``. Default: 50', default=50, type=int, action=SM) + + compatability = parser.add_argument_group('Compatability options') + compatability.add_argument('-mi', '--miracl', help="Include reorientation step to mimic MIRACL's tif to .nii.gz conversion", action='store_true', default=False) + + general = parser.add_argument_group('General arguments') + general.add_argument('-d', '--dirs', help='Paths to sample?? dirs and/or dirs containing them (space-separated) for batch processing. Default: current dir', nargs='*', default=None, action=SM) + general.add_argument('-p', '--pattern', help='Pattern for directories to process. Default: sample??', default='sample??', action=SM) + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()

    @@ -492,14 +501,11 @@

    Source code for unravel.voxel_stats.apply_mask

    Configuration.verbose = args.verbose verbose_start_msg() - samples = get_samples(args.dirs, args.pattern, args.exp_paths) - - progress, task_id = initialize_progress_bar(len(samples), "[red]Processing samples...") - with Live(progress): - for sample in samples: + sample_paths = get_samples(args.dirs, args.pattern, args.verbose) - # Resolve path to sample folder - sample_path = Path(sample).resolve() if sample != Path.cwd().name else Path.cwd() + progress, task_id = initialize_progress_bar(len(sample_paths), "[red]Processing samples...") + with Live(progress): + for sample_path in sample_paths: # Define output output = resolve_path(sample_path, args.output, make_parents=True) diff --git a/_modules/unravel/voxel_stats/hemi_to_LR_avg.html b/_modules/unravel/voxel_stats/hemi_to_LR_avg.html index d7ab620f..cbf8f6ad 100644 --- a/_modules/unravel/voxel_stats/hemi_to_LR_avg.html +++ b/_modules/unravel/voxel_stats/hemi_to_LR_avg.html @@ -356,10 +356,6 @@

    Source code for unravel.voxel_stats.hemi_to_LR_avg

    """ Use ``vstats_hemi_to_avg`` from UNRAVEL to automatically average hemisphere images with their mirrored counterparts. This can also smooth the images with a kernel and apply a mask. -Usage: ------- - vstats_hemi_to_avg -k 0.1 -tp -v - Inputs: - input_img_LH.nii.gz - input_img_RH.nii.gz @@ -368,10 +364,12 @@

    Source code for unravel.voxel_stats.hemi_to_LR_avg

    - input_img_LRavg.nii.gz - input_img_s100_LRavg.nii.gz +Usage: +------ + vstats_hemi_to_avg [--kernel 0.1] [--axis 0] [--shift 2] [--parallel] [--atlas_mask path/atlas_mask.nii.gz] [-v] """ -import argparse import numpy as np import nibabel as nib from glob import glob @@ -382,7 +380,7 @@

    Source code for unravel.voxel_stats.hemi_to_LR_avg

    from fsl.wrappers import fslmaths -from unravel.core.argparse_utils import SM, SuppressMetavar +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM from unravel.core.config import Configuration from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, print_func_name_args_times from unravel.voxel_stats.apply_mask import load_mask @@ -392,14 +390,18 @@

    Source code for unravel.voxel_stats.hemi_to_LR_avg

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-k', '--kernel', help='Smoothing kernel radius in mm if > 0. Default: 0 ', default=0, type=float, action=SM) - parser.add_argument('-ax', '--axis', help='Axis to flip the image along. Default: 0', default=0, type=int, action=SM) - parser.add_argument('-s', '--shift', help='Number of voxels to shift content after flipping. Default: 2', default=2, type=int, action=SM) - parser.add_argument('-tp', '--parallel', help='Enable parallel processing with thread pools', default=False, action='store_true') - parser.add_argument('-amas', '--atlas_mask', help='path/atlas_mask.nii.gz', default=None, action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity', default=False, action='store_true') - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-k', '--kernel', help='Smoothing kernel radius in mm if > 0. Default: 0 ', default=0, type=float, action=SM) + opts.add_argument('-ax', '--axis', help='Axis to flip the image along. Default: 0', default=0, type=int, action=SM) + opts.add_argument('-s', '--shift', help='Number of voxels to shift content after flipping. Default: 2', default=2, type=int, action=SM) + opts.add_argument('-tp', '--parallel', help='Enable parallel processing with thread pools', default=False, action='store_true') + opts.add_argument('-amas', '--atlas_mask', help='path/atlas_mask.nii.gz', default=None, action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', default=False, action='store_true') + return parser.parse_args()
    diff --git a/_modules/unravel/voxel_stats/mirror.html b/_modules/unravel/voxel_stats/mirror.html index 6cde927b..828c3cfd 100644 --- a/_modules/unravel/voxel_stats/mirror.html +++ b/_modules/unravel/voxel_stats/mirror.html @@ -355,37 +355,40 @@

    Source code for unravel.voxel_stats.mirror

     
     
     """
    -Use ``vstats_mirror`` from UNRAVEL to load a <asterisk>.nii.gz, flip a copy [and shift content], average original and copy together, and save as .nii.gz.
    -
    -Usage:
    -------
    -    vstats_mirror -v
    +Use ``vstats_mirror`` from UNRAVEL to load a `*`.nii.gz, flip a copy [and shift content], average original and copy together, and save as .nii.gz.
     
     Note:
         - Use -ax 2 and -s 0 for the CCFv3 2020 atlas.
         - Use -ax 0 and -s 2 for the 25 um Gubra atlas.
    +
    +Usage:
    +------
    +    vstats_mirror [-p '<asterisk>.nii.gz'] [-ax 2] [-s 0] [-v]
     """
     
    -import argparse
     import os
     import numpy as np
     import nibabel as nib
     from pathlib import Path
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SM, SuppressMetavar
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
     from unravel.core.config import Configuration
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, print_func_name_args_times
     
     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-p', '--pattern', help='Pattern to match files. Default: *.nii.gz', default='*.nii.gz', action=SM) - parser.add_argument('-ax', '--axis', help='Axis to flip the image along. Default: 2', default=2, type=int, action=SM) - parser.add_argument('-s', '--shift', help='Number of voxels to shift content after flipping. Default: 0', default=0, type=int, action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity', default=False, action='store_true') - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-p', '--pattern', help='Pattern to match files. Default: *.nii.gz', default='*.nii.gz', action=SM) + opts.add_argument('-ax', '--axis', help='Axis to flip the image along. Default: 2', default=2, type=int, action=SM) + opts.add_argument('-s', '--shift', help='Number of voxels to shift content after flipping. Default: 0', default=0, type=int, action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', default=False, action='store_true') + return parser.parse_args()
    diff --git a/_modules/unravel/voxel_stats/other/IF_outliers.html b/_modules/unravel/voxel_stats/other/IF_outliers.html index cce9198f..64e0acdd 100644 --- a/_modules/unravel/voxel_stats/other/IF_outliers.html +++ b/_modules/unravel/voxel_stats/other/IF_outliers.html @@ -361,7 +361,6 @@

    Source code for unravel.voxel_stats.other.IF_outliers

    path/IF_outliers.py -p '<asterisk>.nii.gz' -m path/mask.nii.gz -o means_in_mask_plot.pdf -v """ -import argparse import glob import os import numpy as np @@ -369,7 +368,8 @@

    Source code for unravel.voxel_stats.other.IF_outliers

    from rich import print from rich.live import Live -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.img_io import load_3D_img from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, initialize_progress_bar @@ -378,12 +378,18 @@

    Source code for unravel.voxel_stats.other.IF_outliers

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-p', '--pattern', help='Regex pattern in quotes for matching .nii.gz images', default=None, action=SM) - parser.add_argument('-m', '--mask', help='path/mask.nii.gz', default=None, action=SM) - parser.add_argument('-o', '--output', help='path/name.[pdf/png]. Default: means_in_mask.pdf ', default='means_in_mask.pdf', action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-p', '--pattern', help='Regex pattern in quotes for matching .nii.gz images', required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-m', '--mask', help='path/mask.nii.gz', default=None, action=SM) + opts.add_argument('-o', '--output', help='path/name.[pdf/png]. Default: means_in_mask.pdf ', default='means_in_mask.pdf', action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/voxel_stats/other/r_to_p.html b/_modules/unravel/voxel_stats/other/r_to_p.html index 15951a0c..75dba8f8 100644 --- a/_modules/unravel/voxel_stats/other/r_to_p.html +++ b/_modules/unravel/voxel_stats/other/r_to_p.html @@ -356,17 +356,19 @@

    Source code for unravel.voxel_stats.other.r_to_p

    """ Converts correlation map to z-score, p value, and FDR p value maps. -Usage: ------- - path/r_to_p.py -i sample01_cfos_correlation_map.nii.gz -x 25 -z 25 -v +Input: + - <image>_correlation_map.nii.gz Outputs: - <image>_z_score_map.nii.gz - <image>_p_value_map.nii.gz - <image>_p_value_map_fdr_corrected.nii.gz + +Usage: +------ + path/r_to_p.py -i sample01_cfos_correlation_map.nii.gz -x 25 -z 25 -v """ -import argparse from pathlib import Path import numpy as np from rich import print @@ -374,7 +376,8 @@

    Source code for unravel.voxel_stats.other.r_to_p

    from scipy.stats import norm from statsmodels.stats.multitest import multipletests -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.img_io import load_3D_img, save_as_nii from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, print_func_name_args_times @@ -383,12 +386,19 @@

    Source code for unravel.voxel_stats.other.r_to_p

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-i', '--input', help='[path/]image.nii.gz', required=True, action=SM) - parser.add_argument('-x', '--xy_res', help='x/y voxel size in microns. Default: get via metadata', default=None, type=float, action=SM) - parser.add_argument('-z', '--z_res', help='z voxel size in microns. Default: get via metadata', default=None, type=float, action=SM) - parser.add_argument('-a', '--alpha', help='FDR alpha. Default: 0.05', default=0.05, type=float, action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='[path/]image.nii.gz', required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-x', '--xy_res', help='x/y voxel size in microns. Default: get via metadata', default=None, type=float, action=SM) + opts.add_argument('-z', '--z_res', help='z voxel size in microns. Default: get via metadata', default=None, type=float, action=SM) + opts.add_argument('-a', '--alpha', help='FDR alpha. Default: 0.05', default=0.05, type=float, action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/voxel_stats/vstats.html b/_modules/unravel/voxel_stats/vstats.html index 8b1c6ab0..ca121b2e 100644 --- a/_modules/unravel/voxel_stats/vstats.html +++ b/_modules/unravel/voxel_stats/vstats.html @@ -356,26 +356,35 @@

    Source code for unravel.voxel_stats.vstats

     """
     Use ``vstats`` from UNRAVEL to run voxel-wise stats using FSL's randomise_parallel command.
     
    -Usage:
    -------
    -    vstats -mas mask.nii.gz -v
    +Prereqs: 
    +    - Input images from ``vstats_prep``, ``vstats_z_score``, or ``vstats_whole_to_avg``.
     
    -Usage w/ additional options:
    -----------------------------
    -    vstats -mas mask.nii.gz -p 12000 -k 0 -op output_prefix -a atlas.nii.gz -v --options --seed=1
    +Inputs:
    +    - mask.nii.gz (e.g., stats/mask.nii.gz)
    +    - `*`.nii.gz files in the current directory with conditions as prefixes (e.g., saline_1.nii.gz, saline_2.nii.gz, drug_1.nii.gz, drug_2.nii.gz)
    +
    +Outputs:
    +    - stats/ directory with randomise_parallel outputs (e.g., uncorrected 1-p value maps [vox_p])
    +
    +Next steps:
    +    - Run ``cstats_fdr_range`` and ``cstats_fdr`` to correct for multiple comparisons.
     
     Note:
    +    - 1 minus p (1-p) value maps are made for visualization (e.g., in FSLeyes), so use 0.95 as the uncorrect threshold for alpha = 0.05.
         - The --options flag is used to pass additional options to the randomise command.
         - It should be the last flag specified in the command.
         - The options should be specified as separate strings, e.g., --options --seed=1 -T
    -    
    -Prereqs: 
    -    - Input images from ``vstats_prep``, ``vstats_z_score``, or ``vstats_whole_to_avg``.
    +    - For info on how to set up and run voxel-wise analyses, see: https://b-heifets.github.io/UNRAVEL/guide.html#voxel-wise-stats
    +    - For a t-test design, tstat1 is group1 > group2 and tstat2 is group2 > group1 (conditions are sorted alphabetically)
    +    - For an ANOVA design, fstat1 is the first contrast, fstat2 is the second contrast, and so on (these are 1-p value maps are non-directional)
     
    -Next steps:
    -    - Run ``cstats_fdr_range`` and ``cstats_fdr`` to correct for multiple comparisons.
    +Usage:
    +------
    +    vstats -mas mask.nii.gz -v
     
    -For info on how to set up and run voxel-wise analyses, see: https://b-heifets.github.io/UNRAVEL/guide.html#voxel-wise-stats
    +Usage w/ additional options:
    +----------------------------
    +    vstats -mas mask.nii.gz [-p 18000] [--kernel 0] [-op output_prefix from current dir] [-a atlas/atlas_CCFv3_2020_30um.nii.gz] [-v] [--options --seed=1]
     """
     
     import argparse
    @@ -388,7 +397,7 @@ 

    Source code for unravel.voxel_stats.vstats

     from rich import print
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SM, SuppressMetavar
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
     from unravel.core.config import Configuration
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, print_func_name_args_times
     
    @@ -396,20 +405,26 @@ 

    Source code for unravel.voxel_stats.vstats

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-mas', '--mask', help='path/mask.nii.gz', required=True, action=SM) - parser.add_argument('-p', '--permutations', help='Number of permutations (divisible by 300). Default: 18000', type=int, default=18000, action=SM) - parser.add_argument('-k', '--kernel', help='Smoothing kernel radius in mm if > 0. Default: 0 ', default=0, type=float, action=SM) - parser.add_argument('-op', '--output_prefix', help='Prefix of output files. Default: current working dir name.', action=SM) - parser.add_argument('-a', '--atlas', help='path/atlas.nii.gz (copied to stats/ for viewing; Default: atlas/atlas_CCFv3_2020_30um.nii.gz)', default='atlas/atlas_CCFv3_2020_30um.nii.gz', action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity', default=False, action='store_true') - parser.add_argument('-opt', '--options', help='Additional options for randomise, specified like "--seed=1 -T"', nargs=argparse.REMAINDER, default=[]) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-mas', '--mask', help='path/mask.nii.gz', required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-p', '--permutations', help='Number of permutations (divisible by 300). Default: 18000', type=int, default=18000, action=SM) + opts.add_argument('-k', '--kernel', help='Smoothing kernel radius in mm if > 0. Default: 0 ', default=0, type=float, action=SM) + opts.add_argument('-op', '--output_prefix', help='Prefix of output files. Default: current working dir name.', action=SM) + opts.add_argument('-a', '--atlas', help='path/atlas.nii.gz (copied to stats/ for viewing; Default: atlas/atlas_CCFv3_2020_30um.nii.gz)', default='atlas/atlas_CCFv3_2020_30um.nii.gz', action=SM) + opts.add_argument('-opt', '--options', help='Additional options for randomise, specified like "--seed=1 -T"', nargs=argparse.REMAINDER, default=[]) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', default=False, action='store_true') + return parser.parse_args()
    # TODO: Add an email option to send a message when the processing is complete. Add progress bar. See if fragments can be generated in parallel. Could make avg and avg diff maps in this script (e.g., before merge since this is fast) - +# TODO: Test nargs=argparse.REMAINDER with options
    [docs] diff --git a/_modules/unravel/voxel_stats/vstats_prep.html b/_modules/unravel/voxel_stats/vstats_prep.html index 61cd47c9..e7a057bc 100644 --- a/_modules/unravel/voxel_stats/vstats_prep.html +++ b/_modules/unravel/voxel_stats/vstats_prep.html @@ -356,24 +356,23 @@

    Source code for unravel.voxel_stats.vstats_prep

    < """ Use ``vstats_prep`` from UNRAVEL to load an immunofluo image, subtract its background, and warp it to atlas space. -Usage: ------- - vstats_prep -i <asterisk>.czi -rb 4 -o cfos_rb4_30um_CCF_space.nii.gz -e [$DIRS] [-v] - Prereqs: - ``reg`` + - ``reg`` Input examples (path is relative to ./sample??; 1st glob match processed): - <asterisk>.czi, ochann/<asterisk>.tif, ochann, <asterisk>.tif, <asterisk>.h5, or <asterisk>.zarr + - `*`.czi, ochann/`*`.tif, ochann, `*`.tif, `*`.h5, or `*`.zarr -Example output: - ./sample??/atlas_space/sample??_cfos_rb4_30um_CCF_space.nii.gz +Output example: + - ./sample??/atlas_space/sample??_cfos_rb4_30um_CCF_space.nii.gz Next steps: Aggregate outputs with ``utils_agg_files`` and run ``vstats``. + +Usage: +------ + vstats_prep -i `*`.czi -o cfos_rb4_30um_CCF_space.nii.gz [-sa 3] [-rb 4] [--chann_idx 1] [--reg_res 50] [-fri reg_outputs/autofl_50um_masked_fixed_reg_input.nii.gz] [-a atlas/atlas_CCFv3_2020_30um.nii.gz] [-dt uint16] [-zo 1] [-inp bSpline] [-md parameters/metadata.txt] [--threads 8] [-mi] [-d list of paths] [-p sample??] [-v] """ -import argparse import shutil from pathlib import Path from rich import print @@ -381,7 +380,8 @@

    Source code for unravel.voxel_stats.vstats_prep

    < from rich.traceback import install from unravel.image_tools.spatial_averaging import apply_2D_mean_filter, spatial_average_2D, spatial_average_3D -from unravel.core.argparse_utils import SuppressMetavar, SM +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM + from unravel.core.config import Configuration from unravel.core.img_io import load_3D_img, load_image_metadata_from_txt from unravel.core.img_tools import rolling_ball_subtraction_opencv_parallel @@ -393,30 +393,33 @@

    Source code for unravel.voxel_stats.vstats_prep

    <
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-e', '--exp_paths', help='List of experiment dir paths w/ sample?? dirs to process.', nargs='*', default=None, action=SM) - parser.add_argument('-p', '--pattern', help='Pattern for sample?? dirs. Use cwd if no matches.', default='sample??', action=SM) - parser.add_argument('-d', '--dirs', help='List of sample?? dir names or paths to dirs to process', nargs='*', default=None, action=SM) - - # Required arguments: - parser.add_argument('-i', '--input', help='path to full res image', required=True, action=SM) - parser.add_argument('-o', '--output', help='Output file name w/o "sample??_" (added automatically). E.g., cfos_rb4_30um_CCF_space.nii.gz', required=True, action=SM) - - # Optional arguments: - parser.add_argument('-sa', '--spatial_avg', help='Spatial averaging in 2D or 3D (2 or 3). Default: None', default=None, type=int, action=SM) - parser.add_argument('-rb', '--rb_radius', help='Radius of rolling ball in pixels (Default: None)', default=None, type=int, action=SM) - parser.add_argument('-c', '--chann_idx', help='.czi channel index. Default: 1', default=1, type=int, action=SM) - parser.add_argument('-r', '--reg_res', help='Resolution of registration inputs in microns. Default: 50', default='50',type=int, action=SM) - parser.add_argument('-fri', '--fixed_reg_in', help='Reference nii header from ``reg``. Default: reg_outputs/autofl_50um_masked_fixed_reg_input.nii.gz', default="reg_outputs/autofl_50um_masked_fixed_reg_input.nii.gz", action=SM) - parser.add_argument('-a', '--atlas', help='path/atlas.nii.gz (Default: atlas/atlas_CCFv3_2020_30um.nii.gz)', default='atlas/atlas_CCFv3_2020_30um.nii.gz', action=SM) - parser.add_argument('-dt', '--dtype', help='Desired dtype for output (e.g., uint8, uint16). Default: uint16', default="uint16", action=SM) - parser.add_argument('-zo', '--zoom_order', help='SciPy zoom order for resampling the raw image. Default: 1', default=1, type=int, action=SM) - parser.add_argument('-inp', '--interpol', help='Type of interpolation (linear, bSpline [default]).', default='bSpline', action=SM) - parser.add_argument('-mi', '--miracl', help='Mode for compatibility (accounts for tif to nii reorienting)', action='store_true', default=False) - parser.add_argument('-md', '--metadata', help='path/metadata.txt. Default: parameters/metadata.txt', default="parameters/metadata.txt", action=SM) - parser.add_argument('-th', '--threads', help='Number of threads for rolling ball subtraction. Default: 8', default=8, type=int, action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity.', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='path to full res image', required=True, action=SM) + reqs.add_argument('-o', '--output', help='Output file name w/o "sample??_" (added automatically). E.g., cfos_rb4_30um_CCF_space.nii.gz', required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-sa', '--spatial_avg', help='Spatial averaging in 2D or 3D (2 or 3). Default: None', default=None, type=int, action=SM) + opts.add_argument('-rb', '--rb_radius', help='Radius of rolling ball in pixels (Default: None)', default=None, type=int, action=SM) + opts.add_argument('-c', '--chann_idx', help='.czi channel index. Default: 1', default=1, type=int, action=SM) + opts.add_argument('-r', '--reg_res', help='Resolution of registration inputs in microns. Default: 50', default='50',type=int, action=SM) + opts.add_argument('-fri', '--fixed_reg_in', help='Reference nii header from ``reg``. Default: reg_outputs/autofl_50um_masked_fixed_reg_input.nii.gz', default="reg_outputs/autofl_50um_masked_fixed_reg_input.nii.gz", action=SM) + opts.add_argument('-a', '--atlas', help='path/atlas.nii.gz (Default: atlas/atlas_CCFv3_2020_30um.nii.gz)', default='atlas/atlas_CCFv3_2020_30um.nii.gz', action=SM) + opts.add_argument('-dt', '--dtype', help='Desired dtype for output (e.g., uint8, uint16). Default: uint16', default="uint16", action=SM) + opts.add_argument('-zo', '--zoom_order', help='SciPy zoom order for resampling the raw image. Default: 1', default=1, type=int, action=SM) + opts.add_argument('-inp', '--interpol', help='Type of interpolation (linear, bSpline [default]).', default='bSpline', action=SM) + opts.add_argument('-md', '--metadata', help='path/metadata.txt. Default: parameters/metadata.txt', default="parameters/metadata.txt", action=SM) + opts.add_argument('-th', '--threads', help='Number of threads for rolling ball subtraction. Default: 8', default=8, type=int, action=SM) + + compatability = parser.add_argument_group('Compatability options') + compatability.add_argument('-mi', '--miracl', help='Mode for compatibility (accounts for tif to nii reorienting)', action='store_true', default=False) + + general = parser.add_argument_group('General arguments') + general.add_argument('-d', '--dirs', help='Paths to sample?? dirs and/or dirs containing them (space-separated) for batch processing. Default: current dir', nargs='*', default=None, action=SM) + general.add_argument('-p', '--pattern', help='Pattern for directories to process. Default: sample??', default='sample??', action=SM) + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    @@ -429,13 +432,11 @@

    Source code for unravel.voxel_stats.vstats_prep

    < Configuration.verbose = args.verbose verbose_start_msg() - samples = get_samples(args.dirs, args.pattern, args.exp_paths) + sample_paths = get_samples(args.dirs, args.pattern, args.verbose) - progress, task_id = initialize_progress_bar(len(samples), "[red]Processing samples...") + progress, task_id = initialize_progress_bar(len(sample_paths), "[red]Processing samples...") with Live(progress): - for sample in samples: - - sample_path = Path(sample).resolve() if sample != Path.cwd().name else Path.cwd() + for sample_path in sample_paths: output_name = f"{sample_path.name}_{Path(args.output).name}" output = sample_path / "atlas_space" / output_name diff --git a/_modules/unravel/voxel_stats/whole_to_LR_avg.html b/_modules/unravel/voxel_stats/whole_to_LR_avg.html index 385e4dca..fbfb33c8 100644 --- a/_modules/unravel/voxel_stats/whole_to_LR_avg.html +++ b/_modules/unravel/voxel_stats/whole_to_LR_avg.html @@ -356,22 +356,24 @@

    Source code for unravel.voxel_stats.whole_to_LR_avg

    """ Use ``vstats_whole_to_avg`` from UNRAVEL to average an image with its mirrored version for voxel-wise stats. This can also smooth the image with a kernel and apply a mask. -Usage: ------- - vstats_whole_to_avg -k 0.1 -v -tp - -Output: - input_img_LRavg.nii.gz - Prereqs: - Input images from ``vstats_prep``. - These may be z-scored with ``vstats_z_score``. +Inputs: + - `*`.nii.gz images in the current directory. + +Output: + - input_img_LRavg.nii.gz for each input image. + Next steps: - Run ``vstats`` to perform voxel-wise stats. + +Usage: +------ + vstats_whole_to_avg [--pattern '<asterisk>.nii.gz'] [--kernel 0] [--axis 2] [--shift 2] [--parallel] [--atlas_mask path/atlas_mask.nii.gz] [-v] """ -import argparse import numpy as np import nibabel as nib from glob import glob @@ -381,7 +383,7 @@

    Source code for unravel.voxel_stats.whole_to_LR_avg

    from rich.traceback import install from concurrent.futures import ThreadPoolExecutor -from unravel.core.argparse_utils import SM, SuppressMetavar +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM from unravel.core.config import Configuration from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, print_func_name_args_times from unravel.voxel_stats.apply_mask import load_mask @@ -391,15 +393,19 @@

    Source code for unravel.voxel_stats.whole_to_LR_avg

    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-p', '--pattern', help='Pattern to match atlas space input images in the working dir. Default: *.nii.gz', default='*.nii.gz', action=SM) - parser.add_argument('-k', '--kernel', help='Smoothing kernel radius in mm if > 0. Default: 0', default=0, type=float, action=SM) - parser.add_argument('-ax', '--axis', help='Axis to flip the image along. Default: 2', default=2, type=int, action=SM) - parser.add_argument('-s', '--shift', help='Number of voxels to shift content after flipping (if atlas is asym.). Default: 0', default=0, type=int, action=SM) - parser.add_argument('-tp', '--parallel', help='Enable parallel processing with thread pools', default=False, action='store_true') - parser.add_argument('-amas', '--atlas_mask', help='path/atlas_mask.nii.gz', default=None, action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity', default=False, action='store_true') - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-p', '--pattern', help='Pattern to match atlas space input images in the working dir. Default: *.nii.gz', default='*.nii.gz', action=SM) + opts.add_argument('-k', '--kernel', help='Smoothing kernel radius in mm if > 0. Default: 0', default=0, type=float, action=SM) + opts.add_argument('-ax', '--axis', help='Axis to flip the image along. Default: 2', default=2, type=int, action=SM) + opts.add_argument('-s', '--shift', help='Number of voxels to shift content after flipping (if atlas is asym.). Default: 0', default=0, type=int, action=SM) + opts.add_argument('-tp', '--parallel', help='Enable parallel processing with thread pools', default=False, action='store_true') + opts.add_argument('-amas', '--atlas_mask', help='path/atlas_space_mask.nii.gz', default=None, action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', default=False, action='store_true') + return parser.parse_args()
    diff --git a/_modules/unravel/voxel_stats/z_score.html b/_modules/unravel/voxel_stats/z_score.html index b3a9a6d2..f702454a 100644 --- a/_modules/unravel/voxel_stats/z_score.html +++ b/_modules/unravel/voxel_stats/z_score.html @@ -356,17 +356,20 @@

    Source code for unravel.voxel_stats.z_score

     """
     Use ``vstats_z_score`` from UNRAVEL to z-score an atlas space image using a tissue mask and/or an atlas mask.
     
    -Usage w/ a tissue mask (warped to atlas space):
    ------------------------------------------------
    -    vstats_z_score -i atlas_space/sample??_cfos_rb4_atlas_space.nii.gz -v
    +Prereqs:
    +    ``vstats_prep`` for inputs [& ``seg_brain_mask`` for tissue masks]
     
    -Usage w/ an atlas mask (warped to atlas space):
    ------------------------------------------------
    -    vstats_z_score -i path/img.nii.gz -n -amas path/atlas_mask.nii.gz -v
    +Inputs:
    +    - path/img.nii.gz (e.g., an immunofluo image in atlas space)
    +    - [reg_inputs/autofl_50um_brain_mask.nii.gz] for a tissue mask
    +    - [path/atlas_mask.nii.gz] for an atlas mask
     
    -Usage w/ both masks for side-specific z-scoring:
    -------------------------------------------------
    -    vstats_z_score -i atlas_space/sample??_cfos_rb4_atlas_space.nii.gz -amas path/RH_mask.nii.gz -s RHz -v
    +Outputs:
    +    - <path/input_img>_z.nii.gz (float32)
    +    - [sample??/atlas_space/autofl_50um_brain_mask.nii.gz]
    +
    +Note:
    +    - z-score = (img.nii.gz - mean pixel intensity in brain)/standard deviation of intensity in brain
     
     Next steps: 
         - Aggregate outputs with ``utils_agg_files``.
    @@ -374,18 +377,23 @@ 

    Source code for unravel.voxel_stats.z_score

         - If using side-specific z-scoring, next use ``vstats_hemi_to_avg`` to average the images.
         - Run ``vstats`` to perform voxel-wise stats.
     
    -Outputs:
    -    - <path/input_img>_z.nii.gz (float32)
    -    - [sample??/atlas_space/autofl_50um_brain_mask.nii.gz]
    +Usage:
    +------
    +    vstats_z_score -i path/img.nii.gz [--suffix z] [-tmas reg_inputs/autofl_50um_brain_mask.nii.gz] [-amas path/atlas_mask.nii.gz] [--no_tmask] [-fri reg_outputs/autofl_50um_masked_fixed_reg_input.nii.gz] [-a atlas/atlas_CCFv3_2020_30um.nii.gz] [-d list of paths] [-p sample??] [-v]
     
    -z-score = (img.nii.gz - mean pixel intensity in brain)/standard deviation of intensity in brain
    +Usage w/ a tissue mask (warped to atlas space):
    +-----------------------------------------------
    +    vstats_z_score -i atlas_space/sample??_cfos_rb4_atlas_space.nii.gz -v
     
    -Prereqs:
    -    ``vstats_prep`` for inputs [& ``seg_brain_mask`` for tissue masks]
    +Usage w/ an atlas mask (warped to atlas space):
    +-----------------------------------------------
    +    vstats_z_score -i path/img.nii.gz --no_tmask -amas path/atlas_mask.nii.gz -v
    +
    +Usage w/ both masks for side-specific z-scoring:
    +------------------------------------------------
    +    vstats_z_score -i atlas_space/sample??_cfos_rb4_atlas_space.nii.gz -amas path/RH_mask.nii.gz -s RH_z -v
     """
     
    -import argparse
    -import shutil
     import nibabel as nib
     import numpy as np
     from pathlib import Path
    @@ -393,7 +401,7 @@ 

    Source code for unravel.voxel_stats.z_score

     from rich.live import Live
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SM, SuppressMetavar
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
     from unravel.core.config import Configuration
     from unravel.core.img_io import load_3D_img
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, get_samples, initialize_progress_bar, print_func_name_args_times
    @@ -403,24 +411,29 @@ 

    Source code for unravel.voxel_stats.z_score

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-e', '--exp_paths', help='List of experiment dir paths w/ sample?? dirs to process.', nargs='*', default=None, action=SM) - parser.add_argument('-p', '--pattern', help='Pattern for sample?? dirs. Use cwd if no matches.', default='sample??', action=SM) - parser.add_argument('-d', '--dirs', help='List of sample?? dir names or paths to dirs to process', nargs='*', default=None, action=SM) - parser.add_argument('-i', '--input', help='full_path/img.nii.gz or rel_path/img.nii.gz ("sample??" works for batch processing)', required=True, action=SM) - parser.add_argument('-s', '--suffix', help='Output suffix. Default: z (.nii.gz replaced w/ _z.nii.gz)', default='z', action=SM) - parser.add_argument('-tmas', '--tissue_mask', help='rel_path/brain_mask.nii.gz. Default: reg_inputs/autofl_50um_brain_mask.nii.gz', default="reg_inputs/autofl_50um_brain_mask.nii.gz", action=SM) - parser.add_argument('-amas', '--atlas_mask', help='path/atlas_mask.nii.gz (can use tmas and/or amas)', default=None, action=SM) - parser.add_argument('-n', '--no_tmask', help='Provide flag to avoid use of tmas', action='store_true') - parser.add_argument('-fri', '--fixed_reg_in', help='Reference nii header from ``reg``. Default: reg_outputs/autofl_50um_masked_fixed_reg_input.nii.gz', default="reg_outputs/autofl_50um_masked_fixed_reg_input.nii.gz", action=SM) - parser.add_argument('-a', '--atlas', help='path/atlas.nii.gz. It is used as a fixed image for warping a brain mask to atlas space (Default: atlas/atlas_CCFv3_2020_30um.nii.gz)', default='atlas/atlas_CCFv3_2020_30um.nii.gz', action=SM) - parser.add_argument('-inp', '--interpol', help='Type of interpolation (nearestNeighbor, multiLabel [default]).', default='multiLabel', action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity', default=False, action='store_true') - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='full_path/img.nii.gz or rel_path/img.nii.gz ("sample??" works for batch processing)', required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-s', '--suffix', help='Output suffix. Default: z (.nii.gz replaced w/ _z.nii.gz)', default='z', action=SM) + opts.add_argument('-tmas', '--tissue_mask', help='rel_path/brain_mask.nii.gz. Default: reg_inputs/autofl_50um_brain_mask.nii.gz', default="reg_inputs/autofl_50um_brain_mask.nii.gz", action=SM) + opts.add_argument('-amas', '--atlas_mask', help='path/atlas_mask.nii.gz (can use tmas and/or amas)', default=None, action=SM) + opts.add_argument('-n', '--no_tmask', help='Provide flag to avoid use of tmas', action='store_true') + opts.add_argument('-fri', '--fixed_reg_in', help='Reference nii header from ``reg``. Default: reg_outputs/autofl_50um_masked_fixed_reg_input.nii.gz', default="reg_outputs/autofl_50um_masked_fixed_reg_input.nii.gz", action=SM) + opts.add_argument('-a', '--atlas', help='path/atlas.nii.gz. It is used as a fixed image for warping a brain mask to atlas space (Default: atlas/atlas_CCFv3_2020_30um.nii.gz)', default='atlas/atlas_CCFv3_2020_30um.nii.gz', action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-d', '--dirs', help='Paths to sample?? dirs and/or dirs containing them (space-separated) for batch processing. Default: current dir', nargs='*', default=None, action=SM) + general.add_argument('-p', '--pattern', help='Pattern for directories to process. Default: sample??', default='sample??', action=SM) + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', default=False, action='store_true') + return parser.parse_args()
    # TODO: Set voxels outside the mask(s) to zero +# TODO: Consider adjusting logic so --no_tmask is not required
    @@ -461,13 +474,11 @@

    Source code for unravel.voxel_stats.z_score

         if args.no_tmask and args.atlas_mask is None: 
             print("\n    [red]Please provide a path for --atlas_mask if --tissue_mask is not used\n")
     
    -    samples = get_samples(args.dirs, args.pattern, args.exp_paths)
    +    sample_paths = get_samples(args.dirs, args.pattern, args.verbose)
     
    -    progress, task_id = initialize_progress_bar(len(samples), "[red]Processing samples...")
    +    progress, task_id = initialize_progress_bar(len(sample_paths), "[red]Processing samples...")
         with Live(progress):
    -        for sample in samples:
    -            
    -            sample_path = Path(sample).resolve() if sample != Path.cwd().name else Path.cwd()
    +        for sample_path in sample_paths:
     
                 if Path(args.input).is_absolute():
                     input_path = Path(args.input)
    @@ -498,7 +509,7 @@ 

    Source code for unravel.voxel_stats.z_score

                     if not fixed_reg_input.exists():
                         fixed_reg_input = sample_path / "reg_outputs" / "autofl_50um_fixed_reg_input.nii.gz"
     
    -                to_atlas(sample_path, brain_mask_in_tissue_space, fixed_reg_input, args.atlas, mask_output, args.interpol, dtype='float32')
    +                to_atlas(sample_path, brain_mask_in_tissue_space, fixed_reg_input, args.atlas, mask_output, 'multiLabel', dtype='float32')  # or 'nearestNeighbor'
                     mask = load_3D_img(mask_output)
                     mask = np.where(mask > 0, 1, 0).astype(np.uint8)
     
    diff --git a/_modules/unravel/warp/points_to_atlas.html b/_modules/unravel/warp/points_to_atlas.html
    index ab08f78d..dcd22b24 100644
    --- a/_modules/unravel/warp/points_to_atlas.html
    +++ b/_modules/unravel/warp/points_to_atlas.html
    @@ -356,22 +356,27 @@ 

    Source code for unravel.warp.points_to_atlas

    """
     Use ``warp_points_to_atlas`` from UNRAVEL to convert cell centroids in native space to an image matching the fixed registration input and then warp it to atlas space.
     
    -Usage:
    -------
    -    warp_points_to_atlas -i regional_stats/<asterisk>_sample??_cell_centroids.csv [-a atlas/atlas_CCFv3_2020_30um.nii.gz] [-r 50] [-af reg_inputs/autofl_50um.nii.gz] [-fri reg_outputs/autofl_50um_masked_fixed_reg_input.nii.gz] [-inp nearestNeighbor] [-thr 20000] [-uthr 20000] [-md parameters/metadata.txt] [-mi -v]
     
     Prereqs: 
         ``reg`` and ``rstats``
     
    +Inputs:
    +    - regional_stats/<Condition>_sample??_cell_centroids.csv (w/ columns: x, y, z, Region_ID) from ``rstats`` (first glob match processed)
    +    - Reference image for target shape for converting points to image before padding and warping: reg_inputs/autofl_50um.nii.gz from ``reg_prep``
    +    - Reference image for warping to atlas space: e.g., atlas/atlas_CCFv3_2020_30um.nii.gz
    +
     Outputs:
         - ./sample??/atlas_space/<args.input name>
         - ./sample??/atlas_space/<args.input name --> .nii.gz>
     
     Notes:
         - If the input CSV has a 'count' column, use ``utils_points_compressor`` to unpack the points before running this script.
    +
    +Usage:
    +------
    +    warp_points_to_atlas -i regional_stats/<asterisk>_sample??_cell_centroids.csv [-a atlas/atlas_CCFv3_2020_30um.nii.gz] [-fri reg_outputs/autofl_50um_masked_fixed_reg_input.nii.gz] [-af reg_inputs/autofl_50um.nii.gz] [-thr 20000 or -uthr 20000] [-md parameters/metadata.txt] [-mi] [-d list of paths] [-p sample??] [-v]
     """
     
    -import argparse
     import nibabel as nib
     import numpy as np
     import pandas as pd
    @@ -380,7 +385,7 @@ 

    Source code for unravel.warp.points_to_atlas

    from rich.live import Live
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SM, SuppressMetavar
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
     from unravel.core.config import Configuration
     from unravel.core.img_io import load_image_metadata_from_txt, nii_to_ndarray, nii_voxel_size
     from unravel.core.img_tools import reorient_for_raw_to_nii_conv, reverse_reorient_for_raw_to_nii_conv
    @@ -393,26 +398,27 @@ 

    Source code for unravel.warp.points_to_atlas

     [docs]
     def parse_args():
    -    parser = argparse.ArgumentParser(formatter_class=SuppressMetavar)
    -    # Arguments for batch processing sample directories:
    -    parser.add_argument('-e', '--exp_paths', help='List of experiment dir paths w/ sample?? dirs to process.', nargs='*', default=None, action=SM)
    -    parser.add_argument('-p', '--pattern', help='Pattern for sample?? dirs. Use cwd if no matches.', default='sample??', action=SM)
    -    parser.add_argument('-d', '--dirs', help='List of sample?? dir names or paths to dirs to process', nargs='*', default=None, action=SM)
    -
    -    # Required arguments:
    -    parser.add_argument('-i', '--input', help='regional_stats/<Condition>_sample??_cell_centroids.csv (w/ columns: x, y, z, Region_ID) from ``rstats`` (first glob match processed)', required=True, action=SM)
    -
    -    # Optional arguments:
    -    parser.add_argument('-a', '--atlas', help='path/atlas.nii.gz or template matching moving image (Default: atlas/atlas_CCFv3_2020_30um.nii.gz)', default='atlas/atlas_CCFv3_2020_30um.nii.gz', action=SM)
    -    parser.add_argument('-fri', '--fixed_reg_in', help='Reference nii header from ``reg``. Default: reg_outputs/autofl_50um_masked_fixed_reg_input.nii.gz', default="reg_outputs/autofl_50um_masked_fixed_reg_input.nii.gz", action=SM)
    -    parser.add_argument('-inp', '--interpol', help='Type of interpolation (e.g., nearestNeighbor [default] or linear).', default='nearestNeighbor', action=SM)
    -    parser.add_argument('-af', '--autofl_img', help='reg_inputs/autofl_50um.nii.gz from ``reg_prep`` (reference for `resample_and_convert_points()`)', default="reg_inputs/autofl_50um.nii.gz", action=SM)
    -    parser.add_argument('-thr', '--thresh', help='Exclude region IDs below this threshold (e.g., 20000 to obtain left hemisphere data)', type=float, action=SM)
    -    parser.add_argument('-uthr', '--upper_thr', help='Exclude region IDs above this threshold (e.g., 20000 to obtain right hemisphere data)', type=float, action=SM)
    -    parser.add_argument('-md', '--metadata', help='path/metadata.txt. Default: parameters/metadata.txt', default="parameters/metadata.txt", action=SM)
    -    parser.add_argument('-mi', '--miracl', help='Mode for compatibility (accounts for tif to nii reorienting)', action='store_true', default=False)
    -    parser.add_argument('-v', '--verbose', help='Increase verbosity.', action='store_true', default=False)
    -    parser.epilog = __doc__
    +    parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__)
    +
    +    reqs = parser.add_argument_group('Required arguments')
    +    reqs.add_argument('-i', '--input', help='regional_stats/<Condition>_sample??_cell_centroids.csv (w/ columns: x, y, z, Region_ID) from ``rstats`` (first glob match processed)', required=True, action=SM)
    +
    +    opts = parser.add_argument_group('Optional arguments')
    +    opts.add_argument('-a', '--atlas', help='path/atlas.nii.gz or template matching moving image (Default: atlas/atlas_CCFv3_2020_30um.nii.gz)', default='atlas/atlas_CCFv3_2020_30um.nii.gz', action=SM)
    +    opts.add_argument('-fri', '--fixed_reg_in', help='Reference nii header from ``reg``. Default: reg_outputs/autofl_50um_masked_fixed_reg_input.nii.gz', default="reg_outputs/autofl_50um_masked_fixed_reg_input.nii.gz", action=SM)
    +    opts.add_argument('-af', '--autofl_img', help='reg_inputs/autofl_50um.nii.gz from ``reg_prep`` (reference for `resample_and_convert_points()`)', default="reg_inputs/autofl_50um.nii.gz", action=SM)
    +    opts.add_argument('-thr', '--thresh', help='Exclude region IDs below this threshold (e.g., 20000 to obtain left hemisphere data)', type=float, action=SM)
    +    opts.add_argument('-uthr', '--upper_thr', help='Exclude region IDs above this threshold (e.g., 20000 to obtain right hemisphere data)', type=float, action=SM)
    +    opts.add_argument('-md', '--metadata', help='path/metadata.txt. Default: parameters/metadata.txt', default="parameters/metadata.txt", action=SM)
    +    
    +    compatability = parser.add_argument_group('Compatability options')
    +    compatability.add_argument('-mi', '--miracl', help='Mode for compatibility (accounts for tif to nii reorienting)', action='store_true', default=False)
    +
    +    general = parser.add_argument_group('General arguments')
    +    general.add_argument('-d', '--dirs', help='Paths to sample?? dirs and/or dirs containing them (space-separated) for batch processing. Default: current dir', nargs='*', default=None, action=SM)
    +    general.add_argument('-p', '--pattern', help='Pattern for directories to process. Default: sample??', default='sample??', action=SM)
    +    general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False)
    +
         return parser.parse_args()
    @@ -426,13 +432,11 @@

    Source code for unravel.warp.points_to_atlas

    Configuration.verbose = args.verbose
         verbose_start_msg()
     
    -    samples = get_samples(args.dirs, args.pattern, args.exp_paths)
    +    sample_paths = get_samples(args.dirs, args.pattern, args.verbose)
     
    -    progress, task_id = initialize_progress_bar(len(samples), "[red]Processing samples...")
    +    progress, task_id = initialize_progress_bar(len(sample_paths), "[red]Processing samples...")
         with Live(progress):
    -        for sample in samples:
    -            
    -            sample_path = Path(sample).resolve() if sample != Path.cwd().name else Path.cwd()
    +        for sample_path in sample_paths:
     
                 # Load resolutions from metadata
                 metadata_path = sample_path / args.metadata
    @@ -483,7 +487,7 @@ 

    Source code for unravel.warp.points_to_atlas

    if np.max(points_resampled_img) > 0:
                     dtype = 'uint16' if np.max(points_resampled_img) > 255 else 'uint8'
             
    -            to_atlas(sample_path, points_resampled_img, args.fixed_reg_in, args.atlas, output_img_path, args.interpol, dtype=dtype)
    +            to_atlas(sample_path, points_resampled_img, args.fixed_reg_in, args.atlas, output_img_path, 'nearestNeighbor', dtype=dtype)
     
                 progress.update(task_id, advance=1)
     
    diff --git a/_modules/unravel/warp/to_atlas.html b/_modules/unravel/warp/to_atlas.html
    index cd2f79c4..0b8ba4b3 100644
    --- a/_modules/unravel/warp/to_atlas.html
    +++ b/_modules/unravel/warp/to_atlas.html
    @@ -356,18 +356,17 @@ 

    Source code for unravel.warp.to_atlas

     """
     Use ``warp_to_atlas`` from UNRAVEL to warp a native image to atlas space.
     
    -Usage:
    -------
    -    warp_to_atlas -i cfos -o img_in_atlas_space.nii.gz -x 3.5232 -z 6 [-mi -v] 
    -
     Prereqs: 
         ``reg``
     
     Input examples (path is relative to ./sample??; 1st glob match processed): 
    -    <asterisk>.czi, cfos/<asterisk>.tif, cfos, <asterisk>.tif, <asterisk>.h5, or <asterisk>.zarr 
    +    `*`.czi, cfos/`*`.tif, cfos, `*`.tif, `*`.h5, or `*`.zarr 
    +
    +Usage:
    +------
    +    warp_to_atlas -i cfos -o img_in_atlas_space.nii.gz [--channel 1] [-md path/metadata.txt] [-a atlas/atlas_CCFv3_2020_30um.nii.gz] [-dt uint16] [-fri reg_outputs/autofl_50um_masked_fixed_reg_input.nii.gz] [--reg_res 50] [-inp bSpline] [-zo 1] [-mi] [-d list of paths] [-p sample??] [-v]
     """
     
    -import argparse
     import nibabel as nib
     import numpy as np
     from pathlib import Path
    @@ -376,9 +375,9 @@ 

    Source code for unravel.warp.to_atlas

     from rich.traceback import install
     
     from unravel.image_io.io_nii import convert_dtype
    -from unravel.core.argparse_utils import SM, SuppressMetavar
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
     from unravel.core.config import Configuration
    -from unravel.core.img_io import load_3D_img
    +from unravel.core.img_io import load_3D_img, load_image_metadata_from_txt
     from unravel.core.img_tools import pad
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, print_func_name_args_times, initialize_progress_bar, get_samples
     from unravel.register.reg_prep import reg_prep
    @@ -388,28 +387,30 @@ 

    Source code for unravel.warp.to_atlas

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-e', '--exp_paths', help='List of experiment dir paths w/ sample?? dirs to process.', nargs='*', default=None, action=SM) - parser.add_argument('-p', '--pattern', help='Pattern for sample?? dirs. Use cwd if no matches.', default='sample??', action=SM) - parser.add_argument('-d', '--dirs', help='List of sample?? dir names or paths to dirs to process', nargs='*', default=None, action=SM) - - # Required arguments: - parser.add_argument('-i', '--input', help='INPUT: Path of native image relative to ./sample??', required=True, action=SM) - parser.add_argument('-o', '--output', help='Output filename. E.g., img_in_atlas_space.nii.gz. Saved in ./sample??/atlas_space/', required=True, action=SM) - - # Optional arguments: - parser.add_argument('-c', '--chann_idx', help='.czi channel index. Default: 1', default=1, type=int, action=SM) - parser.add_argument('-x', '--xy_res', help='Native x/y voxel size in microns (Default: get via metadata)', default=None, type=float, action=SM) - parser.add_argument('-z', '--z_res', help='Native z voxel size in microns (Default: get via metadata)', default=None, type=float, action=SM) - parser.add_argument('-a', '--atlas', help='path/atlas.nii.gz for use as the fixed image (Default: atlas/atlas_CCFv3_2020_30um.nii.gz)', default='atlas/atlas_CCFv3_2020_30um.nii.gz', action=SM) - parser.add_argument('-dt', '--dtype', help='Desired dtype for output (e.g., uint8, uint16). Default: uint16', default="uint16", action=SM) - parser.add_argument('-fri', '--fixed_reg_in', help='Reference nii header from ``reg``. Default: reg_outputs/autofl_50um_masked_fixed_reg_input.nii.gz', default="reg_outputs/autofl_50um_masked_fixed_reg_input.nii.gz", action=SM) - parser.add_argument('-r', '--reg_res', help='Resolution of registration inputs in microns. Default: 50', default='50',type=int, action=SM) - parser.add_argument('-inp', '--interpol', help='Type of interpolation (linear, bSpline [default]).', default='bSpline', action=SM) - parser.add_argument('-zo', '--zoom_order', help='SciPy zoom order for resampling the raw image. Default: 1', default=1, type=int, action=SM) - parser.add_argument('-mi', '--miracl', help='Mode for compatibility (accounts for tif to nii reorienting)', action='store_true', default=False) - parser.add_argument('-v', '--verbose', help='Increase verbosity.', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-i', '--input', help='INPUT: Path of native image relative to ./sample??', required=True, action=SM) + reqs.add_argument('-o', '--output', help='Output filename. E.g., img_in_atlas_space.nii.gz. Saved in ./sample??/atlas_space/', required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-c', '--chann_idx', help='.czi channel index. Default: 1', default=1, type=int, action=SM) + opts.add_argument('-md', '--metadata', help='path/metadata.txt. Default: parameters/metadata.txt', default="parameters/metadata.txt", action=SM) + opts.add_argument('-a', '--atlas', help='path/atlas.nii.gz for use as the fixed image (Default: atlas/atlas_CCFv3_2020_30um.nii.gz)', default='atlas/atlas_CCFv3_2020_30um.nii.gz', action=SM) + opts.add_argument('-dt', '--dtype', help='Desired dtype for output (e.g., uint8, uint16). Default: uint16', default="uint16", action=SM) + opts.add_argument('-fri', '--fixed_reg_in', help='Reference nii header from ``reg``. Default: reg_outputs/autofl_50um_masked_fixed_reg_input.nii.gz', default="reg_outputs/autofl_50um_masked_fixed_reg_input.nii.gz", action=SM) + opts.add_argument('-r', '--reg_res', help='Resolution of registration inputs in microns. Default: 50', default='50',type=int, action=SM) + opts.add_argument('-inp', '--interpol', help='Type of interpolation (linear, bSpline [default], multiLabel, nearestNeighbor).', default='bSpline', action=SM) # or + opts.add_argument('-zo', '--zoom_order', help='SciPy zoom order for resampling the raw image to --reg_res. Default: 1', default=1, type=int, action=SM) + + compatability = parser.add_argument_group('Compatability options') + compatability.add_argument('-mi', '--miracl', help='Mode for compatibility (accounts for tif to nii reorienting)', action='store_true', default=False) + + general = parser.add_argument_group('General arguments') + general.add_argument('-d', '--dirs', help='Paths to sample?? dirs and/or dirs containing them (space-separated) for batch processing. Default: current dir', nargs='*', default=None, action=SM) + general.add_argument('-p', '--pattern', help='Pattern for directories to process. Default: sample??', default='sample??', action=SM) + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    @@ -483,13 +484,11 @@

    Source code for unravel.warp.to_atlas

         Configuration.verbose = args.verbose
         verbose_start_msg()
     
    -    samples = get_samples(args.dirs, args.pattern, args.exp_paths)
    +    sample_paths = get_samples(args.dirs, args.pattern, args.verbose)
     
    -    progress, task_id = initialize_progress_bar(len(samples), "[red]Processing samples...")
    +    progress, task_id = initialize_progress_bar(len(sample_paths), "[red]Processing samples...")
         with Live(progress):
    -        for sample in samples:
    -            
    -            sample_path = Path(sample).resolve() if sample != Path.cwd().name else Path.cwd()
    +        for sample_path in sample_paths:
     
                 output = sample_path / "atlas_space" / args.output
                 output.parent.mkdir(exist_ok=True, parents=True)
    @@ -497,9 +496,16 @@ 

    Source code for unravel.warp.to_atlas

                     print(f"\n\n    {output} already exists. Skipping.\n")
                     continue
     
    +            # Load resolutions from metadata
    +            metadata_path = sample_path / args.metadata
    +            xy_res, z_res, _, _, _ = load_image_metadata_from_txt(metadata_path)
    +            if xy_res is None:
    +                print("    [red1]./sample??/parameters/metadata.txt is missing. Generate w/ io_metadata")
    +                import sys ; sys.exit()
    +
                 # Load full res image [and xy and z voxel size in microns], to be resampled [and reoriented], padded, and warped
                 img_path = sample_path / args.input
    -            img, xy_res, z_res = load_3D_img(img_path, args.chann_idx, "xyz", return_res=True, xy_res=args.xy_res, z_res=args.z_res)
    +            img = load_3D_img(img_path, args.channel)
     
                 # Resample the rb_img to the resolution of registration (and optionally reorient for compatibility with MIRACL)
                 img = reg_prep(img, xy_res, z_res, args.reg_res, args.zoom_order, args.miracl)
    diff --git a/_modules/unravel/warp/to_fixed.html b/_modules/unravel/warp/to_fixed.html
    index 335806d6..06c55513 100644
    --- a/_modules/unravel/warp/to_fixed.html
    +++ b/_modules/unravel/warp/to_fixed.html
    @@ -356,25 +356,24 @@ 

    Source code for unravel.warp.to_fixed

     """
     Use ``warp_to_fixed`` from UNRAVEL to forward warp a moving image (e.g., from atlas space) to fixed image space (e.g., tissue space). The input/output do not need padding.
     
    -Usage:
    -------
    -    warp_to_fixed -f reg_inputs/autofl_50um_masked.nii.gz -m path/moving_img.nii.gz -o path/warped_img.nii.gz -ro reg_outputs -fri autofl_50um_masked_fixed_reg_input.nii.gz [-i multiLabel] [-r 50] [-v]
    -
     Note: 
    -    Run this from the folder containing reg_outputs.
    +    - Run this from the folder containing reg_outputs.
    +    - This script is for warping between different atlas spaces. For warping from atlas space to tissue space, use ``to_native``.
     
    -    This script is for warping between different atlas spaces. For warping from atlas space to tissue space, use ``to_native``.
    +Usage:
    +------
    +    warp_to_fixed -f reg_inputs/autofl_50um_masked.nii.gz -m path/moving_img.nii.gz -o path/warped_img.nii.gz [-ro reg_outputs] [-fri autofl_50um_masked_fixed_reg_input.nii.gz] [-i multiLabel] [-v]
     """
     
    -import argparse
     import nibabel as nib
     import numpy as np
     from pathlib import Path
     from rich import print
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +
     from unravel.core.config import Configuration
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
     from unravel.core.img_io import save_as_nii
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, print_func_name_args_times
     from unravel.warp.warp import warp
    @@ -383,15 +382,21 @@ 

    Source code for unravel.warp.to_fixed

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-f', '--fixed_img', help='path/fixed_img.nii.gz used as input for ``reg`` (no padding; e.g., reg_inputs/autofl_50um_masked.nii.gz)', required=True, action=SM) - parser.add_argument('-m', '--moving_img', help='path/moving_image.nii.gz to warp (e.g., from atlas space)', required=True, action=SM) - parser.add_argument('-o', '--output', help='path/native_image.nii.gz', required=True, action=SM) - parser.add_argument('-ro', '--reg_outputs', help="Name of folder w/ outputs from registration. Default: reg_outputs", default="reg_outputs", action=SM) - parser.add_argument('-fri', '--fixed_reg_in', help='Fixed input for registration (``reg``) w/ padding in <reg_outputs>. E.g., autofl_50um_masked_fixed_reg_input.nii.gz', required=True, action=SM) - parser.add_argument('-i', '--interpol', help='Interpolator for ants.apply_transforms (nearestNeighbor, multiLabel [default], linear, bSpline)', default="multiLabel", action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity.', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-f', '--fixed_img', help='path/fixed_img.nii.gz used as input for ``reg`` (no padding; e.g., reg_inputs/autofl_50um_masked.nii.gz)', required=True, action=SM) + reqs.add_argument('-m', '--moving_img', help='path/moving_image.nii.gz to warp (e.g., from atlas space)', required=True, action=SM) + reqs.add_argument('-o', '--output', help='path/native_image.nii.gz', required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-ro', '--reg_outputs', help="Name of folder w/ outputs from registration. Default: reg_outputs", default="reg_outputs", action=SM) + opts.add_argument('-fri', '--fixed_reg_in', help='Fixed input for registration (``reg``) w/ padding in <reg_outputs>. E.g., autofl_50um_masked_fixed_reg_input.nii.gz', required=True, action=SM) + opts.add_argument('-i', '--interpol', help='Interpolator warping with ants.apply_transforms (nearestNeighbor, multiLabel [default], linear, bSpline)', default="multiLabel", action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_modules/unravel/warp/to_native.html b/_modules/unravel/warp/to_native.html index c408857c..d4b86a31 100644 --- a/_modules/unravel/warp/to_native.html +++ b/_modules/unravel/warp/to_native.html @@ -356,9 +356,8 @@

    Source code for unravel.warp.to_native

     """
     Use ``warp_to_native`` from UNRAVEL to warp an atlas space image to tissue space and scale to full resolution.
     
    -CLI usage:
    -----------
    -    warp_to_native -m <path/image_to_warp_from_atlas_space.nii.gz> -o <native>/native_<img>.zarr
    +Prereq:
    +    - ./parameters/metadata.txt (from io_metadata)
     
     Python usage:
     -------------
    @@ -366,11 +365,11 @@ 

    Source code for unravel.warp.to_native

         >>> native_img = to_native(sample_path, reg_outputs, fixed_reg_in, moving_img_path, metadata_rel_path, reg_res, miracl, zoom_order, interpol, output=None)
         >>> # native_img is an np.ndarray
     
    -Prereq:
    -    ./parameters/metadata.txt (from io_metadata)
    +Usage:
    +------
    +    warp_to_native -m <path/image_to_warp_from_atlas_space.nii.gz> [-o <path/native_image.zarr>] [-fri autofl_50um_masked_fixed_reg_input.nii.gz] [-i multiLabel] [-md parameters/metadata.txt] [-ro reg_outputs] [--reg_res 50] [-zo 0] [-mi] [-d list of paths] [-p sample??] [-v]
     """
     
    -import argparse
     import nibabel as nib
     import numpy as np
     from pathlib import Path
    @@ -379,8 +378,9 @@ 

    Source code for unravel.warp.to_native

     from rich.traceback import install
     from scipy.ndimage import zoom
     
    -from unravel.core.argparse_utils import SuppressMetavar, SM
    +
     from unravel.core.config import Configuration
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
     from unravel.core.img_io import load_image_metadata_from_txt, save_as_zarr, save_as_nii
     from unravel.core.img_tools import reverse_reorient_for_raw_to_nii_conv
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, get_samples, initialize_progress_bar, print_func_name_args_times
    @@ -390,21 +390,28 @@ 

    Source code for unravel.warp.to_native

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-e', '--exp_paths', help='List of experiment dir paths w/ sample?? dirs to process.', nargs='*', default=None, action=SM) - parser.add_argument('-p', '--pattern', help='Pattern for sample?? dirs. Use cwd if no matches.', default='sample??', action=SM) - parser.add_argument('-d', '--dirs', help='List of sample?? dir names or paths to dirs to process', nargs='*', default=None, action=SM) - parser.add_argument('-m', '--moving_img', help='path/image.nii.gz to warp from atlas space', required=True, action=SM) - parser.add_argument('-fri', '--fixed_reg_in', help='Fixed input for registration (``reg``). Default: autofl_50um_masked_fixed_reg_input.nii.gz', default="autofl_50um_masked_fixed_reg_input.nii.gz", action=SM) - parser.add_argument('-i', '--interpol', help='Interpolator for ants.apply_transforms (nearestNeighbor, multiLabel [default], linear, bSpline)', default="multiLabel", action=SM) - parser.add_argument('-o', '--output', help='Save as rel_path/native_image.zarr (fast) or rel_path/native_image.nii.gz if provided', default=None, action=SM) - parser.add_argument('-md', '--metadata', help='path/metadata.txt. Default: ./parameters/metadata.txt', default="./parameters/metadata.txt", action=SM) - parser.add_argument('-ro', '--reg_outputs', help="Name of folder w/ outputs from registration. Default: reg_outputs", default="reg_outputs", action=SM) - parser.add_argument('-r', '--reg_res', help='Resolution of registration inputs in microns. Default: 50', default='50',type=int, action=SM) - parser.add_argument('-zo', '--zoom_order', help='SciPy zoom order for scaling to full res. Default: 0 (nearest-neighbor)', default='0',type=int, action=SM) - parser.add_argument('-mi', '--miracl', help='Mode for compatibility (accounts for tif to nii reorienting)', action='store_true', default=False) - parser.add_argument('-v', '--verbose', help='Increase verbosity.', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-m', '--moving_img', help='path/image.nii.gz to warp from atlas space', required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-o', '--output', help='Save as rel_path/native_image.zarr (fast) or rel_path/native_image.nii.gz if provided', default=None, action=SM) + opts.add_argument('-fri', '--fixed_reg_in', help='Fixed input for registration (``reg``). Default: autofl_50um_masked_fixed_reg_input.nii.gz', default="autofl_50um_masked_fixed_reg_input.nii.gz", action=SM) + opts.add_argument('-i', '--interpol', help='Interpolator for warping with ants.apply_transforms (nearestNeighbor, multiLabel [default], linear, bSpline)', default="multiLabel", action=SM) + opts.add_argument('-md', '--metadata', help='path/metadata.txt. Default: parameters/metadata.txt', default="parameters/metadata.txt", action=SM) + opts.add_argument('-ro', '--reg_outputs', help="Name of folder w/ outputs from registration. Default: reg_outputs", default="reg_outputs", action=SM) + opts.add_argument('-r', '--reg_res', help='Resolution of registration inputs in microns. Default: 50', default='50',type=int, action=SM) + opts.add_argument('-zo', '--zoom_order', help='SciPy zoom order for scaling to full res. Default: 0 (nearest-neighbor)', default='0',type=int, action=SM) + + compatability = parser.add_argument_group('Compatability options') + compatability.add_argument('-mi', '--miracl', help='Mode for compatibility (accounts for tif to nii reorienting)', action='store_true', default=False) + + general = parser.add_argument_group('General arguments') + general.add_argument('-d', '--dirs', help='Paths to sample?? dirs and/or dirs containing them (space-separated) for batch processing. Default: current dir', nargs='*', default=None, action=SM) + general.add_argument('-p', '--pattern', help='Pattern for directories to process. Default: sample??', default='sample??', action=SM) + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    @@ -523,13 +530,11 @@

    Source code for unravel.warp.to_native

         Configuration.verbose = args.verbose
         verbose_start_msg()
     
    -    samples = get_samples(args.dirs, args.pattern, args.exp_paths)
    +    sample_paths = get_samples(args.dirs, args.pattern, args.verbose)
     
    -    progress, task_id = initialize_progress_bar(len(samples), "[red]Processing samples...")
    +    progress, task_id = initialize_progress_bar(len(sample_paths), "[red]Processing samples...")
         with Live(progress):
    -        for sample in samples:
    -            
    -            sample_path = Path(sample).resolve() if sample != Path.cwd().name else Path.cwd()
    +        for sample_path in sample_paths:
     
                 if args.output is not None:
                     output = sample_path / args.output
    diff --git a/_modules/unravel/warp/warp.html b/_modules/unravel/warp/warp.html
    index 510442bb..07da1e32 100644
    --- a/_modules/unravel/warp/warp.html
    +++ b/_modules/unravel/warp/warp.html
    @@ -356,30 +356,29 @@ 

    Source code for unravel.warp.warp

     """
     Use ``warp`` from UNRAVEL to warp to/from atlas space and registration input space
     
    +Prereq: 
    +    - ``reg``
    +
    +Note: 
    +    - This warps padded images in ./reg_outputs (i.e., images that match the padded fixed reg input). For unpadded final images, use ``warp_to_fixed`` and ``warp_to_atlas``.
    +
     Usage for forward warping atlas to tissue space:
     ------------------------------------------------
    -    warp -m atlas_img.nii.gz -f reg_outputs/autofl_50um_masked_fixed_reg_input.nii.gz -ro reg_outputs -o native_space/atlas_in_tissue_space.nii.gz -inp multiLabel -v
    +    warp -m atlas_img.nii.gz -f reg_outputs/autofl_50um_masked_fixed_reg_input.nii.gz -o native_space/atlas_in_tissue_space.nii.gz -inp multiLabel [-ro reg_outputs] [-v]
     
     Usage for inverse warping tissue to atlas space:
     ------------------------------------------------
    -    warp -m reg_outputs/autofl_50um_masked_fixed_reg_input.nii.gz -f atlas_img.nii.gz -ro reg_outputs -o atlas_space/tissue_in_atlas_space.nii.gz -inv -v
    -
    -Prereq: 
    -    ``reg``
    -
    -Note: 
    -    This warps padded images in ./reg_outputs (i.e., images that match the padded fixed reg input). For unpadded final images, use ``warp_to_fixed`` and ``warp_to_atlas``.
    +    warp -m reg_outputs/autofl_50um_masked_fixed_reg_input.nii.gz -f atlas_img.nii.gz -o atlas_space/tissue_in_atlas_space.nii.gz -inv [--inp bSpline] [-ro reg_outputs] [-v]
     """
     
     import ants
    -import argparse
     import numpy as np
     import nibabel as nib
     from pathlib import Path
     from rich import print
     from rich.traceback import install
     
    -from unravel.core.argparse_utils import SM, SuppressMetavar
    +from unravel.core.help_formatter import RichArgumentParser, SuppressMetavar, SM
     from unravel.core.config import Configuration
     from unravel.core.utils import log_command, verbose_start_msg, verbose_end_msg, print_func_name_args_times
     
    @@ -387,15 +386,21 @@ 

    Source code for unravel.warp.warp

     
    [docs] def parse_args(): - parser = argparse.ArgumentParser(formatter_class=SuppressMetavar) - parser.add_argument('-ro', '--reg_outputs', help='path/reg_outputs', required=True, action=SM) - parser.add_argument('-f', '--fixed_img', help='path/fixed_image.nii.gz', required=True, action=SM) - parser.add_argument('-m', '--moving_img', help='path/moving_image.nii.gz', required=True, action=SM) - parser.add_argument('-o', '--output', help='path/output.nii.gz', required=True, action=SM) - parser.add_argument('-inv', '--inverse', help='Perform inverse warping (use flag if -f & -m are opposite from ``reg``)', default=False, action='store_true') - parser.add_argument('-inp', '--interpol', help='Type of interpolation (linear, bSpline [default], nearestNeighbor, multiLabel).', default='bSpline', action=SM) - parser.add_argument('-v', '--verbose', help='Increase verbosity.', action='store_true', default=False) - parser.epilog = __doc__ + parser = RichArgumentParser(formatter_class=SuppressMetavar, add_help=False, docstring=__doc__) + + reqs = parser.add_argument_group('Required arguments') + reqs.add_argument('-m', '--moving_img', help='path/moving_image.nii.gz', required=True, action=SM) + reqs.add_argument('-f', '--fixed_img', help='path/fixed_image.nii.gz', required=True, action=SM) + reqs.add_argument('-o', '--output', help='path/output.nii.gz', required=True, action=SM) + + opts = parser.add_argument_group('Optional arguments') + opts.add_argument('-inv', '--inverse', help='Perform inverse warping (use flag if -f & -m are opposite from ``reg``)', default=False, action='store_true') + reqs.add_argument('-ro', '--reg_outputs', help='path/reg_outputs (contains transformation files)', default='reg_ouputs', action=SM) + opts.add_argument('-inp', '--interpol', help='Type of interpolation (linear, bSpline [default], nearestNeighbor, multiLabel).', default='bSpline', action=SM) + + general = parser.add_argument_group('General arguments') + general.add_argument('-v', '--verbose', help='Increase verbosity. Default: False', action='store_true', default=False) + return parser.parse_args()
    diff --git a/_sources/guide.md.txt b/_sources/guide.md.txt index 980395e0..23cfcf93 100644 --- a/_sources/guide.md.txt +++ b/_sources/guide.md.txt @@ -232,13 +232,13 @@ To view help on arguments for each script (a.k.a. module) in the online document unravel_commands -c # List common commands and filter results -unravel_commands -c | grep vstats # Just print commands related to voxel-wise statistics +uc -f vstats # Just print commands related to voxel-wise statistics # List common commands and their descriptions -unravel_commands -c -d +uc -c -d # List all commands and the modules that they run -unravel_commands -m +uc -m ``` :::{hint} @@ -541,7 +541,7 @@ Other patterns (e.g., sample???) may be used (commands have a -p option for that ```{admonition} Data can be distributed across multiple drives :class: tip dropdown -Paths to each experiment directory may be passed into scripts using the -e flag for batch processing +Paths to each experiment directory may be passed into scripts using the -d flag for batch processing This is useful if there is not enough storage on a single drive. @@ -555,7 +555,7 @@ If SSDs are used, distrubuting data may not speed up processing as much. :class: tip dropdown This helps with keeping track of paths, commands, etc.. ```bash -cd # Change the current working directory to an exp dir +cd touch exp_notes.txt # Make the .txt file ``` ::: @@ -607,7 +607,7 @@ exp ### Optional: clean tifs * If raw data is in the form of a tif series, consider running: ```bash -utils_clean_tifs -t -v -m -e $DIRS #DIRS can be set as a global variable (e.g., with env_var.sh). It should have a list of directories with sample?? dirs to process. +utils_clean_tifs -t -v -m -d $DIRS #DIRS can be set as a global variable (e.g., with env_var.sh). It should have a list of directories with sample?? dirs to process. ``` ```{admonition} utils_clean_tifs :class: tip dropdown @@ -644,7 +644,7 @@ reg_prep -i *.czi -x $XY -z $Z -v # -i options: tif_dir, .h5, .zarr, .tif {py:mod}`unravel.segment.copy_tifs` * Copy resampled autofluo .tif files for making a brain mask with ilastik ```bash -seg_copy_tifs -i reg_inputs/autofl_??um_tifs -s 0000 0005 0050 -o $(dirname $BRAIN_MASK_ILP) -e $DIRS +seg_copy_tifs -i reg_inputs/autofl_??um_tifs -s 0000 0005 0050 -o $(dirname $BRAIN_MASK_ILP) -d $DIRS ``` #### Train an Ilastik project @@ -673,7 +673,7 @@ alias ilastik=run_ilastik.sh # This is for Linux (update the relative path if n - Either double click on the application or run: `ilastik` 1. **Input Data** - Drag training slices into the ilastik GUI + Drag training slices into the ilastik GUI (e.g., from a dir w/ 3 slices per sample and > 2 samples per condition) `ctrl+A` -> right-click -> Edit shared properties -> Storage: Copy into project file -> Ok 2. **Feature Selection** @@ -708,7 +708,7 @@ alias ilastik=run_ilastik.sh # This is for Linux (update the relative path if n {py:mod}`unravel.segment.brain_mask` * Makes reg_inputs/autofl_??um_brain_mask.nii.gz and reg_inputs/autofl_??um_masked.nii.gz for ``reg`` ```bash -seg_brain_mask -ilp $BRAIN_MASK_ILP -v -e $DIRS +seg_brain_mask -ilp $BRAIN_MASK_ILP -v -d $DIRS ``` :::{hint} @@ -741,7 +741,7 @@ Add tutorial for 3D slicer ``` ```bash -reg -m $TEMPLATE -bc -pad -sm 0.4 -ort RPS -a $ATLAS -v -e $DIRS +reg -m $TEMPLATE -bc -pad -sm 0.4 -ort RPS -a $ATLAS -v -d $DIRS ``` :::{admonition} If sample orientations vary @@ -759,7 +759,7 @@ for d in $DIRS ; do cd $d ; for s in sample?? ; do reg -m $TEMPLATE -bc -pad -sm * sample??/reg_outputs/autofl_??um_masked_fixed_reg_input.nii.gz * sample??/reg_outputs/atlas_in_tissue_space.nii.gz ```bash -reg_check -e $DIRS -td $BASE/reg_results +reg_check -d $DIRS -td $BASE/reg_results ``` * View these images with [FSLeyes](https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/FSLeyes) [docs](https://open.win.ox.ac.uk/pages/fsl/fsleyes/fsleyes/userdoc/index.html) @@ -782,14 +782,14 @@ reg_check -e $DIRS -td $BASE/reg_results Copy 3 tifs from each sample or 3 tifs from 3 samples / condition ::: ```bash -seg_copy_tifs -i -s 0100 0500 1000 -o ilastik_segmentation -e $DIRS -v +seg_copy_tifs -i -s 0100 0500 1000 -o ilastik_segmentation -d $DIRS -v ``` #### `seg_ilastik` {py:mod}`unravel.segment.ilastik_pixel_classification` * Perform pixel classification using a trained Ilastik project ```bash -seg_ilastik -i <*.czi, *.h5, or dir w/ tifs> -o seg_dir -ilp $BASE/ilastik_segmentation/trained_ilastik_project.ilp -l 1 -v -e $DIRS +seg_ilastik -i <*.czi, *.h5, or dir w/ tifs> -o seg_dir -ilp $BASE/ilastik_segmentation/trained_ilastik_project.ilp -l 1 -v -d $DIRS ``` @@ -872,7 +872,7 @@ seg_ilastik -i <*.czi, *.h5, or dir w/ tifs> -o seg_dir -ilp $BASE/ilastik_segme {py:mod}`unravel.voxel_stats.vstats_prep` * Preprocess immunofluo images and warp them to atlas space for voxel-wise statistics. ```bash -vstats_prep -i cFos -rb 4 -x $XY -z $Z -o cFos_rb4_atlas_space.nii.gz -v -e $DIRS +vstats_prep -i cFos -rb 4 -x $XY -z $Z -o cFos_rb4_atlas_space.nii.gz -v -d $DIRS ``` :::{admonition} Background subtraction :class: tip dropdown @@ -898,7 +898,7 @@ You can test parameters for background subtraction with: * Z-score atlas space images using tissue masks (from brain_mask) and/or an atlas mask. ```bash -vstats_z_score -i atlas_space/sample??_cFos_rb4_atlas_space.nii.gz -v -e $DIRS +vstats_z_score -i atlas_space/sample??_cFos_rb4_atlas_space.nii.gz -v -d $DIRS ``` :::{hint} * atlas_space is a folder in ./sample??/ with outputs from vstats_prep @@ -908,7 +908,7 @@ vstats_z_score -i atlas_space/sample??_cFos_rb4_atlas_space.nii.gz -v -e $DIRS {py:mod}`unravel.utilities.aggregate_files_from_sample_dirs` * Aggregate pre-processed immunofluorescence (IF) images for voxel-wise stats ```bash -utils_agg_files -i atlas_space/sample??_cFos_rb4_atlas_space_z.nii.gz -e $DIRS -v +utils_agg_files -i atlas_space/sample??_cFos_rb4_atlas_space_z.nii.gz -d $DIRS -v ``` #### `vstats_whole_to_avg` @@ -1002,10 +1002,10 @@ cluster_mirror_indices -m RH -v * Warps cluster index from atlas space to tissue space, crops clusters, applies segmentation mask, and quantifies cell/object or label densities ```bash # Basic usage: -cluster_validation -e -m -s seg_dir -v +cluster_validation -d -m -s seg_dir -v # Processing multiple FDR q value thresholds and both hemispheres: -for q in 0.005 0.01 0.05 0.1 ; do for side in LH RH ; do cluster_validation -e $DIRS -m path/vstats/contrast/stats/contrast_vox_p_tstat1_q${q}/contrast_vox_p_tstat1_q${q}_rev_cluster_index_${side}.nii.gz -s seg_dir/sample??_seg_dir_1.nii.gz -v ; done ; done +for q in 0.005 0.01 0.05 0.1 ; do for side in LH RH ; do cluster_validation -d $DIRS -m path/vstats/contrast/stats/contrast_vox_p_tstat1_q${q}/contrast_vox_p_tstat1_q${q}_rev_cluster_index_${side}.nii.gz -s seg_dir/sample??_seg_dir_1.nii.gz -v ; done ; done ``` #### `cstats_summary` @@ -1013,7 +1013,7 @@ for q in 0.005 0.01 0.05 0.1 ; do for side in LH RH ; do cluster_validation -e $ * Aggregates and analyzes cluster validation data from `cstats_validation` * Update parameters in /UNRAVEL/unravel/cstats/cluster_summary.ini and save it with the experiment ```bash -cluster_summary -c path/cluster_summary.ini -e $DIRS -cvd '*' -vd path/vstats_dir -sk $SAMPLE_KEY --groups group1 group2 -v +cluster_summary -c path/cluster_summary.ini -d $DIRS -cvd '*' -vd path/vstats_dir -sk $SAMPLE_KEY --groups group1 group2 -v ``` group1 and group2 must match conditions in the sample_key.csv diff --git a/_sources/unravel/core/argparse_utils.rst.txt b/_sources/unravel/core/argparse_utils.rst.txt deleted file mode 100644 index 18b16a27..00000000 --- a/_sources/unravel/core/argparse_utils.rst.txt +++ /dev/null @@ -1,9 +0,0 @@ -.. _unravel.core.argparse_utils: - -unravel.core.argparse_utils module -================================== - -.. automodule:: unravel.core.argparse_utils - :members: - :undoc-members: - :show-inheritance: diff --git a/_sources/unravel/core/argparse_utils_rich.rst.txt b/_sources/unravel/core/argparse_utils_rich.rst.txt deleted file mode 100644 index 2616cbd3..00000000 --- a/_sources/unravel/core/argparse_utils_rich.rst.txt +++ /dev/null @@ -1,9 +0,0 @@ -.. _unravel.core.argparse_utils_rich: - -unravel.core.argparse_utils_rich module -======================================= - -.. automodule:: unravel.core.argparse_utils_rich - :members: - :undoc-members: - :show-inheritance: diff --git a/_sources/unravel/core/help_formatter.rst.txt b/_sources/unravel/core/help_formatter.rst.txt new file mode 100644 index 00000000..2a776568 --- /dev/null +++ b/_sources/unravel/core/help_formatter.rst.txt @@ -0,0 +1,9 @@ +.. _unravel.core.help_formatter: + +unravel.core.help_formatter module +================================== + +.. automodule:: unravel.core.help_formatter + :members: + :undoc-members: + :show-inheritance: diff --git a/_sources/unravel/core/toc.rst.txt b/_sources/unravel/core/toc.rst.txt index 2b22a0be..4e053198 100644 --- a/_sources/unravel/core/toc.rst.txt +++ b/_sources/unravel/core/toc.rst.txt @@ -4,8 +4,7 @@ unravel.core package .. toctree:: :maxdepth: 2 - argparse_utils - argparse_utils_rich + help_formatter config img_io img_tools diff --git a/genindex.html b/genindex.html index 4aa9de2a..166f0148 100644 --- a/genindex.html +++ b/genindex.html @@ -425,8 +425,6 @@

    C

  • collapse_hierarchy() (in module unravel.cluster_stats.table)
  • - - + +
  • filter_help_output() (unravel.core.help_formatter.RichArgumentParser method) +
  • filter_region_ids() (in module unravel.region_stats.rstats_mean_IF_summary)
  • - - + @@ -1635,24 +1639,17 @@

    U

  • - unravel.core.argparse_utils - -
  • -
  • - unravel.core.argparse_utils_rich + unravel.core.config
  • - unravel.core.config + unravel.core.help_formatter
  • @@ -1795,8 +1792,6 @@

    U

  • module
  • - -
    • unravel.image_tools.bbox @@ -1804,6 +1799,8 @@

      U

    • module
    + +
    @@ -1002,7 +1002,7 @@

    Add images to sample?? directories

    Data can be distributed across multiple drives

    -

    Paths to each experiment directory may be passed into scripts using the -e flag for batch processing

    +

    Paths to each experiment directory may be passed into scripts using the -d flag for batch processing

    This is useful if there is not enough storage on a single drive.

    Also, spreading data across ~2-4 external drives allows for faster parallel processing (minimizes i/o botlenecks)

    If SSDs are used, distrubuting data may not speed up processing as much.

    @@ -1013,7 +1013,7 @@

    Log exp paths, commands, etc.

    Make an exp_notes.txt

    This helps with keeping track of paths, commands, etc..

    -
    cd <path/exp_dir>  # Change the current working directory to an exp dir
    +
    cd <path/to/dir/with/sample?? folders>
     touch exp_notes.txt  # Make the .txt file
     
    @@ -1068,7 +1068,7 @@

    Optional: clean tifs
  • If raw data is in the form of a tif series, consider running:

  • -
    utils_clean_tifs -t <dir_name> -v -m -e $DIRS  #DIRS can be set as a global variable (e.g., with env_var.sh). It should have a list of directories with sample?? dirs to process. 
    +
    utils_clean_tifs -t <dir_name> -v -m -d $DIRS  #DIRS can be set as a global variable (e.g., with env_var.sh). It should have a list of directories with sample?? dirs to process.