Skip to content

A collection of scripts that checks the masks generated by aligning images to the Allen Brain Atlas

License

Notifications You must be signed in to change notification settings

nimh-dsst/Brain-Atlas-Checker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Brain-Atlas-Checker

A collection of scripts that checks the masks generated by aligning images to the Allen Brain Atlas

Overview

The Brain Atlas Checker is a Python tool designed to recursively scan directories for TIFF files within atlaslabel_def_origspace folders and compare their unique values against a reference CSV file. This tool is particularly useful for validating atlas label files against a known set of valid IDs.

Atlas Info

The atlas_info.csv file in atlases/atlas_v3 was derived from the atlas_info.txt file from Snehashish Roy's CATNIP GitHub Repo.

Features

  • Recursive directory scanning for atlaslabel_def_origspace folders
  • TIFF file parsing to extract unique values
  • CSV parsing for reference IDs
  • Identification of values present in TIFF files but missing from the reference CSV
  • JSON output support
  • Verbose mode for detailed progress tracking

Requirements

click
tifffile

Installation

  1. Clone this repository
  2. Install required packages:
pip install click tifffile

Usage

Basic Command Line Usage

python tiff_scanner.py /path/to/root/directory

With Options

# Save results to JSON file
python tiff_scanner.py /path/to/root/directory -o results.json

# Use verbose mode
python tiff_scanner.py /path/to/root/directory -v

# Specify custom CSV path
python tiff_scanner.py /path/to/root/directory --csv-path /path/to/custom/atlas_info.csv

# Combine options
python tiff_scanner.py /path/to/root/directory -o results.json -v --csv-path /path/to/custom/atlas_info.csv

Command Line Options

  • root_directory: (Required) The starting directory for the recursive search
  • --output, -o: Output JSON file path (optional)
  • --verbose, -v: Enable detailed progress information
  • --csv-path: Path to atlas info CSV file (defaults to "/atlases/atlas_v3/atlas_info.csv")

Output Format

The tool generates a JSON output with the following structure:

{
    "/absolute/path/to/directory1": [1, 2, 3],
    "/absolute/path/to/directory2": [4, 5, 6]
}

Each key is an absolute path to a processed directory, and the corresponding value is a list of integer IDs that were found in the TIFF files but not in the reference CSV.

CSV File Format

The tool expects a CSV file with the following structure:

id,name,acronym,red,green,blue,structure_order,parent_id,parent_acronym
1,Structure1,STR1,255,78,86,75500,557,STR
2,Structure2,STR2,137,205,161,6200,345,STR

The id column is used as the reference for valid values.

Error Handling

  • Invalid CSV files or missing directories will raise appropriate errors
  • Individual TIFF file processing errors are logged but won't stop the overall process
  • Non-integer values in TIFF files are automatically filtered out

Programmatic Usage

The module can also be imported and used programmatically:

from tiff_scanner import scan_for_label_directories

# Scan directories and get results
results = scan_for_label_directories(
    root_path="/path/to/root/directory",
    csv_path="/path/to/atlas_info.csv"
)

# Process results
for directory, missing_ids in results.items():
    print(f"Directory: {directory}")
    print(f"Missing IDs: {missing_ids}")

Contributing

Feel free to open issues or submit pull requests for any improvements or bug fixes.

About

A collection of scripts that checks the masks generated by aligning images to the Allen Brain Atlas

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages