YuLab-SMU / enrichplot

Visualization of Functional Enrichment Result
https://yulab-smu.top/biomedical-knowledge-mining-book/
234 stars 65 forks source link

`pairwise_termsim` error on `compareClusterResult` object when ID descriptions are duplicated #279

Closed j-andrews7 closed 4 months ago

j-andrews7 commented 4 months ago

When running pairwise_termsim on a compareClusterResult object, duplicated term descriptions for unique IDs are not properly handled in the fortify method. This can result in an error in rare cases where there are two significant terms with unique IDs with identical descriptions, e.g:

               ID                                                                    Description
144 R-HSA-9694676 Translation of Replicase and Assembly of the Replication Transcription Complex
161 R-HSA-9679504 Translation of Replicase and Assembly of the Replication Transcription Complex

The error:

Error in `levels<-`(`*tmp*`, value = as.character(levels)) : 
  factor level [260] is duplicated

The other fortify methods already handle this scenario gracefully, and it can be fixed for this instance easily by adding an additional unique call to the levels parameter in https://github.com/YuLab-SMU/enrichplot/blob/devel/R/method-fortify.R#L214

I will submit a PR addressing this shortly.