neuralib.atlas.ccf.dataframe.RoiClassifierDataFrame
- class neuralib.atlas.ccf.dataframe.RoiClassifierDataFrame[source]
Bases:
DataFrameWrapperRoiClassifierDataFrame with each roi (rows)
- Required fields:
acronym- area acronymAP_location: anterior-posterior coordinates (mm)DV_location: dorsal-ventral coordinates (mm)ML_location: medial-lateral coordinates (mm)channel: fluorescence channel (i.e., gfp, rfp, mcherry, …)source: source name (i.e., if circuit tracing, you can give source tracing area…)
- __init__(df, *, cached_dir=None, invalid_post_processing_cache=False)[source]
- Parameters:
df (DataFrame) – DataFrame with required fields
cached_dir (str | Path | PathLike[str] | None) – create cached directory
invalid_post_processing_cache (bool) – invalid post processing cache if cached_dir is not None
Methods
__init__(df, *[, cached_dir, ...])clear([n])See polars.DataFrame.clear.
clone()Clone the wrapper.
dataframe([dataframe, may_inplace])Getter/setter for the internal Polars DataFrame.
drop(*columns[, strict])See polars.DataFrame.drop.
drop_nulls(subset)See polars.DataFrame.drop_nulls.
fill_nan([value])See polars.DataFrame.fill_nan.
fill_null([value, strategy, limit])See polars.DataFrame.fill_null.
filter(*predicates, **constraints)See polars.DataFrame.filter.
filter only
acronymcontain capital lettersfilter_injection_site(area, hemisphere)filter out the injection site labelled
get channel (key): source (value) dict
get_classified_column(field[, strict])classified column name, with the given
group_by(*by[, maintain_order])See polars.DataFrame.group_by.
head([n])See polars.DataFrame.head.
join(other, on[, how, left_on, right_on, ...])See polars.DataFrame.join.
lazy()Wrap dataframe in a lazy wrapper.
limit([n])See polars.DataFrame.limit.
partition_by(by, *more_by[, as_dict])See polars.DataFrame.partition_by.
pipe(function, *args, **kwargs)See polars.DataFrame.pipe.
post_processing(*[, filter_capital, tree, ...])Load the post-processing dataframe
rename(mapping)See polars.DataFrame.rename.
select(*exprs, **named_exprs)See polars.DataFrame.select.
slice(offset[, length])See polars.DataFrame.slice.
sort(by, *more_by[, descending, nulls_last, ...])See polars.DataFrame.sort.
tail([n])See polars.DataFrame.tail.
to_normalized(norm, level, *[, source, ...])To the normalized dataframe (example as volume normalized) .
to_subregion(region, *[, unit, ...])To the subregion dataframe (example as Visual region: VIS) .
with_columns(*exprs, **named_exprs)See polars.DataFrame.with_columns.
with column
family('HB', 'HY', 'TH', 'MB', 'CB', 'CTXpl', 'HPF', 'ISOCORTEX', 'OLF', 'CTXsp')with_hemisphere_column([invert])with column
hemispherewith which hemisphereCopy overlap channels counts to individual channels, only used if overlapped roi is not counted for individual channels
with_row_index([name, offset])See polars.DataFrame.with_row_index.
with customized hierarchical tree structure based on allen brain
Attributes
channel counts dataframe
list of channel names
columnsSee polars.DataFrame.columns.
whether there is overlapped channel
number of channel
number of source
schemaSee polars.DataFrame.schema.
source counts dataframe
list of source names
- __init__(df, *, cached_dir=None, invalid_post_processing_cache=False)[source]
- Parameters:
df (DataFrame) – DataFrame with required fields
cached_dir (str | Path | PathLike[str] | None) – create cached directory
invalid_post_processing_cache (bool) – invalid post processing cache if cached_dir is not None
- dataframe(dataframe=None, may_inplace=True)[source]
Getter/setter for the internal Polars DataFrame.
- Parameters:
dataframe (DataFrame | None) – Optional new dataframe to set.
may_inplace (bool) – If True, update current instance. Otherwise, return new instance.
- Returns:
The current dataframe or a modified wrapper instance.
- Return type:
DataFrame | RoiClassifierDataFrame
- property channels: list[str]
list of channel names
- property n_channels: int
number of channel
- property channel_counts: DataFrame
channel counts dataframe
- property source_counts: DataFrame
source counts dataframe
- property sources: list[str]
list of source names
- property n_sources: int
number of source
- property is_overlapped_channel: bool
whether there is overlapped channel
- get_channel_source_dict()[source]
get channel (key): source (value) dict
- Return type:
dict[str, str]
- get_classified_column(field, strict=True)[source]
classified column name, with the given
- Parameters:
field (int | str | None) – int:
tree_[level]; str:get column; None:acronymstrict (bool) – strict check for the pre-defined classified column
- Return type:
str
- post_processing(*, filter_capital=True, tree=True, family=True, hemisphere=True, copy_overlap=True, filter_injection=None)[source]
Load the post-processing dataframe
- Parameters:
filter_capital (bool) – filter only
acronymcontain capital letterstree (bool) – with customized hierarchical tree structure based on allen brain
family (bool) – with column
family(‘HB’, ‘HY’, ‘TH’, ‘MB’, ‘CB’, ‘CTXpl’, ‘HPF’, ‘ISOCORTEX’, ‘OLF’, ‘CTXsp’hemisphere (bool) – with column
hemispherewith which hemispherecopy_overlap (bool) – Copy overlap channels counts to individual channels, only set true if overlapped roi is not counted for individual channels
filter_injection (tuple[str, str] | None) – filter out the injection site labelled
- Returns:
- Return type:
Self
- filter_injection_site(area, hemisphere)[source]
filter out the injection site labelled
- Parameters:
area (str) – brain area
hemisphere (str) – which hemisphere
- Returns:
- Return type:
Self
- with_tree_columns()[source]
with customized hierarchical tree structure based on allen brain
See also
Wang et al 2020, https://doi.org/10.1016/j.cell.2020.04.007
- Return type:
Self
- with_family_columns()[source]
with column
family(‘HB’, ‘HY’, ‘TH’, ‘MB’, ‘CB’, ‘CTXpl’, ‘HPF’, ‘ISOCORTEX’, ‘OLF’, ‘CTXsp’)- Return type:
Self
- with_hemisphere_column(invert=False)[source]
with column
hemispherewith which hemisphere- Parameters:
invert (bool) – invert hemisphere. Default ML >= 0 (ipsi), ML < 0 (contra)
- Returns:
- Return type:
Self
- with_overlap_copy()[source]
Copy overlap channels counts to individual channels, only used if overlapped roi is not counted for individual channels
- Return type:
Self
- to_normalized(norm, level, *, source=None, top_area=None, rest_as_others=False, hemisphere='both', animal=None, volume_norm_backend='cellatlas')[source]
To the normalized dataframe (example as volume normalized)
┌─────────┬────────┬────────┬───────────┬────────────┬────────────────┬────────────┐ │ source ┆ tree_2 ┆ counts ┆ fraction ┆ hemisphere ┆ Volumes [mm^3] ┆ normalized │ │ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │ │ str ┆ str ┆ u32 ┆ f64 ┆ str ┆ f64 ┆ f64 │ ╞═════════╪════════╪════════╪═══════════╪════════════╪════════════════╪════════════╡ │ overlap ┆ ACA ┆ 1208 ┆ 29.997517 ┆ both ┆ 5.222484 ┆ 231.307537 │ │ pRSC ┆ ACA ┆ 3296 ┆ 22.822324 ┆ both ┆ 5.222484 ┆ 631.117254 │ │ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … │ │ pRSC ┆ VIS ┆ 4035 ┆ 27.939344 ┆ both ┆ 12.957203 ┆ 311.409797 │ │ overlap ┆ VIS ┆ 628 ┆ 15.594736 ┆ both ┆ 12.957203 ┆ 48.46725 │ │ aRSC ┆ VIS ┆ 3865 ┆ 12.627005 ┆ both ┆ 12.957203 ┆ 298.289682 │ └─────────┴────────┴────────┴───────────┴────────────┴────────────────┴────────────┘
- Parameters:
norm (Literal['channel', 'volume', 'cell', 'none']) –
ROIS_NORM_TYPElevel (int | str | None) – tree level for determine which level of classified column
source (str | None) – filter only the given
sourcetop_area (int | None) – filter only the given top areas (sorted based on
fraction)rest_as_others (bool) – vertical concat a region called other with the roi filtered by
top areahemisphere (Literal['ipsi', 'contra', 'both']) – filter only the given
hemisphereanimal (str | None) – with animal id column
animalvolume_norm_backend (Literal['cellatlas', 'brainglobe']) – volume normalization backend. {‘cellatlas’, ‘brainglobe’}
- Returns:
RoiNormalizedDataFrame- Return type:
- to_subregion(region, *, unit='fraction', source_order=None, show_col=None, animal=None, normalize=True)[source]
To the subregion dataframe (example as Visual region: VIS)
┌─────────┬───────────┬───────────┬───────────┬───┬──────────┬──────────┬──────────┬──────────┐ │ source ┆ VISam ┆ VISp ┆ VISpm ┆ … ┆ VISal ┆ VISpor ┆ VISli ┆ VISpl │ │ --- ┆ --- ┆ --- ┆ --- ┆ ┆ --- ┆ --- ┆ --- ┆ --- │ │ str ┆ f64 ┆ f64 ┆ f64 ┆ ┆ f64 ┆ f64 ┆ f64 ┆ f64 │ ╞═════════╪═══════════╪═══════════╪═══════════╪═══╪══════════╪══════════╪══════════╪══════════╡ │ overlap ┆ 39.649682 ┆ 15.127389 ┆ 28.025478 ┆ … ┆ 3.025478 ┆ 2.707006 ┆ 1.592357 ┆ 0.159236 │ │ aRSC ┆ 32.160414 ┆ 28.952135 ┆ 23.05304 ┆ … ┆ 6.080207 ┆ 1.293661 ┆ 2.069858 ┆ 0.07762 │ │ pRSC ┆ 25.947955 ┆ 27.95539 ┆ 27.459727 ┆ … ┆ 3.122677 ┆ 2.973978 ┆ 1.982652 ┆ 1.016109 │ └─────────┴───────────┴───────────┴───────────┴───┴──────────┴──────────┴──────────┴──────────┘
- Parameters:
region (str) – region name
unit (Literal['counts', 'fraction']) – value unit. {‘counts’, ‘fraction’}. default is ‘fraction’
source_order (tuple[str, ...] | None) – source order in dataframe (rows)
show_col (str | None) – force set show col to which level. use case: if a low level area name is classified and show in high level (i.e., TH).
animal (str | None) – with animal column as subregion dataframe
normalize (bool) – do subregion normalization. True: normalize per source within region (each source sums to 100% within this region), False: normalize per source to total input counts (fraction of total input for that source). Default is True
- Returns:
- Return type: