if (FALSE) {
library(easybio)
data(pbmc.markers)
# Basic usage: Annotate clusters using the top 50 markers per cluster
matched_cells <- matchCellMarker2(pbmc.markers, n = 50, spc = "Human")
print(matched_cells)
# To see the top annotation for each cluster
top_matches <- matched_cells[, .SD[1], by = cluster]
print(top_matches)
# Advanced usage: Stricter filtering and focus on specific tissues
matched_cells_strict <- matchCellMarker2(
pbmc.markers,
n = 30,
spc = "Human",
avg_log2FC_threshold = 0.5,
p_val_adj_threshold = 0.01,
tissueType = c("Blood", "Bone marrow")
)
print(matched_cells_strict)
# --- Example with a custom reference ---
# Create a custom reference as a named list.
custom_ref_list <- list(
"T-cell" = c("CD3D", "CD3E"),
"B-cell" = c("CD79A", "MS4A1"),
"Myeloid" = "LYZ"
)
# Convert the list to a long data.frame compatible with the 'ref' parameter.
custom_ref_df <- list2dt(custom_ref_list, col_names = c("cell_name", "marker"))
# Run annotation using the custom reference.
# When 'ref' is provided, the internal cellMarker2 database and its filters
# ('spc', 'tissueClass', 'tissueType') are ignored for matching.
matched_custom <- matchCellMarker2(
pbmc.markers,
n = 50,
ref = custom_ref_df
)
print(matched_custom)
}
Run the code above in your browser using DataLab