neuralib.atlas.ccf.classifier
- neuralib.atlas.ccf.classifier.FluorReprType
alias of
dict[str,str]
- typeddict neuralib.atlas.ccf.classifier.UserInjectionConfig[source]
typing.TypedDict.- Required Keys:
area (
str) – injection areahemisphere (
Literal['ipsi','contra','both']) – injection hemisphereignore (
bool) – whether local roi counts will be ignoredfluor_repr (
dict[str,str]) – fluorescence color and tracing source alias pairs
- class neuralib.atlas.ccf.classifier.RoiClassifier[source]
- __init__(ccf_dir, merge_level=None, plane='coronal', config=None)[source]
Classifier for see the ROIs distribution across the mouse brain
- Parameters:
ccf_dir (AbstractCCFDir) – ccf directory info
merge_level (int | str | None) – which number (int) of hierarchical merge area, or the col name (str) for output generate
plane (PLANE_TYPE) – slice cutting orientation
config (UserInjectionConfig | None) – UserInjectionConfig for customized injection info
- ccf_dir
- merge_level
- plane
- ignore_injection_site: Final[bool]
- fluor_repr: FluorReprType
- property has_overlap: bool
If has overlap channel counts
- property parsed_df: DataFrame
dataframe after parsing
Example:
┌───────────────────────────────────┬─────────┬─────────────┬─────────────┬─────────────┬─────────┬─────────┬────────┬───────────────────────────┬──────────────┬────────┬────────────┬────────────┬────────────┬────────────┬────────────┬───────────┐ │ name ┆ acronym ┆ AP_location ┆ DV_location ┆ ML_location ┆ avIndex ┆ channel ┆ source ┆ abbr ┆ acronym_abbr ┆ hemi. ┆ merge_ac_0 ┆ merge_ac_1 ┆ merge_ac_2 ┆ merge_ac_3 ┆ merge_ac_4 ┆ family │ │ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │ │ str ┆ str ┆ f64 ┆ f64 ┆ f64 ┆ i64 ┆ str ┆ str ┆ str ┆ str ┆ str ┆ str ┆ str ┆ str ┆ str ┆ str ┆ str │ ╞═══════════════════════════════════╪═════════╪═════════════╪═════════════╪═════════════╪═════════╪═════════╪════════╪═══════════════════════════╪══════════════╪════════╪════════════╪════════════╪════════════╪════════════╪════════════╪═══════════╡ │ Ectorhinal area/Layer 5 ┆ ECT5 ┆ -3.03 ┆ 4.34 ┆ -4.5 ┆ 377 ┆ gfp ┆ aRSC ┆ Ectorhinal area ┆ ECT ┆ contra ┆ ECT ┆ ECT ┆ ECT ┆ ECT ┆ ECT ┆ ISOCORTEX │ │ Perirhinal area layer 6a ┆ PERI6a ┆ -3.03 ┆ 4.42 ┆ -4.37 ┆ 372 ┆ gfp ┆ aRSC ┆ Perirhinal area ┆ PERI ┆ contra ┆ PERI ┆ PERI ┆ PERI ┆ PERI ┆ PERI ┆ ISOCORTEX │ │ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … │ │ Ventral auditory area layer 6a ┆ AUDv6a ┆ -2.91 ┆ 3.52 ┆ 4.46 ┆ 156 ┆ rfp ┆ pRSC ┆ Ventral auditory area ┆ AUDv ┆ ipsi ┆ AUD ┆ AUD ┆ AUD ┆ AUD ┆ AUDv ┆ ISOCORTEX │ │ Ectorhinal area/Layer 6a ┆ ECT6a ┆ -2.91 ┆ 4.14 ┆ 4.47 ┆ 378 ┆ rfp ┆ pRSC ┆ Ectorhinal area ┆ ECT ┆ ipsi ┆ ECT ┆ ECT ┆ ECT ┆ ECT ┆ ECT ┆ ISOCORTEX │ │ Temporal association areas layer… ┆ TEa5 ┆ -2.91 ┆ 4.02 ┆ 4.55 ┆ 365 ┆ rfp ┆ pRSC ┆ Temporal association area ┆ TEa ┆ ipsi ┆ TEa ┆ TEa ┆ TEa ┆ TEa ┆ TEa ┆ ISOCORTEX │ └───────────────────────────────────┴─────────┴─────────────┴─────────────┴─────────────┴─────────┴─────────┴────────┴───────────────────────────┴──────────────┴────────┴────────────┴────────────┴────────────┴────────────┴────────────┴───────────┘
- property classified_column: Literal['acronym_abbr', 'merge_ac_0', 'merge_ac_1', 'merge_ac_2', 'merge_ac_3', 'merge_ac_4', 'family']
- property channels: list[str]
list of fluorescence channels (sorted based on
fluor_repr)
- property n_channels: int
number of fluorescence channels
- property sources: list[str]
list of unique sources
- property n_sources: int
number of source name
- property areas: list[str]
list of area in the given
classified_column
- property n_total_rois: int
number of total rois
- property nroi_channel: DataFrame
channels and counts Dataframe
- property nroi_source: DataFrame
channels and counts Dataframe
- property nroi_area: DataFrame
dict with key (area name) and value (number of cells)
- get_percent_sorted_df(hemisphere='both')[source]
Get percentage-sorted dataframe
- Parameters:
hemisphere (Literal['ipsi', 'contra', 'both']) – which hemisphere {‘ipsi’, ‘contra’, ‘both’}
- Returns:
dataframe
- Return type:
DataFrame
hemi: optional col. if hemisphere is`both`, then sum together
Example of merge level equal to 2:
┌─────────┬────────────┬────────┬────────┬───────────┐ │ source ┆ merge_ac_2 ┆ *hemi. ┆ n_rois ┆ percent │ │ --- ┆ --- ┆ --- ┆ --- ┆ --- │ │ str ┆ str ┆ str ┆ u32 ┆ f64 │ ╞═════════╪════════════╪════════╪════════╪═══════════╡ │ pRSC ┆ VIS ┆ ipsi ┆ 5701 ┆ 22.761209 │ │ aRSC ┆ MO ┆ ipsi ┆ 2277 ┆ 21.360225 │ │ overlap ┆ MO ┆ ipsi ┆ 571 ┆ 17.799252 │ │ aRSC ┆ ACA ┆ ipsi ┆ 1729 ┆ 16.219512 │ │ overlap ┆ SUB ┆ ipsi ┆ 494 ┆ 15.399002 │ │ … ┆ … ┆ … ┆ … ┆ … │ │ pRSC ┆ MED ┆ contra ┆ 1 ┆ 0.003992 │ │ pRSC ┆ PPN ┆ contra ┆ 1 ┆ 0.003992 │ │ pRSC ┆ APr ┆ ipsi ┆ 1 ┆ 0.003992 │ │ pRSC ┆ BMA ┆ contra ┆ 1 ┆ 0.003992 │ │ pRSC ┆ P5 ┆ contra ┆ 1 ┆ 0.003992 │ └─────────┴────────────┴────────┴────────┴───────────┘
- get_classified_data(norm=None, *, top_area=None, source=None, add_other=False, supply_overlap=True, hemisphere='both', area=None)[source]
processed data for plotting / visualization
- Parameters:
norm (MouseBrainRoiNormHandler | None) –
BrainMapNormHandlertop_area (int | None) – select top ranks area based on channel-based normalized percentage
source (Source | None) – specify source, if not then produce all source
add_other (bool) – the rest of regions (after top selection), classified as other (i.e., pie chart)
supply_overlap (bool) – add overlap roi counts into other channel(s)
hemisphere (HEMISPHERE_TYPE) – filter the output data with selected hemisphere {‘ipsi’, ‘contra’, ‘both’}
area (Area | list[Area] | None) – filter the output data with selected area
- Returns:
- Return type:
- class neuralib.atlas.ccf.classifier.RoiClassifiedNormTable[source]
- source_classifier: RoiClassifier
- norm_type: ROIS_NORM_TYPE | None
- hemisphere: HEMISPHERE_TYPE
- data: pl.DataFrame
processed data after ROIClassifier
Optional col: hemi. , only existed if init with either
hemisphereis ‘ipsi’ or ‘contra’<ROIS_NORM_TYPE>_norm depending on
norm_type
Example of data with volume normalization method:
┌─────────┬────────────┬────────┬───────────┬───┬───────────┬───────────┬─────────────────┬────────┐ │ channel ┆ merge_ac_2 ┆ n_rois ┆ percent ┆ … ┆ Volumes ┆ n_neurons ┆ *volume_norm_n_r┆ animal │ │ --- ┆ --- ┆ --- ┆ --- ┆ ┆ [mm^3] ┆ --- ┆ ois ┆ --- │ │ str ┆ str ┆ i64 ┆ f64 ┆ ┆ --- ┆ i64 ┆ --- ┆ str │ │ ┆ ┆ ┆ ┆ ┆ f64 ┆ ┆ f64 ┆ │ ╞═════════╪════════════╪════════╪═══════════╪═══╪═══════════╪═══════════╪═════════════════╪════════╡ │ overlap ┆ ACA ┆ 423 ┆ 30.344333 ┆ … ┆ 5.222484 ┆ 337372 ┆ 80.995934 ┆ YW051 │ │ gfp ┆ MO ┆ 3352 ┆ 24.545987 ┆ … ┆ 22.248234 ┆ 985411 ┆ 150.663641 ┆ YW051 │ │ rfp ┆ ACA ┆ 1383 ┆ 23.791502 ┆ … ┆ 5.222484 ┆ 337372 ┆ 264.816494 ┆ YW051 │ │ gfp ┆ ACA ┆ 3130 ┆ 22.920328 ┆ … ┆ 5.222484 ┆ 337372 ┆ 599.331616 ┆ YW051 │ │ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … │ │ overlap ┆ SS ┆ 1 ┆ 0.071736 ┆ … ┆ 37.177937 ┆ 2384622 ┆ 0.026898 ┆ YW051 │ │ overlap ┆ ECT ┆ 1 ┆ 0.071736 ┆ … ┆ 3.457703 ┆ 387378 ┆ 0.289209 ┆ YW051 │ │ overlap ┆ TEa ┆ 1 ┆ 0.071736 ┆ … ┆ 3.860953 ┆ 386396 ┆ 0.259003 ┆ YW051 │ │ rfp ┆ TT ┆ 1 ┆ 0.017203 ┆ … ┆ 1.734078 ┆ 124596 ┆ 0.576675 ┆ YW051 │ └─────────┴────────────┴────────┴───────────┴───┴───────────┴───────────┴─────────────────┴────────┘
- property value_col: str
column name for the value
- property classified_column: Literal['acronym_abbr', 'merge_ac_0', 'merge_ac_1', 'merge_ac_2', 'merge_ac_3', 'merge_ac_4', 'family']
classified column based on the
RoiClassifier
- with_areas(areas)[source]
filter the data with selected area
- Parameters:
areas (Area | list[Area]) – area or list of area
- Returns:
- Return type:
Self
- with_hemisphere(hemi)[source]
filter the data with selected hemisphere
- Parameters:
hemi (Literal['ipsi', 'contra', 'both']) – {‘ipsi’, ‘contra’}
- Returns:
- Return type:
Self
- get_bias_value_dataframe(yunit='percent', to_index=True, verbose=True)[source]
Dataframe with bias value using either
simple subtraction using either percent or n_rois in self.data (bias_value)
index calculation (bias index)
- Parameters:
yunit (str)
to_index – to bias index (1og2 (P_areaA / P_areaB)). refer to Chen et al., 2022. biorxiv. otherwise, do simple subtraction NOTE that index is currently calculate based on channel-normalization value (percent col)
verbose – do print for output
- Returns:
DataFrame
- Return type:
DataFrame
Example:
┌────────────┬────────────┐ │ merge_ac_1 ┆ bias_value*│ │ --- ┆ --- │ │ str ┆ f64 │ ╞════════════╪════════════╡ │ MO ┆ -18.591053 │ │ SS ┆ -5.362179 │ │ … ┆ … │ │ CP ┆ 3.897736 │ │ VIS ┆ 12.899966 │ └────────────┴────────────┘
- to_bokeh(yunit='percent')[source]
to bokeh data ColumnSource input structure
- Parameters:
yunit (str) – {‘percent’, ‘n_rois’}
- Returns:
key: x & counts
value: (area, channel) & neuronal counts or percentage
- Return type:
dict[str, list]
- to_winner_dataframe()[source]
For ternary plot in plotly module
- Returns:
dataframe
- Return type:
DataFrame
┌────────────┬─────────┬──────┬──────┬───────┬────────┐ │ merge_ac_1 ┆ overlap ┆ pRSC ┆ aRSC ┆ total ┆ winner │ │ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │ │ str ┆ i64 ┆ i64 ┆ i64 ┆ i64 ┆ str │ ╞════════════╪═════════╪══════╪══════╪═══════╪════════╡ │ ACA ┆ 1000 ┆ 1048 ┆ 2865 ┆ 4913 ┆ gfp │ │ RSP ┆ 327 ┆ 1086 ┆ 1345 ┆ 2758 ┆ gfp │ │ … ┆ … ┆ … ┆ … ┆ … ┆ … │ │ CB ┆ 0 ┆ 0 ┆ 1 ┆ 1 ┆ gfp │ │ CUN ┆ 0 ┆ 0 ┆ 1 ┆ 1 ┆ gfp │ └────────────┴─────────┴──────┴──────┴───────┴────────┘
- __init__(source_classifier, norm_type, hemisphere, data)
Method generated by attrs for class RoiClassifiedNormTable.
- Parameters:
source_classifier (RoiClassifier)
norm_type (ROIS_NORM_TYPE | None)
hemisphere (HEMISPHERE_TYPE)
data (pl.DataFrame)
- Return type:
None
- neuralib.atlas.ccf.classifier.supply_overlap_dataframe(df, supply_channel_name)[source]
Supply overlap counting in the parsed dataframe.
** Only used if excluding the overlap cell while counting the rfp and gfp channel
- Parameters:
df (DataFrame) – dataframe contain source column with overlap literal in the cell
supply_channel_name (Iterable[str]) – channel names to be supplied from overlap
- Return type:
DataFrame
- neuralib.atlas.ccf.classifier.parse_csv(ccf_dir, fluor_repr, *, plane='coronal', df=None, invert_hemi=False)[source]
Narrow down the info in the ccf roi output
columns abbr, acronym_abbr and hemi are added to the df
- Parameters:
ccf_dir (AbstractCCFDir | None) – if None, directly give
dfargfluor_repr (FluorReprType) –
FluorReprTypeplane (PLANE_TYPE) –
PLANE_TYPE{‘coronal’, ‘sagittal’, ‘transverse’}df (pl.DataFrame | None) – if None, give
ccf_dirarginvert_hemi (bool) – if True, then ML_location >= 0 is ipsilateral site. otherwise, is contralateral site
- Returns:
DataFrame
- Return type:
pl.DataFrame