Skip to content

heatmapEnrichment(): conversion from wide to long format is incorrect #160

@toobiwankenobi

Description

@toobiwankenobi

Hi @ncborcherding

I think (not 100% sure though) the conversion from wide to long format performed in the heatmapEnrichment() function is incorrect. I think transposing the data.frame is causing a problem.

long <- data.frame(
variable = rep(gene.set, each = nrow(agg)),
value = as.vector(t(agg[gene.set])),
group = rep(agg[[group.by]], times = length(gene.set)),
stringsAsFactors = FALSE
)

Example: The line as.vector(t(...)) returns all values of the first row. However, both variable and group are constructed assuming values are returned row-by-row for the first column etc. This leads to misalignment.

I would suggest switching to tidyr::pivot_longer() to avoid this problem (unless you want to keep base R) and make the conversion less error-prone.

If you want to keep base R, I think this chunk would fix the issue

long <- data.frame(
  variable = rep(gene.set, each = nrow(agg)),
  value = unlist(agg[gene.set], use.names = FALSE),
  group = rep(agg[["ident"]], times = length(gene.set)),
  stringsAsFactors = FALSE
)

Could you validate this?

Let me know what you would like to do. I can create a pull request once you confirm this.

Best wishes,
Tobi

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions