First install and load the relevant packages

Import the packages we need

knitr::opts_chunk$set(echo = TRUE)
library(HiTMapper)
library(ggraph)
library(tidyverse)

Load the example dataset from the HiTMapper package.

When HiTMapper is imported, an example data set is also loaded. Options to load the example data include running any of the following: HiTMapper::toy_data, toy_data, or data("toy_data").

data("toy_data")
head(toy_data)

A data frame containing phenotype definitions is also available in the package. HiTMapper can use it to label clusters. For different datasets/panels, you can provide phenotype definitions in the same format.

defs

The function HiTMapper is a wrapper for all important functionality. The only required parameter is the input cytometry data.

The output of HiTMapper is a list, containing various information about the model.

set.seed(0)
mapper <- HiTMapper(toy_data, total_nodes=200, resolution=0.5, defs=defs)
names(mapper)

For the remainder of this vignette, we will explore some of the list elements in the output. The most important is clustering, an array of cluster membership ids for every cell. You can use the table function from base R to get a quick summary.

table(mapper$clustering)

Another important list element is community_medians, which gives median marker intensity for each community. Internally, HiTMapper uses these community medians and the phenotype definitions to assign labels.

heatmap(mapper$community_medians)

The list element gr contains the graph that HiTMapper constructed, as an igraph object. If you're familiar with the igraph package, you can use the functions therein to operate on gr. You can also use the ggraph package to make various network plots; for example, color the nodes by community assignment. The layout is non-deterministic; try out a couple of random seeds.

set.seed(0)

ggraph(mapper$gr, layout="fr") +
 geom_edge_link(aes(alpha = weight)) +
 geom_node_point(aes(color = mapper$community, size=tabulate(mapper$mapping))) +
 scale_edge_alpha(guide="none") +
 theme_graph(base_family = "sans") +
 theme(text=element_text(size = 18))

Alternatively, use the built-in plot_mapper function, which plots the distribution of chosen markers in the Mapper graph, as well as the community assignment of each node. The path argument can be used to save plots to files; this is recommended when plotting multiple markers.

set.seed(0)
markers <- c("CD3", "CD19", "CD16")
plot_mapper(mapper, markers=markers, path=NULL)


matei-ionita/flowMapper documentation built on Oct. 17, 2023, 9:45 p.m.