Skip to content

addGeneScoreMatrix: GeneScoreMatrix is silently all-NaN when gene widths are equal (divide by max(m)-min(m) = 0) #2334

Open

Description

@scttfrdmn

In .addGeneScoreMat (default useTSS = FALSE, gene-body path), R/MatrixGeneScores.R at v1.0.3:

270    m <- 1 / width(geneRegions)
271    geneRegions$geneWeight <- 1 + m * (geneScaleFactor - 1) / (max(m) - min(m))

If every gene region has the same width, max(m) - min(m) is 0, every geneWeight is Inf/NaN, and the whole GeneScoreMatrix comes out NaN, with no error or warning. The failure only shows up later, far from its cause: getMarkerFeatures(useMatrix = "GeneScoreMatrix") stops with missing value where TRUE/FALSE needed.

This bit us on a small synthetic genome with uniform gene lengths (ArchR 1.0.3 from bioconda r-archr, R 4.4, on linux-aarch64 and linux-64 alike). Varying the gene lengths makes the matrix finite.

A second, possibly related question: the expression is not a min-max scaling of m. That would be 1 + (m - min(m)) * (geneScaleFactor - 1) / (max(m) - min(m)), mapping to [1, geneScaleFactor]. As written, the weights span [1 + min(m)·k, 1 + max(m)·k], which reaches geneScaleFactor only when min(m) is close to 0. If min-max is the intent, the fix covers both issues. If it isn't, a guard is enough, e.g.

rng <- max(m) - min(m)
geneRegions$geneWeight <- if (rng > 0) 1 + m * (geneScaleFactor - 1) / rng else geneScaleFactor

Either way, it would help to error (or warn) on a non-finite GeneScoreMatrix at creation time rather than at getMarkerFeatures.

Activity

  1. immanuelazn commented on Oct 16, 2026

    @immanuelazn
    Collaborator

    Hi @scttfrdmn! Thanks for using ArchR! Please make sure that your post belongs in the Issues section. Only bugs and error reports belong in the Issues section. Usage questions and feature requests should be posted in the Discussions section, not in Issues.

    If you are getting an error, it is likely due to something specific to your dataset, usage, or computational environment, all of which are extremely challenging to troubleshoot. As such, we require reproducible examples (preferably using the tutorial dataset) from users who want assistance. If you cannot reproduce your error, we will not be able to help.
    Before going through the work of making a reproducible example, search the previous Issues, Discussions, function definitions, or the ArchR manual and you will likely find the answers you are looking for.
    If your post does not contain a reproducible example, it is unlikely to receive a response.

    In addition to a reproducible example, you must do the following things before we help you, unless your original post already contained this information:
    1. If you've encountered an error, have you already searched previous Issues to make sure that this hasn't already been solved?
    2. Did you post your log file? If not, add it now.
    3. Remove any screenshots that contain text and instead copy and paste the text using markdown's codeblock syntax (three consecutive backticks). You can do this by editing your original post.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions