Skip to content

Fix division-by-zero in filter.points & as.vector regression in multi-traits#153

Open
lyangfan wants to merge 2 commits intoYinLiLin:masterfrom
lyangfan:fix-signal-line
Open

Fix division-by-zero in filter.points & as.vector regression in multi-traits#153
lyangfan wants to merge 2 commits intoYinLiLin:masterfrom
lyangfan:fix-signal-line

Conversation

@lyangfan
Copy link
Copy Markdown

@lyangfan lyangfan commented May 7, 2026

Summary

1. Fix division-by-zero in filter.points causing density plot point loss

filter.points is called with constant y values in density rendering. When y_range == 0, (y - y_min) / (y_max - y_min) produces 0/0 = NaN. R's duplicated() treats the first NaN as unique and all subsequent as duplicates, collapsing the entire density bar to a single pixel.

Reproduce:

data(pig60K)
CMplot(pig60K, plot.type="d", bin.size=1e6,
       chr.den.col=c("darkgreen", "yellow", "red"),
       file="jpg", dpi=300, file.output=TRUE)

2. Fix as.vector regression in multi-traits mode

The optimization commit (23905fc) removed Pmap <- as.matrix(Pmap) to keep Pmap as data.frame for performance. However, as.vector(Pmap[,3:(R+2)]) in the multi-traits section relies on Pmap being a matrix — as.vector() on a data.frame (which is a list) returns it unchanged. Subsequent min_no_na(pvalue)min(list, na.rm=TRUE) crashes.

Reproduce:

data(pig60K)
CMplot(pig60K, plot.type="m", LOG10=TRUE, multraits=TRUE,
       col=c("grey60","#4197d8","#f8c120"),
       file="jpg", dpi=150, file.output=TRUE)
# Error: invalid 'type' (list) of argument

🤖 Generated with Claude Code

lyangfan and others added 2 commits May 8, 2026 04:16
In the density plot, filter.points is called with a constant y value
(per-chromosome band position), making y_max - y_min = 0. This causes
0/0 = NaN, collapsing all keys to NaN and making duplicated() keep
only the first point per group. The result is severe point loss in
density plots.

Fix: check for zero range before division; assign 0L to scaled values
when range is 0, preserving correct point filtering behavior.
as.vector() on a multi-column data.frame does not flatten it to a
numeric vector, causing min() to fail with "invalid type (list)".
Use unlist() first. Bug existed since upstream (2023-06-28).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.

1 participant