Skip to content

Adjust quartile and generated bins to special outliers - #12472

Open
Tanishq-Choudhary wants to merge 3 commits into
cBioPortal:masterfrom
Tanishq-Choudhary:fix-bin-outlier-boundaries
Open

Tanishq-Choudhary wants to merge 3 commits into
cBioPortal:masterfrom
Tanishq-Choudhary:fix-bin-outlier-boundaries

Conversation

@Tanishq-Choudhary

Copy link
Copy Markdown

Describe changes proposed in this pull request:

  • Quartile and generated bins were built from every numeric value and never trimmed to the bounds of special outlier values like <=40 or >52. Values inside a bound were counted twice, in the outlier bin and in the first or last data bin. When a whole generated bin fell inside the bound, the request failed with IllegalArgumentException: Invalid range.
  • They now go through adjustCustomBins like custom bins do, and a single boundary left after that becomes the outlier split for all three methods, as it already did for custom bins.
  • adjustCustomBins no longer adds a bound that is already one of the bins. Custom bins 40, 52, 60 with a >52 value made a [52, 52] bin and counted the 52s twice.

Examples with 36 ages (20, 22, ..., 90) plus one special value:

Bin method Special value master this PR
Quartiles <=40 39 counted for 37 patients (38 and 40 counted twice) 37
Generate bins, size 10, anchor 0 (ages 20, 25, ..., 90) <=35 Invalid range: (35..30] 16 of 16
Custom bins 40, 52, 60 >52 38 counted for 37 patients 37

This happens when the numeric values reach past a special value's bound, e.g. a study view combining a study that records <=40 with one that records exact ages. Quartiles and Generate bins came in with #9198.

Checks

Three tests added to DataBinnerTest, one per case above; all three fail on master. DataBinnerTest, DataBinHelperTest, ClinicalDataBinUtilTest, StudyViewControllerTest, ColumnarStoreStudyViewControllerTest and StudyViewFilterApplierTest pass, and spotless:check is clean. I can't add labels; fix would fit.

Quartile and generated bins were built from every numeric value and
never trimmed to the bounds of special outlier values such as "<=40" or
">52". Values inside those bounds were counted in the outlier bin and
in the first or last data bin, and when a whole bin fell inside the
bound, moving its edge to the bound threw "Invalid range".

Apply adjustCustomBins to them as custom bins already do, and use a
single remaining boundary as the outlier split for all three methods.
adjustCustomBins also no longer adds a bound that is already one of
the bins, which made a zero-width bin and counted its values twice.
@Tanishq-Choudhary
Tanishq-Choudhary marked this pull request as ready for review November 19, 2026 19:46

@arieleven arieleven 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.

Nice fix. Running generated and quartile boundaries through adjustCustomBins closes the case where the first bin started below a special lower outlier and later got its start moved past its end. The noneMatch guard also stops a duplicate boundary (and so a zero-width bin) when the special value lands exactly on a bin edge. The three tests read clearly and line up with the counts I worked out by hand.

One edge case I think the new single-boundary branch doesn't reach for quartiles. If the special outlier sits exactly on Q3 (say the data has <=73 and Q3 is 73), adjustCustomBins([Q1, Q2, 73]) keeps only [73], because 73 is already in the list and isn't added back. One boundary gives zero linear bins, so this branch fires first:

if (MEDIAN == binMethod || (QUARTILE == binMethod && dataBins.size() == 0)) {
  lowerOutlierBin.setEnd(median);
  upperOutlierBin.setStart(median);
} else if (adjustedBins != null && adjustedBins.size() == 1) { ... }

The outlier bins would then split at the median (<=55 / >55 in the 20..90 data from your quartile test) and not at 73, so the values the dataset reports as <=73 end up counted under a <=55 label. Checking adjustedBins.size() == 1 before the quartile-empty fallback, or limiting that fallback to the case where adjustedBins is empty or all quartiles were identical, would keep the special value as the split point. A variant of testLinearDataBinnerQuartileBinsWithSpecialOutlierAboveQ1 with <=73 would cover it.

Small thing: adjustCustomBins is now used for all three methods, so a more neutral name (e.g. adjustBinsToOutliers) and a Javadoc that mentions generated and quartile bins would help the next reader.

When a special outlier value equals Q3, the adjusted quartile bins
reduce to that one value, which gives no linear bins. The quartile
fallback to the median ran first, so values counted as "<=35" ended
up under a "<=23.5" label. Check for a single remaining boundary
before falling back to the median.

Rename adjustCustomBins to adjustBinsToOutliers since it now handles
generated and quartile bins too.
@Tanishq-Choudhary

Copy link
Copy Markdown
Author

Confirmed and fixed in 2728cba. The <=73 variant of the 20..90 test goes to the discrete binner (only 9 distinct values above 73), so the new test uses 1..46 with "<=35", where Q3 is 35. Before the fix that gave <=23.5 (24) and >23.5 (23). The single-boundary check now runs before the quartile fallback, and adjustCustomBins is renamed to adjustBinsToOutliers with the Javadoc updated.

This branch has not been deployed

No deployments
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.

2 participants