Map to external data

connectome_interpreter.external_map.hex_heatmap(df: Series | DataFrame, style: dict | None = None, sizing: dict | None = None, dpi: int = 72, custom_colorscale: list | None = None, global_min: float | None = None, global_max: float | None = None, dataset: str | None = 'mcns_right') Figure[source]

Generate a hexagonal heat map plot of the data. The index of the data should be formatted as strings of the form ‘-12,34’, where the first number is the x-coordinate and the second number is the y-coordinate.

Parameters:
  • df – pd.Series | pd.DataFrame The data to plot. Each column will generate a separate frame in the plot.

  • style

    dict, default=None Dict containing styling formatting variables. Possible keys are:

    • ’font_type’: str, default=’arial’

    • ’linecolor’: str, default=’black’

    • ’papercolor’: str, default=’rgba(255,255,255,255)’ (white)

  • sizing

    dict, default=None Dict containing size formatting variables. Possible keys are:

    • ’fig_width’: int, default=260 (mm)

    • ’fig_height’: int, default=220 (mm)

    • ’fig_margin’: int, default=0 (mm)

    • ’fsize_ticks_pt’: int, default=20 (points)

    • ’fsize_title_pt’: int, default=20 (points)

    • ’markersize’: int, default=18 if dataset=’mcns_right’, 20 if dataset=’fafb_right’

    • ’ticklen’: int, default=15

    • ’tickwidth’: int, default=5

    • ’axislinewidth’: int, default=3

    • ’markerlinewidth’: int, default=0.9

    • ’cbar_thickness’: int, default=20

    • ’cbar_len’: float, default=0.75

  • dpi – int, default=72 Dots per inch for the output figure. Standard is 72 for screen/SVG/PDF. Use higher values (e.g., 300) for print-quality output.

  • custom_colorscale – list, default=None Custom colorscale for the heatmap. If None, defaults to white-to-blue colorscale [[0, “rgb(255, 255, 255)”], [1, “rgb(0, 20, 200)”]].

  • global_min – float, default=None Global minimum value for the color scale. If None, the minimum value of the data is used but if that is negative, use 0.

  • global_max – float, default=None Global maximum value for the color scale. If None, the maximum value of the data is used.

  • dataset

    str, default=’mcns_right’ The dataset to use for the hexagon locations. Options are:

    • ’mcns_right’: columnar coordinates of individual cells from columnar cell types: L1, L2, L3, L5, Mi1, Mi4, Mi9, C2, C3, Tm1, Tm2, Tm4, Tm9, Tm20, T1, within the medulla of the right optic lobe, from Nern et al. 2024.

    • ’fafb_right’: columnar coordinates of individual cells from columnar cell types, in the right optic lobe of FAFB, from Matsliah et al. 2024.

Returns:

go.Figure

Return type:

fig

connectome_interpreter.external_map.load_dataset(dataset: str) DataFrame[source]

Load the dataset from the package data folder. These datasets have been preprocessed to work with connectomics data. The preprocessing scripts are in this repository: https://github.com/YijieYin/interpret_connectome.

Parameters:

dataset

