ark.utils.metacluster_remap_gui

ark.utils.metacluster_remap_gui.colormap_helper

ark.utils.metacluster_remap_gui.colormap_helper.distinct_cmap(n=33)[source]

Return a List of n visually distinct colors as a matplotlib ListedColorMap

The sequence of color is deterministic for any n, and increasing n does not change the lower index colors.

Parameters:

n (int) – The number of RGB tuples to return.

Returns:

N distinct colors as a matplotlib ListedColorMap

Return type:

matplotlib.colors.ListedColormap

ark.utils.metacluster_remap_gui.colormap_helper.distinct_rgbs(n=33)[source]

Return a List of n visually distinct colors as RGB tuples.

The sequence of color is deterministic for any n, and increasing n does not change the lower index colors.

Parameters:

n (int) – The number of RGB tuples to return.

Returns:

List of the distinct colors as RGB tuples.

Return type:

List[Tuple[int,int,int]]

ark.utils.metacluster_remap_gui.colormap_helper.generate_meta_cluster_colormap_dict(meta_cluster_remap_path, cmap, cluster_type='pixel')[source]

Returns a compact version of the colormap used in the interactive reclustering processes.

Generate a separate one for the raw meta cluster labels and the renamed meta cluster labels.

Used in the pixel and cell meta cluster overlays, as well as the average weighted channel expression heatmaps for cell clustering

Parameters:
  • meta_cluster_remap_path (str) – Path to the file storing the mapping from SOM to meta clusters (raw and renamed)

  • cmap (matplotlib.colors.ListedColormap) – The colormap generated by the interactive reclustering process

  • cluster_type (str) – The type of clustering being done

Returns:

  • A dict containing the raw meta cluster labels mapped to their respective colors

  • A dict containing the renamed meta cluster labels mapped to their respective colors

Return type:

tuple

ark.utils.metacluster_remap_gui.file_reader

ark.utils.metacluster_remap_gui.file_reader.metaclusterdata_from_files(cluster_path, cluster_type='pixel', prefix_trim=None)[source]

Read and validate raw CSVs and return an initialized MetaClusterData

Parameters:
  • cluster_path (str or IO) – file path or filelike object

  • cluster_type (str) – the type of cluster data to read, needs to be either 'pixel' or 'cell'

  • prefix_trim (str) – If set, remove this prefix from each column of the data in cluster_path

Returns:

fully initialized metacluster data

Return type:

MetaClusterData

ark.utils.metacluster_remap_gui.metaclusterdata

class ark.utils.metacluster_remap_gui.metaclusterdata.MetaClusterData(cluster_type, raw_clusters_df, raw_pixelcounts_df)[source]

Bases: object

Store the state of the clusters and metaclusters

Parameters:
  • cluster_type (str) – the type of clustering being done

  • raw_clusters_df (pd.Dataframe) – validated and initialized clusters dataframe.

  • raw_pixelcounts_df (pd.Dataframe) – validated and initialized pixelcounts dataframe.

change_displayname(metacluster, displayname)[source]
property cluster_count
cluster_in_metacluster(metacluster)[source]
property clusters
property clusters_with_metaclusters
property fixed_width_marker_names
get_metacluster_displayname(metacluster)[source]
property linkage_matrix
property marker_count
property marker_names
property metacluster_count
property metacluster_displaynames
property metaclusters
new_metacluster()[source]
property output_mapping_filename
remap(cluster, metacluster)[source]
save_output_mapping()[source]
set_marker_order(new_indexes)[source]
which_metacluster(cluster)[source]

ark.utils.metacluster_remap_gui.metaclustergui

class ark.utils.metacluster_remap_gui.metaclustergui.MetaClusterGui(metaclusterdata, heatmapcolors=seaborn.diverging_palette, width=17.0, debug=False, enable_throttle=True)[source]

Bases: object

Coordinate and present the metacluster Graphical User Interface

mcd

State of the actual clusters at any point in time

Type:

MetaClusterData)

selected_clusters

Currently selected clusters

Type:

set[int]

