Skip to content

Revision of qcscore_model_spe branch#64

Open
BenedettaBanzi wants to merge 2 commits into
qcscore_model_spefrom
qscore_model_spe
Open

Revision of qcscore_model_spe branch#64
BenedettaBanzi wants to merge 2 commits into
qcscore_model_spefrom
qscore_model_spe

Conversation

@BenedettaBanzi

Copy link
Copy Markdown
Collaborator
  • Fixed some issues with QS computation with custom formula;
  • updated QC functions documentation;
  • added more customazable settings to plot functions;
  • function name standardization to Quality Score (QScore);
  • updated vignettes.

…lected metrics. Function name standardization to QScore. plotCellsFovs with distinct parameters for points and FOV number sizes. Updated documentation and vignettes.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates SpaceTrooper’s Quality Score (QS) APIs and documentation, including renaming/standardizing “QCScore” to “QScore”, expanding plot customization controls, and refreshing vignettes/man pages for the new interface.

Changes:

  • Renames QS-related functions/outputs (e.g., computeQCScore()computeQScore(), QC_scoreQScore) and updates package docs/vignettes accordingly.
  • Adds/extends support for user-specified QS model formulas and updates QS model training/application documentation.
  • Expands plotting customization parameters (e.g., point size/alpha and label sizes) and updates associated docs/vignettes.

Reviewed changes

Copilot reviewed 14 out of 32 changed files in this pull request and generated 15 comments.

Show a summary per file
File Description
vignettes/SpaceTrooper_utilities.Rmd Updates utilities vignette for QScore naming and adds custom-formula example.
vignettes/RNA_tutorial_vignette.rmd Updates RNA tutorial to use renamed QS APIs and updated plotting args.
vignettes/Protein_tutorial_vignette.Rmd Updates protein tutorial to use renamed QS APIs and updated plotting args.
README.md Updates quickstart example to computeQScore()/computeQScoreFlags().
R/spatialQCPlots.R Adds plot customization parameters and refactors plotting function signatures.
R/readMerfish.R Updates warning message wording for Quality Score terminology.
R/QC.R Renames/updates QS computation pipeline, formula handling, model application helper, and extensive roxygen updates.
NEWS.md Updates release notes for 1.1.8 changes.
NAMESPACE Updates exports to new function names (adds .applyQScoreModel, swaps QCScore exports for QScore).
man/trainModel.Rd Updates documentation wording for ridge logistic regression model fitting.
man/spatialPerCellQC.Rd Updates parameter descriptions and expanded behavior documentation.
man/plotZoomFovsMap.Rd Documents new plotZoomFovsMap arguments and naming.
man/plotCellsFovs.Rd Documents new plotCellsFovs arguments and naming.
man/getModelFormula.Rd Updates usage to metricList (but needs consistency fixes).
man/dot-computeXenMerTrainSet.Rd Documentation wording update for internal helper.
man/dot-computeCosmxTrainSet.Rd Documentation wording update for internal helper.
man/dot-computeCosmxProteinTrainSet.Rd Documentation wording update for internal helper.
man/dot-computeBorderDistanceCosMx.Rd Documentation wording updates for FOV terminology.
man/dot-checkSkw.Rd Documentation wording update for internal helper.
man/dot-applyQScoreModel.Rd Adds documentation for .applyQScoreModel() (example currently inconsistent with actual API).
man/computeTrainDF.Rd Updates docs to QScore_train naming and other wording.
man/computeThresholdFlags.Rd Updates docs wording and clarifies outputs.
man/computeSpatialOutlier.Rd Updates docs wording and clarifies behavior.
man/computeQScoreFlags.Rd Adds documentation for computeQScoreFlags().
man/computeQScore.Rd Adds documentation for computeQScore().
man/computeQCScoreFlags.Rd Removes deprecated/renamed QCScoreFlags man page.
man/computeQCScore.Rd Removes deprecated/renamed computeQCScore man page.
man/computeOutliersQScore.Rd Renames and updates outlier-computation documentation for QScore.
man/computeLambda.Rd Updates usage to new signature (but needs argument/example consistency fixes).
man/checkOutliers.Rd Updates docs wording and naming to Quality Score.
man/applyQCScoreModel.Rd Removes deprecated/renamed applyQCScoreModel man page.
DESCRIPTION Bumps version to 1.1.8.
Files not reviewed (18)
  • man/checkOutliers.Rd: Generated file
  • man/computeLambda.Rd: Generated file
  • man/computeQScore.Rd: Generated file
  • man/computeQScoreFlags.Rd: Generated file
  • man/computeSpatialOutlier.Rd: Generated file
  • man/computeThresholdFlags.Rd: Generated file
  • man/computeTrainDF.Rd: Generated file
  • man/dot-applyQScoreModel.Rd: Generated file
  • man/dot-checkSkw.Rd: Generated file
  • man/dot-computeBorderDistanceCosMx.Rd: Generated file
  • man/dot-computeCosmxProteinTrainSet.Rd: Generated file
  • man/dot-computeCosmxTrainSet.Rd: Generated file
  • man/dot-computeXenMerTrainSet.Rd: Generated file
  • man/getModelFormula.Rd: Generated file
  • man/plotCellsFovs.Rd: Generated file
  • man/plotZoomFovsMap.Rd: Generated file
  • man/spatialPerCellQC.Rd: Generated file
  • man/trainModel.Rd: Generated file
