Project: s41467-025-56441-5 | Function: cellscore (r)

system: You are an expert R programmer implementing algorithms from scientific papers.
Complete the masked function based on the algorithm description.
Follow R best practices and maintain consistent code style.
Return **only** the complete R function code.

user: Complete this R function:

**DESCRIPTION:** Implements custom cell type scoring algorithm using expression-based binning and control gene sampling. Calculates cell type scores by comparing marker gene expression to background genes matched for expression levels.

**KEY TERMS:** {
  "markers": "Cell type marker genes",
  "nbins": "Expression level bins for matching",
  "markersub": "Filtered marker genes",
  "control": "Background/control gene expression"
}

**CONTEXT CODE:** ####data####

tumors       = readRDS("/mnt/data/users/levi/snRNAseqGLASS/primary_tumors.RDS")
cell_marker  = read_xlsx("d:/Documents/Results/Gemistocytes/manuscript/Submission/Nature Communications/7.Supplementary_tables.xlsx", sheet = "Table S10", skip = 2)

####functions####

cellscore <- function(object, markers, nbins = 30, assay = "SCT", slot = "data") {
  stop("Function implementation has been masked")
}


Complete the function implementation replacing "stop("Not implemented")".