plot
group
group(group, selected_regions, *markers, colors=[], orientation='h', check_regions=True)
Scatter plot of AnimalGroup data in the selected brain regions.
Parameters:
-
group:AnimalGroupThe data of a cohort to plot.
-
selected_regions:list[str] | np.ndarray[str]A list of the brain regions picked to plot.
-
*markers:str, default=()The marker(s) to plot the data of. If not specified, it plots all markers in
group. -
colors:Iterable, default=[]The list of colours used to identify each marker.
-
orientation:str, default='h''h' for horizontal scatter plots; 'v' for vertical scatter plots.
-
check_regions:bool, default=TrueIf False, it does not check whether
groupcontains allselected_regions. If data for a region is missing, it will display an empty scatter.
Returns:
Raises:
-
ValueError–If
grouphas data split between left and right hemisphere. -
ValueError–If you didn't specify a colour for one of the markers chosen to display.
-
KeyError–If at least one region in
selected_regionsis missing fromgroup.
pie_ontology
pie_ontology(brain_ontology, selected_regions, use_acronyms=True, hole=0.3, line_width=2, text_size=12)
Pie plot of the major divisions weighted on the number of corresponding selected subregions.
Parameters:
-
brain_ontology:AllenBrainOntologyThe brain region ontology used to gather the major divisions of each brain area.
-
selected_regions:Collection[str]The selected subregions counted by major division.
-
use_acronyms:bool, default=TrueIf True, it displays brain region names as acronyms. If False, it uses their full name.
-
hole:float, default=0.3The size of the hole in the pie chart. Must be between 0 and 1.
-
line_width:float, default=2The thickness of pie's slices.
-
text_size:float, default=12The size of the brain region names.
Returns:
above_threshold
above_threshold(brains, threshold, regions, width=700, height=500)
Scatter plot of the regions above a threshold. Usually used together with SliceMetrics.CVAR.
Parameters:
-
brains:Experiment | AnimalGroup | Sequence[AnimalBrain]The brains from where to get the data.
-
threshold:floatThe threshold above which a brain region is displayed.
-
regions:Sequence[str]The names of the brain regions to filter from.
-
width:int, default=700The width of the plot.
-
height:int, default=500The height of the plot.
Returns:
slice_density
slice_density(brains, regions, width=700, height=500)
Scatter plot of the sections' density.
Parameters:
-
brains:SlicedExperiment | SlicedGroup | Sequence[SlicedBrain]The brains from where to get the data.
-
regions:CollectionThe regions to plot. If the data of
brainsis split between left and right hemisphere, you can pass, for example, both "Left: Isocortex" and "Right: Isocortex". -
width:int, default=700The width of the plot.
-
height:int, default=500The height of the plot.
Returns:
region_scores
region_scores(scores, brain_ontology, title=None, title_size=20, regions_size=15, use_acronyms=True, use_acronyms_in_mjd=True, mjd_opacity=0.5, thresholds=None, width=800, barheight=30, bargap=0.3, bargroupgap=0.0)
Bar plot of the given regions' scores, visually grouped by the major divisions of the given brain_ontology.
Parameters:
-
scores:pd.SeriesA series of scores for each brain region, where each brain region is represented by its acronym and it is the index of the scores.
-
brain_ontology:AllenBrainOntologyThe brain region ontology used to gather the major divisions of each brain area.
-
title:str, default=NoneThe title of the plot.
-
title_size:int, default=20The size of the title.
-
regions_size:int, default=15The size of each brain region name.
-
use_acronyms:bool, default=TrueIf True, it uses the acronym of the brain regions instead of their full name.
-
use_acronyms_in_mjd:bool, default=TrueIf True, it uses the acronym of the major divisions instead of their full name.
-
mjd_opacity:float, default=0.5The amount of opacity used for the background of bar plot, delimiting each major division.
-
thresholds:float | Collection[float], default=NoneIf specified, it plots a vertical dotted line at the given value.
-
width:int, default=800The width of the plot.
Returns:
-
–
A Plotly figure.
heatmap
heatmap(bd1, brain_regions, bd2=None, orientation='frontal', depth=None, n=10, highlighted_regions=None, cmin=None, cmax=None, cmap='magma_r', centered_cmap=False, ccenter=0, show_acronyms=False, title=None, ticks=None, ticks_labels=None, atlas_name='allen_mouse_25um', output_path=None, filename=None)
Plots the heatmaps of the given BrainData onto a 2D representation of the brain
delimited by the desired regions.
Parameters:
-
bd1:BrainDataThe brain data to plot.
-
brain_regions:list[str]The brain regions to be displayed in the 2D.
-
bd2:BrainData, default=NoneIf specified, it splits the heatmap in two hemispheres and plots
bd1on the left hemishpere, andbd2on the right hemisphere. -
orientation:str, default='frontal'The orientation at which the 3D brain is cut into 2D sections. It can be either "frontal", "sagittal" or "horizontal".
-
depth:int | Sequence[int], default=NoneThe depth, in µm along the
orientation, at which to cut the brain and produce the corresponding heatmap. If a sequence of depths is given, it produces multiple heatmaps. -
n:int, default=10If
depthis not specified, it defines the number of equidistant heatmaps to plot by sectioning the brain alongorientation. -
highlighted_regions:Sequence[str] | tuple[Sequence[str]], default=NoneIf specified, it draws a thicker outlines on the regions correspoding to the given acronyms. If
bd2is also specified, it can also be a tuple of two lists, one for each hemisphere. -
cmin:float, default=NoneThe lowerbound value for the heatmap.
-
cmax:float, default=NoneThe upperbound value for the heatmap.
-
cmap:str | mpl.colors.Colormap, default='magma_r'The colormap used for the heatmap.
-
centered_cmap:bool, default=FalseIf True, it uses a linear colormap that spans from red to blue, with white being the neutral/middle color.
-
ccenter:float, default=0If
centered_cmap=True, it sets the white color to the specified value, even if the distance fromccenterofcminandcmaxdiffers. -
show_acronyms:bool, default=FalseIf True, it overlays the acronym over each brain region in the heatmap.
-
title:str, default=NoneThe title of the figure.
-
ticks:Sequence[float], default=NoneIf specified, it adds additional ticks to the colormap in the legend of the figure.
This option may be useful to show to which values specific colors correspond to. -
ticks_labels:Sequence[str], default=NoneIf specified, it set a name to the corresponding
ticks. -
atlas_name:str, default='allen_mouse_25um'The name used by BrainGlobe to identify the atlas to plot
-
output_path:Path | str, default=NoneIf specified, it saves all the resulting heatmaps in the given location. It no folder exists at the given location, it creates it.
-
filename:str, default=NoneThe name used as prefix for each heatmap SVG file saved into
output_path.
Returns:
hierarchy
hierarchy(brain_ontology, bdata=None)
draw_edges
draw_edges(G, layout, width)
draw_nodes
draw_nodes(G, layout, brain_ontology, node_size, fill_mode='region', outline_size=0.5, outline_mode='region', centrality_metric=None, metrics={'degree': ig.VertexSeq.degree})
Draws a plotly Scatter plot of the given graph G, based on the given layout.
Parameters:
-
G:ig.GraphA graph
-
layout:ig.LayoutThe layout used to position the nodes of the graph
G -
brain_ontology:braian.AllenBrainOntologyThe atlas ontology associated with
G. It is used to retrieve information about brain regions. -
node_size:intThe size of the region nodes
-
fill_mode:str, default='region'The mode chosen to color each region node. Accepted values are:
"region","centrality"or"cluster". -
outline_size:float, default=0.5The size of the region nodes' outlines
-
outline_mode:str, default='region'The mode chosen to color each region node outline. Accepted values are:
"region","centrality"or"cluster". If"region", it colors based onbrain_ontology. If"centrality", it colors based on the attribute defined incentrality_metricofGvertices. If"cluster", it colors based onclusterattribute onGvertices. -
centrality_metric:str, default=NoneThe name of the attribute used if
fill_modeoroutline_modeare set to"centrality". -
metrics:dict[str, Callable[[ig.VertexSeq], Iterable[float]]], default={'degree': ig.VertexSeq.degree}A dictionary that defines M additional information for the vertices of graph
G. The keys are title of an additional metric, while the values are functions that take aigraph.VertexSeqand spits a value for each vertex.
Returns:
Raises:
-
ValueError–If
fill_modeoroutline_modeare set to"centrality", butGvertices have no attributes named"cluster". -
ValueError–If
fill_modeoroutline_modeare set to"centrality", butGvertices have no attributes named as defined bycentrality_metric.
permutation
permutation(pls, component=1)
Plots the result of PLS.random_permutation().
It shows how much the product of the given partial least square analysis is a result of pure chance.
Parameters:
-
pls:bas.PLSAn instance of a mean-centered task partial least square analysis.
-
component:int, default=1The component of the PLS for which to plot the permutation.
Returns:
See also
groups_salience
groups_salience(pls, component=1)
latent_variable
latent_variable(pls, of='X', width=800, height=800)
PCA-like plot of brain scores or group scores of a PLS. This might help see how animals or groups are discernable from each other.
It always plots the first component on the x-axis and the second component on the y-axis.
Parameters:
-
pls:bas.PLSAn instance of a mean-centered task partial least square analysis.
-
of:str, default='X'If "X", it plots the brain scores. If "Y", it plots the group scores.
-
width:int, default=800The width of the plot.
-
height:int, default=800The height of the plot.
Returns:
xmas_tree
xmas_tree(groups, selected_regions, marker1, marker2=None, brain_ontology=None, pls_n_permutation=None, pls_n_bootstrap=None, pls_threshold=None, pls_seed=None, markers_salience_scores=None, plot_scatter=True, scatter_width=0.7, space_between_markers=0.02, groups_marker1_colours=['LightCoral', 'SandyBrown'], groups_marker2_colours=['IndianRed', 'Orange'], max_value=None, color_heatmap='deep_r', width=None, height=None)
Plots the XMasTree of the given data. This is a visualisation of whole-brain data from multiple groups in a way that is comprehensive and complete.
The data is divided in two main plots: a heatmap (the trunk) and a scatter plot (the leaves and the xmas baubles). Both are aligned on the y-axis so that each row represents the data of a brain region across animals, groups and markers.
If pls_n_permutation and pls_n_bootstrap—or, alternatively, markers_salience_scores—are specified, it dims out the
brain regions that are not salient in a partial least squared analysis between the given groups.
it is only supported when there are only two groups.
Parameters:
-
groups:Experiment | Collection[AnimalGroup]The groups to display in the plot.
-
selected_regions:Collection[str]The acronyms of the brain regions shown in the plot.
Ifbrain_ontologyis not given, selecting any missing region from thegroupsdata will result in an error. -
marker1:strThe name of the marker's data to plot.
-
marker2:str, default=NoneIf specified, the name of the second marker's data to plot.
-
brain_ontology:AllenBrainOntology, default=NoneIf specified, the
selected_regionsare checked against the ontology and sorted by major divisions. If a brain region is missing fromgroupsbut present inselected_regions, it is shown with all-NA values. -
pls_n_permutation:int, default=NoneIf specified, it corresponds to the parameter used for defining how generizable the salience scores are.
-
pls_n_bootstrap:int, default=NoneIf specified, it corresponds to the parameter used for finding the stable regions.
-
pls_threshold:float, default=NoneThe threshold used on the salience scores to define which regions are salient and which ones are not.
If not specified, it applies a threshold of \(~1.96\). -
pls_seed:int, default=NoneThe random seed used for PLS's permutation and bootstrap operations. If specified, the salient regions are always deterministic.
-
markers_salience_scores:dict[str, BrainData], default=NoneThe salience scores computed on
marker1and, eventually,marker2.
If specified, it does not usepls_n_permutationandpls_bootstrapparmeters and select the brain regions to dim out based on this dictonary. -
plot_scatter:bool, default=TrueIf False, it does not plot the scatter plot of the brain regions' values for each animal. It only plots the mean of the whole group.
-
scatter_width:float, default=0.7The ratio of the whole plot's width dedicated to the scatter plot. The remaining 1-scatter_width is occupied by the heatmap.
-
space_between_markers:float, default=0.02The retio of the whole plot's width dedicated to the gap between markers and used to specify the major divisions.
Ifmarker2andbrain_ontologyare not specified, it is not used. -
groups_marker1_colours:Sequence, default=['LightCoral', 'SandyBrown']The list of colours used to identify
marker1scatter data of each group. -
groups_marker2_colours:Sequence, default=['IndianRed', 'Orange']The list of colours used to identify
marker2scatter data of each group. -
max_value:int, default=NoneIf specified, it caps the visualization of the brain data to this value.
-
color_heatmap:str, default='deep_r'The colormap used to display the data in the heatmap.
-
width:int, default=NoneThe width of the plot.
-
height:int, default=NoneThe height of the plot.
Returns: