BrainLine

Data Helper Functions

brainlit.BrainLine.download_subvolumes(data_dir: str, brain_id: str, layer_names: list, dataset_to_save: str, data_file: str)[source]

Download subvolumes around a set of manually marked points for validation of machine learning model.

Parameters
  • data_dir (str) -- Path to directory where subvolumes will be saved.

  • brain_id (str) -- Brain ID key in brain2paths dictionary from soma_data or axon_data/

  • layer_names (list) -- List of precomputed layer names associated with the brain_id, ordered by primary signal channel (e.g. antibody), background channel, and secondary signal channel (e.g. endogenous fluorescence).

  • dataset_to_save (str) -- val or train - specifies which set of subvolumes should be downloaded, if applicable.

  • data_file (str) -- path to json file with data information.

Raises

ValueError -- If object_type is not soma or axon

brainlit.BrainLine.json_to_points(url, round=False)[source]

Extract points from a neuroglancer url.

Parameters
  • url (str) -- url to neuroglancer state (that was posted to neurodata json server).

  • round (bool, optional) -- whether to round coordinates to integers. Defaults to False.

Returns

Keys are names of point layers and values are lists of points from that layer.

Return type

dict

Apply Ilastik and Validate Models

class brainlit.BrainLine.ApplyIlastik(ilastik_path: str, project_path: str, brains_path: str, brains: list)[source]

Applies ilastik to subvolumes for the purpose of validating machine learning algorithms.

Parameters
  • ilastik_path (str) -- Path to ilastik executable.

  • project_path (str) -- Path to ilastik project.

  • brains_path (str) -- Path to directory that contains brain samples subdirectories.

  • brains (list) -- List of brain sample names.

ilastk_path

Path to ilastik executable.

Type

str

project_path

Path to ilastik project.

Type

str

brains_path

Path to directory that contains brain samples subdirectories.

Type

str

brains

List of brain sample names.

Type

list

brainlit.BrainLine.plot_results(data_dir: str, brain_ids: list, object_type: str, positive_channel: int, doubles: list = [], show_plot: bool = True)[source]

Plot precision recall curve for a specified brain.

Parameters
  • data_dir (str) -- Path to directory where brain subvolumes are stored.

  • brain_id (str) -- Brain id to examine (brain2paths key from _data.py file).

  • object_type (str) -- soma or axon, the type of data to examine.

  • positive_channel (int) -- Channel that represents neuron in the predictions.

  • doubles (list, optional) -- Filenames of soma subvolumes that contain two somas, if applicable. Defaults to [].

  • show_plot (bool, optional) -- Whether to run pyplot, useful for pytests when figures should not be displayed. Defaults to True.

Raises

ValueError -- _description_

Returns

Best f-score across all thresholds. float: Threshold that yields the best validation f-score.

Return type

float

brainlit.BrainLine.examine_threshold(data_dir: str, brain_id: str, threshold: float, object_type: str, positive_channel: int, doubles: list = [], show_plot: bool = True)[source]

Display results in napari of all subvolumes that were below some performance threshold, at a given threshold.

Parameters
  • data_dir (str) -- Path to directory where brain subvolumes are stored.

  • brain_id (str) -- Brain ID to examine (from _data.py file).

  • threshold (float) -- Threshold to examine.

  • object_type (str) -- soma or axon, the data type being examined.

  • positive_channel (int) -- 0 or 1, Channel that represents neuron in the predictions.

  • doubles (list, optional) -- Filenames of soma subvolumes that contain two somas, if applicable. Defaults to [].

  • show_plot (bool, optional) -- Whether to run napari, useful for pytests when figures should not be displayed. Defaults to True.

Raises
  • ValueError -- If object_type is neither axon nor soma

  • ValueError -- If positive_channel is not 0 or 1.

class brainlit.BrainLine.ApplyIlastik_LargeImage(ilastik_path: str, ilastik_project: str, ncpu: int, data_file: str, results_dir: Union[str, Path] = None)[source]

Apply ilastik to large image, where chunking is necessary.

Parameters
  • ilastk_path (str) -- Path to ilastik executable.

  • ilastik_project (str) -- Path to ilastik project.

  • ncpu (int) -- Number of cpus to use for applying ilastik in parallel.

  • object_type (str) -- Soma for soma detection or axon for axon segmentaiton.

  • results_dir -- (str or Path): For soma detection, the directory to write detection results.

ilastk_path

Path to ilastik executable.

Type

str

ilastik_project

Path to ilastik project.

Type

str

ncpu

Number of cpus to use for applying ilastik in parallel.

Type

int

object_type

Soma for soma detection or axon for axon segmentaiton.

Type

str

results_dir

(Path): For soma detection, the directory to write detection results.

Results Analysis

class brainlit.BrainLine.SomaDistribution(brain_ids: list, data_file: str, ontology_file: str, show_plots: bool = True)[source]

Object to generate various analysis images for results from a set of brain IDs. An implementation of BrainDistribution class.

Parameters
  • brain_ids (list) -- List of brain IDs (keys of data json file).

  • data_files (str) -- Path to json file that contains information about samples.

  • show_plots (bool) -- Whether to show plots, only works if you have graphics access.

brain2paths

Information about different data samples.

Type

dict

show_plots

Whether to show plots, only works if you have graphics access.

Type

bool

atlas_points

Key - sample ID, Value - coordinates of soma detection.

Type

dict

id_to_regioncounts

Key - sample ID, Value - dictionary of detection counts by region.

Type

dict

region_graph

Graph of region hierarchy with soma detection counts as node attributes.

Type

nx.DiGraph

class brainlit.BrainLine.AxonDistribution(brain_ids: list, data_file: str, regional_distribution_dir: str, ontology_file: str, show_plots: bool = True)[source]

Generates visualizations of results of axon segmentations of a set of brains. Implements BrainDistribution.

Parameters
  • brain_ids (list) -- List of brain IDs (keys of data json file).

  • data_files (str) -- Path to json file that contains information about samples.

  • regional_distribution_dir (str) -- Path to directory with pkl files that countain segmentation results by region.

  • show_plots (bool) -- Whether to show plots, only works if you have graphics access.

regional_distribution_dir

Path to directory with pkl files that countain segmentation results by region.

Type

str

region_graph

Graph of region hierarchy with segmentation results as node attributes.

Type

nx.DiGraph

total_axon_vols

Key - sample ID Value - Total volume of segmented axon.

Type

dict

brain2paths

Information about different data samples.

Type

dict

show_plots

Whether to show plots, only works if you have graphics access.

Type

bool