Comments suppressed due to low confidence (4)

man/computeLambda.Rd:18

  • computeLambda documentation is inconsistent with the new signature computeLambda(modelMatrix, trainDF): it still documents a modelFormula argument and the examples call computeLambda(df_train, modform). This will mislead users and fail during example checks.

This issue also appears on line 39 of the same file.
man/computeLambda.Rd:42

  • The example still uses the old API (getModelFormula(metadata(spe)$formula_variables) and computeLambda(df_train, modform)), but the function signatures were updated. This example will error if executed.
    vignettes/SpaceTrooper_utilities.Rmd:513
  • The vignette currently tells users the I(abs(log2AspectRatio) * as.numeric(dist_border < 50)) term "must have spaces around the * and < operators". Requiring exact whitespace makes the API brittle and is easy for users to get wrong; it’s better to document that whitespace is irrelevant (and ensure the implementation normalizes it).
    R/QC.R:369
  • computeLambda() docs still say it "constructs the design matrix via model.matrix()", but the function now takes modelMatrix as an argument and no longer builds it internally. This makes the description misleading.
#' Internally, the function:
#'   constructs the design matrix via \code{model.matrix()},
#'   runs k-fold cross-validation of ridge logistic regression using `cv.glmnet` with `alpha = 0`,
#'   extracts and returns `ridge_cv$lambda.min`.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread R/QC.R
df <- ctx$df; out_var <- ctx$out_var; tech <- ctx$tech

train_df <- computeTrainDF(df, out_var, tech, verbose)
model_formula <- getModelFormula(names(out_var))

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a wrong suggestion. model_formula should be built ALWAYS using the computed variables contained in out_var, not just when modelFormula is null. out_var is the vector of metrics resulting from the checks made by .prepQCContext. If the number of outliers is not enough, that metric is automatically discarded from the vector

Comment thread R/QC.R
Comment on lines 757 to 760
#' @param formulaVars A named character vector mapping variable names
#' (e.g. `"log2SignalDensity"`, `"Area_um"`, etc.) to their corresponding
#' outlier label columns, typically from
#' `metadata(spe)$formula_variables`.
Comment thread R/QC.R
out_var <- metricList
if ("log2AspectRatio" %in% out_var) {
out_var[grep("log2AspectRatio", out_var)] <-
"I(abs(log2AspectRatio) * as.numeric(dist_border<50))"
Comment thread R/QC.R
Comment on lines +1261 to 1265
#' spe_test <- applyQScoreModel(
#' spe=spe_test,
#' qcModel=qc_model,
#' scoreName="QC_score_transferred"
#' scoreName="QScore_transferred"
#' )
Comment on lines +58 to +62
spe_test <- applyQScoreModel(
spe=spe_test,
qcModel=qc_model,
scoreName="QScore_transferred"
)
Comment thread man/getModelFormula.Rd
Comment on lines +7 to 13
getModelFormula(metricList)
}
\arguments{
\item{formulaVars}{A named character vector mapping variable names
(e.g. `"log2SignalDensity"`, `"Area_um"`, etc.) to their corresponding
outlier label columns, typically from
`metadata(spe)$formula_variables`.}
Comment thread R/QC.R
Comment on lines +433 to +437
#' `~(log2SignalDensity + Area_um + I(abs(log2AspectRatio) * as.numeric(dist_border < 50)) + log2Ctrl_total_ratio)^2`.
#' When user-provided, the formula must follow the same default syntax and
#' removed (or added) terms should be written exactly as in the default formula,
#' e.g. `I(abs(log2AspectRatio) * as.numeric(dist_border < 50))` must have spaces
#' around the `*` and `<` operators.
Comment thread R/QC.R
Comment on lines +466 to 469
computeQScore <- function(spe, bestLambda=NULL, modelFormula=NULL, verbose=FALSE) {
stopifnot(is(spe, "SpatialExperiment"))
if (dim(spe[,spe$total == 0])[2] != 0) {
warning(paste0(dim(spe[,spe$total == 0])[2],
Comment thread R/QC.R
Comment on lines 352 to 356
#' @param trainDF `data.frame`
#' A data frame for training that must include:
#' A data frame for QS model training that must include:
#' Predictor columns: All columns referenced in the formula returned by `getModelFormula()`.
#' `qscore_train` A binary (0/1) response vector to be modeled.
#' @param modelFormula `character`
Comment thread R/QC.R
Comment on lines 1216 to 1220
#' @description
#' Apply a previously trained QC score model to a new SpatialExperiment object.
#' Internal: applies a previously trained Quality Score model to a new SpatialExperiment object.
#' See details for important considerations when applying a model to a
#' different dataset.
#' @details
@drighelli

Copy link
Copy Markdown
Owner

@copilot based on your review, provide possible solutions to the problems in a different PR, and add the old computeQCScore function with the .Deprecated instruction based on the bioconductor guidelines present here:
https://contributions.bioconductor.org/deprecation.html

Copilot AI commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

@drighelli I've opened a new pull request, #65, to work on those changes. Once the pull request is ready, I'll request review from you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants