unravel.region_stats.rstats_summary module#

Use rstats_summary (rss) from UNRAVEL to plot and summarize region-wise results.

Prereqs:
  • rstats and agg to calculate regional stats and aggregate them to a single directory for analysis and plotting.

Inputs:
  • CSV files from rstats (example naming: <condition>_sample??_regional_<cell or label>_densities.csv or <condition>_sample??_regional_mean_in_seg.csv)

  • CSV files from rstats (example naming: <condition>_sample??_regional_cell_densities.csv or <condition>_sample??_regional_mean_in_seg.csv)

  • Input CSV columns: Region_ID, Side, ID_Path, Region, Abbr, <OneWordCondition>_sample??

  • The <OneWordCondition>_sample?? column has the values for each region

  • sample?? should be one word too (e.g., sample07 not sample_07)

Outputs:
  • Saved to ./<test_type>_plots_<side>

  • Plots for each region with values for each group (e.g., Saline, MDMA, Meth)

  • Summary of significant differences between groups

  • regional_values_all.csv (Columns: columns: Region_ID,Side,Name,Abbr,Saline_sample06,Saline_sample07,…,MDMA_sample01,…,Meth_sample23,…)

  • Optionally: regional_values_all_w_hemi_exclusions.csv (same as above but with hemispheres excluded based on –exclude_hemi)

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 –side both [-i <input_pattern>] [-y cell_density | label_density | y axis name] [-div 10000] [-csv CCFv3-2020_regional_summary.csv] [-b ABA] [-s light:white] [-o tukey_plots] [-e pdf] [-eh sample07:R sample12:L] [-v]

Usage for t-tests:#

rstats_summary –groups Saline MDMA –side both -c Saline [-i <input_pattern>] [-alt two-sided] [-y cell_density | label_density | y axis name] [-div 10000] [-csv CCFv3-2020_regional_summary.csv] [-b ABA] [-s light:white] [-o t-test_plots] [-e pdf] [-eh sample07:R sample12:L] [-v]

Usage for mean intensity in segmentation mask within each region:#

rstats_summary –groups Saline LPS –side both -i ‘*mean_in_seg.csv’ -y ‘Mean Iba1-IF in segmentation mask’

unravel.region_stats.rstats_summary.parse_args()[source]#
unravel.region_stats.rstats_summary.get_region_details(region_id, df)[source]#
unravel.region_stats.rstats_summary.parse_color_argument(color_arg, num_groups, region_id, csv_path)[source]#
unravel.region_stats.rstats_summary.parse_exclude_hemi(exclude_args)[source]#

Parse the –exclude_hemi arguments to determine which hemisphere to exclude for specific samples.

Parameters:

exclude_args (-) – List of strings in the format “sampleNN:R” or “sampleNN:L” indicating which hemisphere to exclude for each sample.

Returns:

“R”, “sample12”: “L”}.

Return type:

  • dict mapping sample names (e.g., “sample07”) to the hemisphere to exclude (“R” or “L”). For example, {“sample07”

unravel.region_stats.rstats_summary.mask_excluded_side(side_df, side_letter, exclude_map)[source]#

Mask the data for the specified side if it is marked for exclusion in the exclude_map. :param - side_df: the DataFrame containing the data for the current side (columns: Region_ID, Side, ID_Path, Region, Abbr, <group_sample??>, …) :type - side_df: DataFrame :param - side_letter: the letter representing the current side (“L” or “R”) :type - side_letter: str :param - exclude_map: a dictionary mapping sample names to the hemisphere to exclude (e.g., {“sample07”: “R”, “sample12”: “L”}) :type - exclude_map: dict

Returns:

the modified DataFrame with the specified side masked (set to NaN) for the samples that are marked for exclusion in the exclude_map

Return type:

  • DataFrame

Parameters:
  • side_df (DataFrame) –

  • side_letter (str) –

  • exclude_map (dict[str, str]) –

unravel.region_stats.rstats_summary.summarize_significance(test_df, id)[source]#

Summarize the results of the statistical tests.

Parameters:
  • test_df (-) – the DataFrame containing the test results (w/ columns: group1, group2, p-value, meandiff)

  • id (-) – the region or cluster ID

Returns:

the DataFrame containing the summarized results

Return type:

  • summary_df (DataFrame)

unravel.region_stats.rstats_summary.process_and_plot_data(df, region_id, region_name, region_abbr, side, out_dir, group_columns, test_type, args)[source]#

Process the data for a specific region and create a bar plot with statistical comparisons.

unravel.region_stats.rstats_summary.main()[source]#