| Title: | Multidimensional Macrophage Profiling |
|---|---|
| Description: | Provides a multidimensional computational framework for macrophage profiling based on an ontology of biological programs. The framework independently detects macrophage populations and characterizes their lineage-associated and functional-state programs using program-level expression scores, detection coverage, gene-program coherence, cluster profiles, and profile similarity. The framework is designed to capture continuous and combinatorial macrophage states without imposing binary activation categories. |
| Authors: | Alessandro Palma [aut, cre, cph] (ORCID: <https://orcid.org/0000-0003-1300-5479>) |
| Maintainer: | Alessandro Palma <[email protected]> |
| License: | GPL-3 |
| Version: | 0.99.0 |
| Built: | 2026-10-26 19:35:18 UTC |
| Source: | https://github.com/BiocStaging/MacrophageFramework |
Runs the independent macrophage detector and applies the Macrophage Framework to clusters passing the detector gate. The detector establishes macrophage identity independently from the Framework ontology, whereas the Framework characterizes lineage-associated and functional-state programs.
analyze_macrophage_profile( expression = NULL, clusters = NULL, ontology = NULL, object = NULL, assay = "RNA", layer = NULL, reduction = NULL, detect_macrophages = TRUE, macrophage_clusters = NULL, min_core_score = 0.1, species = "Human", output_dir = "MacrophageFramework_output", save_outputs = TRUE )analyze_macrophage_profile( expression = NULL, clusters = NULL, ontology = NULL, object = NULL, assay = "RNA", layer = NULL, reduction = NULL, detect_macrophages = TRUE, macrophage_clusters = NULL, min_core_score = 0.1, species = "Human", output_dir = "MacrophageFramework_output", save_outputs = TRUE )
expression |
A gene-by-cell expression matrix. Ignored when
|
clusters |
A vector assigning each cell to a cluster. Ignored when
|
ontology |
Optional Framework ontology. If |
object |
Optional Seurat object. If supplied, expression data and cluster identities are extracted automatically. |
assay |
Assay to use when |
layer |
Expression layer to use when |
reduction |
Reduction used to obtain the embedding from a Seurat
object. If |
detect_macrophages |
Logical indicating whether the independent macrophage detector should be run. |
macrophage_clusters |
Optional vector specifying clusters to analyze
directly. If |
min_core_score |
Minimum cluster-level macrophage-core score required for inclusion when macrophage clusters are selected by the detector. |
species |
Species used for ontology gene mapping. Supported values
include |
output_dir |
Directory in which analysis outputs are saved when
|
save_outputs |
Logical indicating whether analysis results and
visualization outputs should be written to |
The function accepts either a gene-by-cell expression matrix together with cluster assignments or a Seurat object. For Seurat objects, expression data and cluster identities are extracted automatically. The Framework ontology is version 0.4 by default.
A list containing macrophage detection results, Framework profiles,
similarity, hierarchy, program scores, coverage and coherence diagnostics,
ontology, annotations, embedding information, and the analyzed cells and
clusters. When save_outputs = TRUE, the list also contains paths
to the generated output files.
ontology <- load_ontology("v0.4") genes <- unique( ontology$Gene[ !is.na(ontology$Gene) & nzchar(ontology$Gene) ] ) set.seed(1) expression <- matrix( sample(1:5, length(genes) * 6, replace = TRUE), nrow = length(genes), dimnames = list( genes, paste0("Cell", seq_len(6)) ) ) clusters <- rep(c("Cluster1", "Cluster2"), each = 3) result <- analyze_macrophage_profile( expression = expression, clusters = clusters, ontology = ontology, detect_macrophages = FALSE, macrophage_clusters = unique(clusters), species = "Human", save_outputs = FALSE ) head(result$analyzed_cells)ontology <- load_ontology("v0.4") genes <- unique( ontology$Gene[ !is.na(ontology$Gene) & nzchar(ontology$Gene) ] ) set.seed(1) expression <- matrix( sample(1:5, length(genes) * 6, replace = TRUE), nrow = length(genes), dimnames = list( genes, paste0("Cell", seq_len(6)) ) ) clusters <- rep(c("Cluster1", "Cluster2"), each = 3) result <- analyze_macrophage_profile( expression = expression, clusters = clusters, ontology = ontology, detect_macrophages = FALSE, macrophage_clusters = unique(clusters), species = "Human", save_outputs = FALSE ) head(result$analyzed_cells)
Calculates the fraction of genes belonging to each Macrophage Framework program that are detected in each cell. A gene is considered detected when its expression value is greater than zero.
calculate_detection_coverage(expression, ontology = NULL)calculate_detection_coverage(expression, ontology = NULL)
expression |
A gene-by-cell expression matrix. Dense matrices and sparse matrices from the Matrix package are supported. Gene names must be provided as row names. |
ontology |
Optional Framework ontology data frame. If |
Coverage is calculated independently for each program and cell using only ontology genes that are present in the supplied expression matrix. It therefore describes the extent to which the genes defining a program are detected in a cell and should be interpreted as a diagnostic measure rather than as a probability, confidence score, or measure of program activity.
A program-by-cell numeric matrix containing the proportion of available ontology genes detected in each cell. Rows correspond to Framework programs and columns correspond to cells.
ontology <- load_ontology() set.seed(1) genes <- unique(ontology$Gene) expression <- matrix( rpois(length(genes) * 5, lambda = 1), nrow = length(genes), dimnames = list( genes, paste0("Cell", seq_len(5)) ) ) coverage <- calculate_detection_coverage( expression = expression, ontology = ontology ) head(coverage)ontology <- load_ontology() set.seed(1) genes <- unique(ontology$Gene) expression <- matrix( rpois(length(genes) * 5, lambda = 1), nrow = length(genes), dimnames = list( genes, paste0("Cell", seq_len(5)) ) ) coverage <- calculate_detection_coverage( expression = expression, ontology = ontology ) head(coverage)
Calculates the cosine similarity between two Macrophage Framework profiles based on their program scores. Only biological programs shared by both profiles and with non-missing scores in both profiles are used.
calculate_profile_similarity(profile_1, profile_2)calculate_profile_similarity(profile_1, profile_2)
profile_1 |
A Macrophage Framework profile list containing a
|
profile_2 |
A second Macrophage Framework profile list containing a
|
Cosine similarity measures the similarity in the overall pattern of program scores independently of the absolute magnitude of the two profiles. Values closer to 1 indicate more similar program profiles, whereas values closer to 0 indicate less similar profiles.
A numeric value representing the cosine similarity between the
two profiles. NA is returned when fewer than two programs can be
compared or when one of the profiles has zero magnitude.
profile_1 <- list( scores = matrix( c(1, 0.5, 0.2), ncol = 1, dimnames = list( c("Program_A", "Program_B", "Program_C"), "Profile_1" ) ) ) profile_2 <- list( scores = matrix( c(0.8, 0.6, 0.1), ncol = 1, dimnames = list( c("Program_A", "Program_B", "Program_C"), "Profile_2" ) ) ) calculate_profile_similarity(profile_1, profile_2)profile_1 <- list( scores = matrix( c(1, 0.5, 0.2), ncol = 1, dimnames = list( c("Program_A", "Program_B", "Program_C"), "Profile_1" ) ) ) profile_2 <- list( scores = matrix( c(0.8, 0.6, 0.1), ncol = 1, dimnames = list( c("Program_A", "Program_B", "Program_C"), "Profile_2" ) ) ) calculate_profile_similarity(profile_1, profile_2)
Quantifies the internal coherence of each Macrophage Framework program across individual cells. Coherence is calculated from pairwise similarity among the genes belonging to each program that are detected in a given cell.
calculate_program_coherence(expression, ontology = NULL, scale_factor = 10000)calculate_program_coherence(expression, ontology = NULL, scale_factor = 10000)
expression |
A gene-by-cell expression matrix. Dense matrices and sparse matrices from the Matrix package are supported. Gene names must be provided as row names. |
ontology |
Optional Framework ontology data frame. If |
scale_factor |
Numeric scaling factor used for library-size
normalization. Defaults to |
Expression values are normalized using transcriptome-wide library size,
scaled by scale_factor, and log-transformed before coherence is
calculated. Genes with zero expression in a cell are treated as
unobserved and are excluded from the pairwise calculation.
For each program and cell, pairwise relative expression differences are calculated among observed program genes and combined using the product of their ontology weights. The resulting coherence score is bounded between 0 and 1, with higher values indicating greater internal agreement among the observed genes of a program.
Coherence is a diagnostic measure of internal program consistency and should not be interpreted as a probability, confidence score, or direct measure of program activity.
A program-by-cell numeric matrix containing coherence scores.
Rows correspond to Framework programs and columns correspond to cells.
Values range from 0 to 1. NA values indicate that fewer than two
program genes were detected in the corresponding cell.
ontology <- load_ontology() set.seed(1) genes <- unique(ontology$Gene) expression <- matrix( rpois(length(genes) * 5, lambda = 1), nrow = length(genes), dimnames = list( genes, paste0("Cell", seq_len(5)) ) ) coherence <- calculate_program_coherence( expression = expression, ontology = ontology ) head(coherence)ontology <- load_ontology() set.seed(1) genes <- unique(ontology$Gene) expression <- matrix( rpois(length(genes) * 5, lambda = 1), nrow = length(genes), dimnames = list( genes, paste0("Cell", seq_len(5)) ) ) coherence <- calculate_program_coherence( expression = expression, ontology = ontology ) head(coherence)
Loads a predefined version of the Macrophage Framework ontology from the
package's installed inst/extdata directory.
load_ontology(version = "v0.4")load_ontology(version = "v0.4")
version |
Character string specifying the ontology version to load.
Defaults to |
The current ontology version is "v0.4". In this version, macrophage
identity is established independently by the macrophage detector and is
therefore not represented as an ontology dimension. The ontology defines
lineage-associated and functional-state programs used for Framework
scoring and annotation.
A data frame containing the selected Macrophage Framework ontology.
ontology <- load_ontology() head(ontology)ontology <- load_ontology() head(ontology)
Visualizes the relative intensity of Macrophage Framework programs across analyzed macrophage clusters. Program scores are normalized independently for each cluster to unit Euclidean norm for visualization, allowing the relative composition of multidimensional profiles to be compared.
plot_macrophage_profile(result)plot_macrophage_profile(result)
result |
Output list returned by
|
This normalization is applied only for visualization and does not modify the original program scores stored in the analysis result.
A ggplot object showing normalized program-intensity
profiles for the analyzed clusters.
ontology <- load_ontology("v0.4") genes <- unique( ontology$Gene[ !is.na(ontology$Gene) & nzchar(ontology$Gene) ] ) set.seed(1) expression <- matrix( sample(1:5, length(genes) * 6, replace = TRUE), nrow = length(genes), dimnames = list( genes, paste0("Cell", seq_len(6)) ) ) clusters <- rep(c("Cluster1", "Cluster2"), each = 3) result <- analyze_macrophage_profile( expression = expression, clusters = clusters, ontology = ontology, detect_macrophages = FALSE, macrophage_clusters = unique(clusters), species = "Human", save_outputs = FALSE ) plot_macrophage_profile(result)ontology <- load_ontology("v0.4") genes <- unique( ontology$Gene[ !is.na(ontology$Gene) & nzchar(ontology$Gene) ] ) set.seed(1) expression <- matrix( sample(1:5, length(genes) * 6, replace = TRUE), nrow = length(genes), dimnames = list( genes, paste0("Cell", seq_len(6)) ) ) clusters <- rep(c("Cluster1", "Cluster2"), each = 3) result <- analyze_macrophage_profile( expression = expression, clusters = clusters, ontology = ontology, detect_macrophages = FALSE, macrophage_clusters = unique(clusters), species = "Human", save_outputs = FALSE ) plot_macrophage_profile(result)
Visualizes pairwise similarity between macrophage profiles as a heatmap.
Similarity values are obtained from the profile similarity matrix generated
by analyze_macrophage_profile and represent cosine similarity
between multidimensional program-score profiles.
plot_macrophage_similarity(result)plot_macrophage_similarity(result)
result |
Output list returned by
|
Higher values indicate greater similarity between profiles. The diagonal represents the similarity of each profile with itself.
A ggplot object containing a heatmap of pairwise macrophage
profile similarity.
ontology <- load_ontology("v0.4") genes <- unique( ontology$Gene[ !is.na(ontology$Gene) & nzchar(ontology$Gene) ] ) set.seed(1) expression <- matrix( sample(1:5, length(genes) * 6, replace = TRUE), nrow = length(genes), dimnames = list( genes, paste0("Cell", seq_len(6)) ) ) clusters <- rep(c("Cluster1", "Cluster2"), each = 3) result <- analyze_macrophage_profile( expression = expression, clusters = clusters, ontology = ontology, detect_macrophages = FALSE, macrophage_clusters = unique(clusters), species = "Human", save_outputs = FALSE ) plot_macrophage_similarity(result)ontology <- load_ontology("v0.4") genes <- unique( ontology$Gene[ !is.na(ontology$Gene) & nzchar(ontology$Gene) ] ) set.seed(1) expression <- matrix( sample(1:5, length(genes) * 6, replace = TRUE), nrow = length(genes), dimnames = list( genes, paste0("Cell", seq_len(6)) ) ) clusters <- rep(c("Cluster1", "Cluster2"), each = 3) result <- analyze_macrophage_profile( expression = expression, clusters = clusters, ontology = ontology, detect_macrophages = FALSE, macrophage_clusters = unique(clusters), species = "Human", save_outputs = FALSE ) plot_macrophage_similarity(result)
Visualizes Macrophage Framework profile annotations on a dimensional reduction stored in a Seurat object. The function produces two plots: the original computational cluster assignments and the corresponding multidimensional Macrophage Framework profile annotations.
plot_macrophage_umap(result, object, clusters, cell_names, reduction = "umap")plot_macrophage_umap(result, object, clusters, cell_names, reduction = "umap")
result |
Output list returned by
|
object |
Seurat object containing the dimensional reduction to plot. |
clusters |
A vector of cell-level cluster assignments corresponding
to |
cell_names |
Character vector of cell barcodes corresponding to the
elements of |
reduction |
Name of the Seurat dimensional reduction to use.
Defaults to |
Cells are matched between the dimensional reduction and the supplied
cluster assignments using their cell barcodes. Framework profile labels
are obtained from summarize_macrophage_profile.
Although the function is named plot_macrophage_umap, any Seurat
dimensional reduction containing at least two dimensions can be used.
A patchwork object containing two ggplot panels:
the original computational clusters and the corresponding Macrophage
Framework profile annotations.
ontology <- load_ontology("v0.4") genes <- unique( ontology$Gene[ !is.na(ontology$Gene) & nzchar(ontology$Gene) ] ) set.seed(1) cells <- paste0("Cell", seq_len(6)) expression <- matrix( sample(1:5, length(genes) * length(cells), replace = TRUE), nrow = length(genes), dimnames = list(genes, cells) ) clusters <- rep(c("Cluster1", "Cluster2"), each = 3) result <- analyze_macrophage_profile( expression = expression, clusters = clusters, ontology = ontology, detect_macrophages = FALSE, macrophage_clusters = unique(clusters), species = "Human", save_outputs = FALSE ) seurat_object <- SeuratObject::CreateSeuratObject( counts = expression ) embeddings <- matrix( rnorm(length(cells) * 2), nrow = length(cells), dimnames = list(cells, c("UMAP_1", "UMAP_2")) ) seurat_object[["umap"]] <- SeuratObject::CreateDimReducObject( embeddings = embeddings, key = "UMAP_", assay = "RNA" ) plot_macrophage_umap( result = result, object = seurat_object, clusters = clusters, cell_names = cells, reduction = "umap" )ontology <- load_ontology("v0.4") genes <- unique( ontology$Gene[ !is.na(ontology$Gene) & nzchar(ontology$Gene) ] ) set.seed(1) cells <- paste0("Cell", seq_len(6)) expression <- matrix( sample(1:5, length(genes) * length(cells), replace = TRUE), nrow = length(genes), dimnames = list(genes, cells) ) clusters <- rep(c("Cluster1", "Cluster2"), each = 3) result <- analyze_macrophage_profile( expression = expression, clusters = clusters, ontology = ontology, detect_macrophages = FALSE, macrophage_clusters = unique(clusters), species = "Human", save_outputs = FALSE ) seurat_object <- SeuratObject::CreateSeuratObject( counts = expression ) embeddings <- matrix( rnorm(length(cells) * 2), nrow = length(cells), dimnames = list(cells, c("UMAP_1", "UMAP_2")) ) seurat_object[["umap"]] <- SeuratObject::CreateDimReducObject( embeddings = embeddings, key = "UMAP_", assay = "RNA" ) plot_macrophage_umap( result = result, object = seurat_object, clusters = clusters, cell_names = cells, reduction = "umap" )
Calculates weighted expression scores for the biological programs defined
in the Macrophage Framework ontology. Expression values are normalized using
the transcriptome-wide library size of each cell, scaled by
scale_factor, and log-transformed before program scores are
calculated.
score_programs( expression, ontology = NULL, scale_factor = 10000, library_size = NULL )score_programs( expression, ontology = NULL, scale_factor = 10000, library_size = NULL )
expression |
A gene-by-cell expression matrix. Dense matrices and sparse matrices from the Matrix package are supported. Gene names must be provided as row names. |
ontology |
Optional Framework ontology data frame. If |
scale_factor |
Numeric scaling factor used for library-size
normalization. Defaults to |
library_size |
Optional vector containing the library size for each
cell. If |
Only ontology genes detected in the supplied expression matrix are used for
scoring. Program scores are calculated as the weighted mean of the
log-transformed expression values of the genes belonging to each program.
Gene weights are defined by the Weight column of the ontology.
Program coverage is calculated as the proportion of ontology genes available in the expression matrix for each program. Coverage therefore describes gene availability and is not used as a probability or confidence measure.
A list containing:
A program-by-cell matrix of weighted program scores.
The number of ontology genes available in the expression matrix for each program.
The total number of genes defined for each program in the ontology.
The proportion of ontology genes available for each program.
ontology <- load_ontology() set.seed(1) expression <- matrix( rpois(100, lambda = 2), nrow = 10, dimnames = list( ontology$Gene[seq_len(10)], paste0("Cell", seq_len(10)) ) ) result <- score_programs( expression = expression, ontology = ontology )ontology <- load_ontology() set.seed(1) expression <- matrix( rpois(100, lambda = 2), nrow = 10, dimnames = list( ontology$Gene[seq_len(10)], paste0("Cell", seq_len(10)) ) ) result <- score_programs( expression = expression, ontology = ontology )
Calculates the median and interquartile range (IQR) of each program's cell-level coherence within each cluster. Non-finite values are excluded from the calculations.
summarize_cluster_coherence(cell_coherence, cluster_labels)summarize_cluster_coherence(cell_coherence, cluster_labels)
cell_coherence |
Numeric matrix of program-by-cell coherence values, with programs in rows and cells in columns. |
cluster_labels |
Vector assigning one cluster label to each
cell, in the same order as the columns of |
A list containing two matrices, median and
IQR. Both matrices have programs in rows and clusters
in columns. Entries remain NA when a program-cluster
combination has no finite coherence values.
Converts the results of a Macrophage Framework analysis into a data frame containing cluster-level identity, lineage, functional state, and other profile information.
summarize_macrophage_profile(result, clusters = NULL)summarize_macrophage_profile(result, clusters = NULL)
result |
Output from |
clusters |
Optional vector of cell-level cluster assignments, used to calculate the number of cells in each cluster. |
A data.frame summarizing the multidimensional macrophage profiles, including cluster identity, lineage, functional state, profile labels, and program-level scores and diagnostics.
ontology <- load_ontology("v0.4") genes <- unique( ontology$Gene[ !is.na(ontology$Gene) & nzchar(ontology$Gene) ] ) set.seed(1) expression <- matrix( sample(1:5, length(genes) * 6, replace = TRUE), nrow = length(genes), dimnames = list( genes, paste0("Cell", seq_len(6)) ) ) clusters <- rep(c("Cluster1", "Cluster2"), each = 3) result <- analyze_macrophage_profile( expression = expression, clusters = clusters, ontology = ontology, detect_macrophages = FALSE, macrophage_clusters = unique(clusters), species = "Human", save_outputs = FALSE ) summary <- summarize_macrophage_profile( result = result, clusters = clusters ) head(summary)ontology <- load_ontology("v0.4") genes <- unique( ontology$Gene[ !is.na(ontology$Gene) & nzchar(ontology$Gene) ] ) set.seed(1) expression <- matrix( sample(1:5, length(genes) * 6, replace = TRUE), nrow = length(genes), dimnames = list( genes, paste0("Cell", seq_len(6)) ) ) clusters <- rep(c("Cluster1", "Cluster2"), each = 3) result <- analyze_macrophage_profile( expression = expression, clusters = clusters, ontology = ontology, detect_macrophages = FALSE, macrophage_clusters = unique(clusters), species = "Human", save_outputs = FALSE ) summary <- summarize_macrophage_profile( result = result, clusters = clusters ) head(summary)