(str) The name of the dataset to load. Options are:

  • ’DoOR_adult’: mapping from glomeruli to chemicals, from Munch and Galizia DoOR dataset (https://www.nature.com/articles/srep21841).

  • ’DoOR_adult_sfr_subtracted’: mapping from glomeruli to chemicals, with spontaneous firing rate subtracted. There are therefore negative values.

  • ’Dweck_adult_chem’: mapping from glomeruli to chemicals extracted from fruits, from Dweck et al. 2018 (https://www.cell.com/cell-reports/abstract/S2211-1247(18)30663-6). Firing rates normalised to between 0 and 1.

  • ’Dweck_adult_fruit’: mapping from glomeruli to fruits, from Dweck et al. 2018. Number of responses normalised to between 0 and 1.

  • ’Dweck_larva_chem’: mapping from olfactory receptors to chemicals, from Dweck et al. 2018. Firing rates normalised to between 0 and 1.

  • ’Dweck_larva_fruit’: mapping from olfactory receptors to fruits from Dweck et al. 2018. Number of responses normalised to between 0 and 1.

  • ’Nern2024’: columnar coordinates of individual cells from a collection of columnar cell types within the medulla of the right optic lobe, from Nern et al. 2024 (https://www.biorxiv.org/content/10.1101/2024.04.16.589741v2).

  • ’Matsliah2024’: columnar coordinates of individual cells from a collection of columnar cell types in the right optic lobe from FAFB, from Matsliah et al. 2024 (https://www.nature.com/articles/s41586-024-07981-1).

  • ’Badel2016_PN’: mapping from olfactory projection neurons to odours, from Badel et al. 2016 (https://www.cell.com/neuron/fulltext/S0896-6273(16)30201-X).

  • ’Zhao2024’: mapping from hexagonal coordinates to 3D coordinates, update from Zhao et al. 2022 (https://www.biorxiv.org/content/10.1101/2022.12.14.520178v1).

Returns:

The dataset as a pandas DataFrame. For the adult, the glomeruli are in the rows. For the larva, receptors are in the rows.

Return type:

pd.DataFrame

connectome_interpreter.external_map.looming_stimulus(start_coords, all_coords, n_time=4)[source]

Generate a list of lists of coordinates for a looming stimulus. The stimulus starts at the start_coords and expands outwards in a hexagonal pattern. The stimulus expands for n_time steps. Currently the expansion happens one layer at a time.

Parameters:
  • start_coords (list) – List of strings of the form ‘x,y’ where x and y are the coordinates of the starting hexes for the stimulus.

  • all_coords (list) – List of strings of the form ‘x,y’ where x and y are the coordinates of all hexes in the grid.

  • n_time (int) – Default=4. Number of time steps for the stimulus to expand.

Returns:

List of lists of strings of the form ‘x,y’ where x and y are the coordinates of the hexes that are stimulated at each time step.

Return type:

stim_str (list)

connectome_interpreter.external_map.make_sine_stim(phase=0, amplitude=1, n=8)[source]

Generate a dictionary of values representing a sine wave stimulus with a given phase and amplitude. The sine wave is defined over n points, starting from the given phase.

Parameters:
  • phase (int) – Phase of the sine wave in degrees. Default is 0.

  • amplitude (float) – Amplitude of the sine wave. Default is 1.

  • n (int) – Number of points in the sine wave. Default is 8.

Returns:

A dictionary where keys are indices from 1 to n, and values are the corresponding sine wave values.

Return type:

dict

connectome_interpreter.external_map.map_to_experiment(df, dataset=None, custom_experiment=None)[source]

Map the connectomics data to experimental data. For example, if odour1 excites neuron1 0.5, and neuron2 0.6; both neuron1 and neuron2 output to neuron3 (0.7 and 0.8 respectively), then the output of neuron3 to odour1 is 0.5*0.7 + 0.6*0.8 = 0.83. The result would only be 1 if a stimulus excites neurons 100%, and those neurons constitue 100% of the downstream neuron’s input.

Parameters:
  • df (pd.DataFrame) – The connectivity data. Standardised input (e.g. glomeruli, receptors) in rows, observations (target neurons) in columns.

  • dataset (str) –

    The name of the dataset to load. Options are:

    • ’DoOR_adult’: mapping from glomeruli to chemicals, from Munch and Galizia DoOR dataset (https://www.nature.com/articles/srep21841).

    • ’DoOR_adult_sfr_subtracted’: mapping from glomeruli to chemicals, with spontaneous firing rate subtracted. There are therefore negative values.

    • ’Dweck_adult_chem’: mapping from glomeruli to chemicals extracted from fruits, from Dweck et al. 2018 (https://www.cell.com/cell-reports/abstract/S2211-1247(18)30663-6). Firing rates normalised to between 0 and 1.

    • ’Dweck_adult_fruit’: mapping from glomeruli to fruits, from Dweck et al. 2018. Number of responses normalised to between 0 and 1.

    • ’Dweck_larva_chem’: mapping from olfactory receptors to chemicals, from Dweck et al. 2018. Firing rates normalised to between 0 and 1.

    • ’Dweck_larva_fruit’: mapping from olfactory receptors to fruits, from Dweck et al. 2018. Number of responses normalised to between 0 and 1.

    • ’Nern2024’: columnar coordinates of individual cells from a collection of columnar cell types within the medulla of the right optic lobe, from Nern et al. 2024.

    • ’Badel2016_PN’: mapping from olfactory projection neurons to odours, from Badel et al. 2016 (https://www.cell.com/neuron/fulltext/S0896-6273(16)30201-X).

  • custom_experiment (pd.DataFrame) – A custom experimental dataset to compare the connectomics data to. The row indices of this dataframe must match the row indices of df. They are the units of comparison (e.g. glomeruli).

Returns:

The similarity between the connectomics data and the experimental data. Rows are neurons, columns are external stimulus.

Return type:

pd.DataFrame

connectome_interpreter.external_map.plot_mollweide_projection(data: Series | DataFrame, fig_size: tuple = (900, 700), custom_colorscale: str = 'Viridis', global_min: float | None = None, global_max: float | None = None, dataset: str = 'Zhao2024', marker_size: int = 8) Figure[source]

Generates a heatmap to visualize the value of column features per column using the mollweide projection.

Parameters:
  • data (pd.Series | pd.DataFrame) – Data with index formatted as strings of the form ‘-12,34’, where the first number is the x-coordinate and the second number is the y-coordinate. The data to plot. Each column will generate a separate frame in the plot.

  • fig_size (tuple) – Size of the figure in pixels (width, height).

  • custom_colorscale (str) – Name of the Plotly colorscale to use.

  • global_min (float | None) – Global minimum value for the color scale. If this minumum is >0, 0 is used.

  • global_max (float | None) – Global maximum value for the color scale. If None, the maximum value of the data is used.

  • dataset (str) –

    The dataset to use for the hexagon locations. Options are:

  • marker_size (int) – Size of markers in the plot.

Returns:

A Plotly figure object containing the mollweide projection heatmap.

Return type:

go.Figure