Parameters:
  • data (MetaClusterData)) – An initialized MetaClusterData instance

  • heatmapcolors (matplotlib.colors.ColorMap)) – If you wish to change the default heatmap colors

  • width (float) – Adjust the actual width to accomodate monitor size, resolution, zoom, etc

  • debug (bool) – Enable debug mode for the GUI. This enables a special logging window where output from callbacks can be printed.

  • enable_throttle (bool) – Control whether or not to throttle GUI callbacks. Disabling might be helpful for debugging certain race conditions.

clear_selection(e)
enable_debug_mode()[source]

Display the debug output widget as part of the GUI

This is used to route logging, output, and tracebacks that happen in any of the event handler callbacks.

make_gui()[source]

Create and configure all of the plots which make up the GUI

Below is a map of the physical subplot layout of the Axes within the Figure.

The abbreviation is used both for the axes

e.g. self.ax_c

as well as the plotted items.

e.g. self.im_c, self.rects_cp

Map of matplotlib Figure:

|   |    Cluster     | Meta |
----------------------------
|   |    cp          |  cb  | counts of pixels, color bar
| cd|    c           |  m   | heatmap itself
|   |    cs          |  ms  | selection markers
|   |    cl          |  ml  | metacluster color labels
make_widgets()[source]

Create the physical ipywidgets that display below the GUI plot.

move_dendro_labels(ax, dendrosplit_ratio=1.8)[source]

Overlay axis labels directly onto a scipy dendrogram

Final image will use the ratio 1:dendrosplit_ratio for tree_region:labels_region

Parameters:
  • ax (matplotlib.axes.Axes) – The axis containing the existing scipy dendrogram

  • dendrosplit_ratio (float) – How big to make the the labels compared to the tree

new_metacluster(e)
onpick(e)
onpick_remap(e)[source]
onpick_select(e)[source]

Handle or route for handling all clicks to any matplotlib plots.

remap_current_selection(metacluster)[source]

Instruct the MetaClusterData to remap the selected clusters

All selected clusters will be remapped to the metacluster id which is passed

Parameters:

metacluster (int) – metacluster id to map the current selection to

select_metacluster(metacluster)[source]
property selection_mask

2D boolean mask of shape (1,cluster_count) of currently selected clusters

update_current_metacluster(metacluster)
update_current_metacluster_displayname(t)
update_current_metacluster_handler(t)[source]
update_gui()[source]

Update and redraw any updated GUI elements

update_zscore(e)

ark.utils.metacluster_remap_gui.throttle

ark.utils.metacluster_remap_gui.throttle.throttle(wait)[source]

Second order decorator for rate-limiting a function within an asyncio concurrent app

  • The first call will always happen without delay.

  • Subsequent calls, within wait seconds, are dropped, even if argurments differ.

  • The final call will always execute, sometimes with a delay. This guarentees that that final value passed to will be applied.

Example usage:

@throttle(.5)
def update_a_gui_element(e):
    do_stuff(e.name)
    but_not_too_often()
Parameters:

wait (float) – minimum time between subsequent calls, in seconds

Returns:

Decorator for throttling by wait seconds

Return type:

function

ark.utils.metacluster_remap_gui.zscore_norm

class ark.utils.metacluster_remap_gui.zscore_norm.ZScoreNormalize(*args: Any, **kwargs: Any)[source]

Bases: Normalize

Normalizer tailored for zscore heatmaps

Map each value of an incoming vector each between 0 and 1, which is the interval for cmaps.

The mapping consists of two separate linearly interpolated intervals:

[vmin,vcenter] -> [0.0,0.5] [vcenter,vmax] -> [0.5,1.0]

__init__(vmin=-3, vcenter=0, vmax=3)[source]

Initial ZScoreNormalize

vmin < vcenter < vmax

Parameters:
  • vmin (float) – Value to map to 0 in the colormap

  • vcenter (float) – Value to map to .5 in the colormap

  • vmax (float) – Value to map to 1 in the colormap

calibrate(values)[source]
inverse(value)[source]