Inspect the Membership of Features Across ClustoCell Results
Source:R/featureInspect.R
featureInspect.RdfeatureInspect() searches one or more features across all marker
collections contained within a ClustoCell object, including global
feature collections, cross-cluster markers, major cluster-specific markers,
and sub-cluster-specific markers. All matches are returned in a single
long-format data frame containing the feature level, membership, marker
type, Gini score, purity, and rank. Optionally, a publication-quality
ggplot2 visualisation summarising feature memberships can also be
generated.
Usage
featureInspect(
clustoCell,
features,
level = NULL,
type = NULL,
sort_by = c("input", "rank", "gini"),
plot = FALSE,
title = NULL,
subtitle = NULL,
tag = NULL,
nrow_panels = NULL,
dotsize = 3,
show_purity = TRUE,
class_palette = NULL,
color_low = "steelblue",
color_high = "firebrick",
panel_border_color = "black",
panel_border_size = 0.5,
axis_text_size = 8,
axis_title_size = 9,
plot_margin_right = 10,
xlab = "Rank",
ylab = "Feature",
show_legend = TRUE,
legend_position = "right",
legend_box = "vertical",
legend_box_just = "left"
)Arguments
- clustoCell
An object of class
ClustoCellobtained usingclustoCellormarkoClust.- features
A character vector of feature names (e.g. gene symbols) to inspect across the
ClustoCellobject.- level
Character vector specifying which hierarchical level(s) to include in the output. One or more of
"Global","Cross-cluster","Major cluster", and"Sub-cluster". IfNULL(default), results from all levels are returned. If none of the queried features are found at the specified level(s), a zero-rowdata.frameis returned (with a warning) rather than an error.- type
Character vector specifying which marker type(s) to include in the output. One or more of
"Positive","Negative","Medium","Pure Ranked","Pure High","Pure Medium", and"Pure". IfNULL(default), results of all types are returned. The value"Pure"is a convenience shorthand that expands to"Pure Ranked","Pure High", and"Pure Medium"simultaneously, including all global feature categories. Individual pure types (e.g."Pure High") can also be specified directly. Thelevelandtypefilters are applied independently; if their combination yields no matching rows, a zero-rowdata.frameis returned (with a warning) rather than an error.- sort_by
Character string specifying how to order the rows of the output table. One of:
"input"(Default) Rows follow the order of
featuresas supplied by the user, then by level (Global \(\rightarrow\) Cross-cluster \(\rightarrow\) Major cluster \(\rightarrow\) Sub-cluster)."rank"Ascending
Rank(rows withNArank appear last), then by input order within ties."gini"Descending
Gini_Score(rows withNAGini score appear last), then by input order within ties.
- plot
Logical. If
FALSE(default), adata.frameis returned. IfTRUE, a named list with elements$tableand$plotis returned.- title
Character. Plot title. Ignored when
plot = FALSE.- subtitle
Character. Plot subtitle. Ignored when
plot = FALSE.- tag
Character. Plot tag (e.g. panel label). Ignored when
plot = FALSE.- nrow_panels
Integer. Number of rows used when faceting the plot by
Membership. IfNULL(default), the number of rows is determined automatically byfacet_wrap. Ignored whenplot = FALSE.- dotsize
Numeric. Controls the size range of the dots in the plot. The actual
sizeaesthetic is scaled betweendotsize * 0.4anddotsize * 1.8. Default is3. Ignored whenplot = FALSE.- show_purity
Logical. If
TRUE(default), dot colour encodesPurityvia a continuous gradient. IfFALSE, dot colour encodesTypeas a discrete scale. Ignored whenplot = FALSE.- class_palette
Optional. Only used when
show_purity = FALSE. Specifies the colour scale forType. Can be one of:A ggplot2 scale object (e.g.
ggplot2::scale_colour_brewer()).A named or unnamed character vector of colours (e.g.
c("red", "blue", "green")), which is passed toscale_colour_manual.NULL(default): the default ggplot2 discrete colour scale is used.
Ignored when
plot = FALSE.- color_low
Character. The low-end colour of the continuous Purity gradient. Default is
"steelblue". Ignored whenshow_purity = FALSEorplot = FALSE.- color_high
Character. The high-end colour of the continuous Purity gradient. Default is
"firebrick". Ignored whenshow_purity = FALSEorplot = FALSE.- panel_border_color
Character. Colour of the panel border. Default is
"black". Ignored whenplot = FALSE.- panel_border_size
Numeric. Line width of the panel border. Default is
0.5. Ignored whenplot = FALSE.- axis_text_size
Numeric. Font size (in points) for axis tick labels. Default is
8. Ignored whenplot = FALSE.- axis_title_size
Numeric. Font size (in points) for axis titles. Default is
9. Ignored whenplot = FALSE.- plot_margin_right
Numeric. Right margin of the plot in points. Default is
10. Ignored whenplot = FALSE.- xlab
Character. Label for the x-axis. Default is
"Rank". Ignored whenplot = FALSE.- ylab
Character. Label for the y-axis. Default is
"Feature". Ignored whenplot = FALSE.- show_legend
Logical. Whether to display the plot legend. Default is
TRUE. Ignored whenplot = FALSE.- legend_position
Character. Position of the legend. One of
"right"(default),"left","top","bottom", or"none". Ignored whenplot = FALSE.- legend_box
Character. Arrangement of multiple legend keys. One of
"vertical"(default) or"horizontal". Ignored whenplot = FALSE.- legend_box_just
Character. Justification of legend boxes. Default is
"left". Ignored whenplot = FALSE.
Value
- If
plot = FALSE A
data.framewith one row for each occurrence of each queried feature across all (or the selected) marker collections. Columns are:FeatureFeature name (character).
LevelHierarchical level at which the feature was found:
"Global","Cross-cluster","Major cluster", or"Sub-cluster"(character).MembershipThe specific collection in which the feature was found, e.g.
"Global Features","Cross-cluster Marker","C1", or"C1-Sub1"(character).TypeMarker type:
"Pure High","Pure Medium","Pure Ranked","Positive","Negative", or"Medium"(character).Gini_ScoreGini score of the feature within the collection (numeric).
NAfor global features.PurityPurity of the feature within the collection (numeric).
NAfor global and cross-cluster features.RankRank of the feature within its specific collection (integer).
NAfor global features. See Details.
If no queried feature is found in any collection (or in the specified level(s)), a zero-row
data.framewith the above columns is returned.- If
plot = TRUE A named list with two elements:
$tableThe results
data.framedescribed above.$plotA
ggplotobject visualising the identified feature memberships as a dot plot faceted byMembership. Dot position (x-axis) encodesRank, dot size encodes the invertedGini_Score(larger = purer), dot shape encodesType, and dot colour encodesPurity(orTypewhenshow_purity = FALSE). Features without a Gini score are shown as large semi-transparent grey dots. See Details.
Details
Rank interpretation. The Rank column reflects the rank of
the feature within its specific collection (i.e. within the
combination of Level, Membership, and Type), as
assigned by clustoCell or markoClust. It does
not represent the row position in the output table returned by
featureInspect(). A feature ranked 1st in cluster C1 positive
markers and 5th in sub-cluster C1-Sub1 medium markers will appear in two
separate rows with Rank values of 1 and 5, respectively.
Dot size in the plot. When plot = TRUE, dot size encodes
the inverted Gini score: a lower Gini score indicates a purer
marker and is represented by a larger dot. The size legend labels
display the original Gini score values for interpretability. Features
without a Gini score (i.e. global features stored in
globally_pure_ranked, globally_pure_high, or
globally_pure_medium) are rendered as large, semi-transparent grey
dots with a heavier border stroke to signal that their size carries no
quantitative meaning. These features are also plotted at \(x = 0\)
because no rank is assigned to them; the 0 tick label is suppressed
in panels that contain only unranked features to avoid misinterpretation.
Level and type filtering. When level and/or type
are specified, only rows matching the requested value(s) are returned. The
two filters are applied sequentially and independently: level is
applied first, then type. Specifying type = "Pure" expands
to all three global pure-type categories ("Pure Ranked",
"Pure High", "Pure Medium") but does not override the
level filter — if level is set to a non-global level, the
combination will yield zero rows (with a warning). If no features are found
after filtering, a zero-row data.frame is returned with a warning
rather than an error, allowing featureInspect() to be used safely
inside loops or lapply() calls.
Examples
if (FALSE) { # \dontrun{
# --- Basic usage: return a table only ---
result_table <- featureInspect(
clustoCell = my_clustocell_obj,
features = c("CD3D", "MS4A1", "FOXP3")
)
print(result_table)
# --- Filter to a single level ---
result_major <- featureInspect(
clustoCell = my_clustocell_obj,
features = c("CD3D", "MS4A1", "FOXP3"),
level = "Major cluster"
)
# --- Filter to multiple levels ---
result_sub <- featureInspect(
clustoCell = my_clustocell_obj,
features = c("CD3D", "MS4A1", "FOXP3"),
level = c("Major cluster", "Sub-cluster")
)
# --- Return table sorted by Gini score ---
result_gini <- featureInspect(
clustoCell = my_clustocell_obj,
features = c("CD3D", "MS4A1", "FOXP3"),
sort_by = "gini"
)
# --- Return table and plot (default aesthetics) ---
result_list <- featureInspect(
clustoCell = my_clustocell_obj,
features = c("CD3D", "MS4A1", "FOXP3"),
plot = TRUE
)
result_list$table
result_list$plot
# --- Customise the plot ---
result_custom <- featureInspect(
clustoCell = my_clustocell_obj,
features = c("CD3D", "MS4A1", "FOXP3"),
plot = TRUE,
title = "Feature Membership Overview",
subtitle = "ClustoCell marker hierarchy",
show_purity = TRUE,
color_low = "navy",
color_high = "gold",
dotsize = 4,
nrow_panels = 2,
legend_position = "bottom"
)
result_custom$plot
# --- Colour dots by Type instead of Purity ---
result_type <- featureInspect(
clustoCell = my_clustocell_obj,
features = c("CD3D", "MS4A1"),
plot = TRUE,
show_purity = FALSE,
class_palette = c(
Positive = "#2166AC",
Negative = "#D6604D",
Medium = "#4DAC26",
"Pure High" = "#762A83"
)
)
result_type$plot
# --- Filter to positive markers only ---
result_pos <- featureInspect(
clustoCell = my_clustocell_obj,
features = c("CD3D", "MS4A1", "FOXP3"),
type = "Positive"
)
# --- Filter to all global (pure) features using the shorthand ---
result_pure <- featureInspect(
clustoCell = my_clustocell_obj,
features = c("CD3D", "MS4A1", "FOXP3"),
type = "Pure"
)
# --- Combine level and type filters ---
result_combo <- featureInspect(
clustoCell = my_clustocell_obj,
features = c("CD3D", "MS4A1", "FOXP3"),
level = c("Major cluster", "Sub-cluster"),
type = c("Positive", "Negative")
)
# --- Safe use when a level or type may not exist ---
# Returns a zero-row data.frame with a warning (no error)
result_empty <- featureInspect(
clustoCell = my_clustocell_obj,
features = c("CD3D"),
level = "Cross-cluster"
)
result_empty2 <- featureInspect(
clustoCell = my_clustocell_obj,
features = c("CD3D"),
type = "Pure"
)
} # }