unravel.cluster_stats.validation module#

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.

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)

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”

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]

unravel.cluster_stats.validation.parse_args()[source]#
unravel.cluster_stats.validation.crop_outer_space(native_cluster_index, output_path)[source]#

Crop outer space around all clusters and save bounding box to .txt file (outer_bounds.txt) Return cropped native_cluster_index, outer_xmin, outer_xmax, outer_ymin, outer_ymax, outer_zmin, outer_zmax

unravel.cluster_stats.validation.cluster_bbox(cluster_ID, native_cluster_index_cropped)[source]#

Get bounding box for the current cluster. Return cluster_ID, xmin, xmax, ymin, ymax, zmin, zmax.

unravel.cluster_stats.validation.cluster_bbox_parallel(native_cluster_index_cropped, clusters)[source]#

Get bounding boxes for each cluster in parallel. Return list of results.

unravel.cluster_stats.validation.count_cells(seg_in_cluster, connectivity=6)[source]#

Count cells (objects) in each cluster using connected-components-3d Return the number of cells in the cluster.

unravel.cluster_stats.validation.density_in_cluster(cluster_data, native_cluster_index_cropped, seg_cropped, xy_res, z_res, connectivity=6, density='cell_count')[source]#

Measure cell count or volume of segmented voxels in the current cluster. For cell densities, return: cluster_ID, cell_count, cluster_volume_in_cubic_mm, cell_density, xmin, xmax, ymin, ymax, zmin, zmax For label densities, return: cluster_ID, seg_volume_in_cubic_mm, cluster_volume_in_cubic_mm, label_density, xmin, xmax, ymin, ymax, zmin, zmax.

unravel.cluster_stats.validation.density_in_cluster_parallel(cluster_bbox_results, native_cluster_index_cropped, seg_cropped, xy_res, z_res, connectivity=6, density='cell_count')[source]#

Measure cell count or volume of segmented voxels in each cluster in parallel. Return list of results.

unravel.cluster_stats.validation.main()[source]#