Skip to content

Fix row alignment bug in getWithColData append mode#346

Closed
aboyoun wants to merge 1 commit intowaldronlab:develfrom
aboyoun:bugfix/getWithColData-append
Closed

Fix row alignment bug in getWithColData append mode#346
aboyoun wants to merge 1 commit intowaldronlab:develfrom
aboyoun:bugfix/getWithColData-append

Conversation

@aboyoun
Copy link
Copy Markdown

@aboyoun aboyoun commented Mar 28, 2026

Fix row alignment bug in getWithColData append mode

Fixes a data corruption bug in getWithColData() when mode="append" where patient metadata was assigned to incorrect samples.

Problem

When appending MAE colData to experiment colData, the function performed positional cbind() on two DataFrames with incompatible row orderings:

  • existing (experiment colData): indexed by sample IDs
  • leftovers (MAE colData): indexed by patient IDs in sampleMap order
    This caused silent data corruption where samples received metadata from different patients (e.g., sample from patient M99 getting patient M4's age, treatment, outcome data).

Solution

Added row alignment step using sampleMap to reorder leftovers before cbind:

append_idx <- match(rownames(existing), sampleMap(mae)[["colname"]])
leftovers <- leftovers[append_idx, , drop = FALSE]

Changes

  • R/MultiAssayExperiment-helpers.R: Fixed row ordering in getWithColData() append branch
  • tests/testthat/test-MultiAssayExperiment-helpers.R: Added regression test with mismatched row orders
  • DESCRIPTION: Version bump to 1.37.4

Testing

Regression test verifies that when experiment colData and sampleMap have different row orders, each sample correctly receives its associated patient's metadata from MAE colData.

Credit

Bug reported and diagnosed by James Bonaffini.

When mode=append, existing (experiment colData) and leftovers (MAE colData)
had incompatible row orderings, causing patient metadata to be assigned to
wrong samples. Fix uses sampleMap to properly align rows before cbind.
Reported by James Bonaffini. Includes regression test.
@LiNk-NY
Copy link
Copy Markdown
Collaborator

LiNk-NY commented Mar 28, 2026

Thanks Patrick and James for the fix ! 5388577

@LiNk-NY LiNk-NY closed this Mar 28, 2026
@jbonaffini
Copy link
Copy Markdown

Thanks @aboyoun for the writeup!

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