Problem with fgsea
0
0
Entering edit mode
Barista • 0
@e51ccd8d
Last seen 2.4 years ago
Netherlands

Hello everyone,

Back in October I performed fgsea analysis without problem, obtaining up/downregulated genesets. Now I am trying to do another analysis with fgsea, and I keep getting the same error, which I am unable to resolve. The error is:

"Error in names(res) <- *vtmp* : 'names' attribute [30] must be the same length as the vector [20]"

I have already checked a thousand times whether my ranked genelist has correct, non duplicated, non-missing names, which definitly is the case. Also have I tried multiple ways of importing the Hallmark genesets (first through msigdbr package in R en later by downloading the .gmt file), both which are not working. Furthermore, have I tried to update all packages, upgrading R to the newest version and also running my analysis of October again, which yielded me the same error.

Are other people also experiencing this error and if so, did you find a workaround? Any advice is greatly appreciated.

See below my code used and version number of R and related packages:

 #GSEA
    GSEA_ranks <- TT[,c(4,5,8)]
    GSEA_ranks$metric <- -log10(GSEA_ranks$PValue)/sign(GSEA_ranks$logFC)
    GSEA_ranks$SYMBOL <- GSEA_ranks$hgnc_symbol
    GSEA_ranks1 <- subset(GSEA_ranks, select = c("SYMBOL", "metric"))
    GSEA_ranks1 <- as.data.frame(GSEA_ranks1)

    GSEA_ranks2 <- GSEA_ranks1 %>% 
      select(SYMBOL, metric) %>% 
      na.omit() %>% 
      distinct() %>% 
      group_by(SYMBOL) %>% 
      summarize(metric=mean(metric))

    table(duplicated(GSEA_ranks2$SYMBOL))
    table(is.na(GSEA_ranks2$SYMBOL))
    summary(GSEA_ranks2$metric)

    #ordering the result
    GSEA_ranks2 <- GSEA_ranks2[order(GSEA_ranks2$metric, decreasing = T),]

    #creating ranked gene list
    ranks <- GSEA_ranks2$metric
    names(ranks) <- GSEA_ranks2$SYMBOL

    msig <- msigdbr(species = "human", category = "H")
    msigdbr_list <-  split(x = msig$gene_symbol, f = msig$gs_name)

    #Running fgsea algorithm:
    fgseaRes <- fgseaMultilevel(pathways = msigdbr_list, stats = ranks)

R version 4.1.3 (2022-03-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=Dutch_Netherlands.1252  LC_CTYPE=Dutch_Netherlands.1252    LC_MONETARY=Dutch_Netherlands.1252
[4] LC_NUMERIC=C                       LC_TIME=Dutch_Netherlands.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] msigdbr_7.4.1          data.table_1.14.2      fgsea_1.21.2           clusterProfiler_4.2.2  reshape2_1.4.4        
 [6] haven_2.4.3            EnhancedVolcano_1.12.0 ggrepel_0.9.1          readxl_1.3.1           gplots_3.1.1          
[11] RColorBrewer_1.1-2     forcats_0.5.1          stringr_1.4.0          purrr_0.3.4            readr_2.1.2           
[16] tidyr_1.2.0            tibble_3.1.6           ggplot2_3.3.5          tidyverse_1.3.1        dplyr_1.0.8           

loaded via a namespace (and not attached):
  [1] snow_0.4-4             shadowtext_0.1.1       backports_1.4.1        fastmatch_1.1-3        plyr_1.8.6            
  [6] igraph_1.2.11          lazyeval_0.2.2         splines_4.1.3          BiocParallel_1.28.3    GenomeInfoDb_1.30.1   
 [11] digest_0.6.29          yulab.utils_0.0.4      GOSemSim_2.20.0        viridis_0.6.2          GO.db_3.14.0          
 [16] fansi_1.0.2            magrittr_2.0.2         memoise_2.0.1          tzdb_0.2.0             Biostrings_2.62.0     
 [21] graphlayouts_0.8.0     modelr_0.1.8           extrafont_0.17         extrafontdb_1.0        enrichplot_1.14.2     
 [26] colorspace_2.0-3       blob_1.2.2             rvest_1.0.2            xfun_0.24              crayon_1.5.1          
 [31] RCurl_1.98-1.6         jsonlite_1.8.0         scatterpie_0.1.7       ape_5.6-2              glue_1.6.2            
 [36] polyclip_1.10-0        gtable_0.3.0           zlibbioc_1.40.0        XVector_0.34.0         proj4_1.0-11          
 [41] Rttf2pt1_1.3.10        BiocGenerics_0.40.0    maps_3.4.0             scales_1.1.1           DOSE_3.20.1           
 [46] DBI_1.1.2              Rcpp_1.0.8.3           viridisLite_0.4.0      gridGraphics_0.5-1     tidytree_0.3.9        
 [51] bit_4.0.4              stats4_4.1.3           httr_1.4.2             ellipsis_0.3.2         pkgconfig_2.0.3       
 [56] farver_2.1.0           dbplyr_2.1.1           utf8_1.2.2             ggplotify_0.1.0        tidyselect_1.1.2      
 [61] labeling_0.4.2         rlang_1.0.2            AnnotationDbi_1.56.2   munsell_0.5.0          cellranger_1.1.0      
 [66] tools_4.1.3            cachem_1.0.6           downloader_0.4         cli_3.2.0              generics_0.1.2        
 [71] RSQLite_2.2.11         broom_0.7.12           fastmap_1.1.0          ggtree_3.2.1           babelgene_21.4        
 [76] bit64_4.0.5            fs_1.5.2               tidygraph_1.2.0        caTools_1.18.2         KEGGREST_1.34.0       
 [81] ggraph_2.0.5           nlme_3.1-155           ash_1.0-15             ggrastr_1.0.1          aplot_0.1.2           
 [86] DO.db_2.9              xml2_1.3.3             compiler_4.1.3         rstudioapi_0.13        beeswarm_0.4.0        
 [91] png_0.1-7              reprex_2.0.1           treeio_1.18.1          tweenr_1.0.2           stringi_1.7.6         
 [96] ggalt_0.4.0            lattice_0.20-45        Matrix_1.4-1           vctrs_0.3.8            pillar_1.7.0          
[101] lifecycle_1.0.1        bitops_1.0-7           patchwork_1.1.1        qvalue_2.26.0          R6_2.5.1              
[106] KernSmooth_2.23-20     gridExtra_2.3          vipor_0.4.5            IRanges_2.28.0         MASS_7.3-56           
[111] gtools_3.9.2           assertthat_0.2.1       withr_2.5.0            S4Vectors_0.32.3       GenomeInfoDbData_1.2.7
[116] parallel_4.1.3         hms_1.1.1              grid_4.1.3             ggfun_0.0.5            ggforce_0.3.3         
[121] Biobase_2.54.0         lubridate_1.8.0        tinytex_0.35           ggbeeswarm_0.6.0      
fgsea • 2.5k views
ADD COMMENT
0
Entering edit mode

Without having access to your input data it is very difficult to help you. It would be best if you could come up with a reproducible example that results in this error. It is also not clear where exactly the error occurs.

Having said this, does the example code on the help page of fgseaMultilevel run properly? If so, then it is something specific to the way your input data is formatted. If not, then it may be related to fgsea itself. However, the example code runs fine on my machine so I doubt that this is the case (although not all installed packages on my system have the same version as on your system; so good to check it as well).

# from help page

data(examplePathways)
data(exampleRanks)
fgseaMultilevelRes <- fgseaMultilevel(examplePathways, exampleRanks, maxSize=500, eps=0)
ADD REPLY
0
Entering edit mode

Dear Guido,

I understand that it is hard to solve without a reproducible example. Running the fgsea example results in the same error:

> fgseaMultilevelRes <- fgseaMultilevel(examplePathways, exampleRanks, maxSize=500)
Error in names(res) <- `*vtmp*` : 
  'names' attribute [96] must be the same length as the vector [20]

In addition to some warnings which I havent copied in (those were minor warnings as I read in other posts).

Probably it seems related to the fgsea package or other packages. I will (again) try to re-install the package!

ADD REPLY
0
Entering edit mode

Mmm, this indeed suggests it is something specific to your installation. Two suggestions:

  • (re)start R, only load the library fgsea, and then only run the example fgsea code (3 llines of code). This ensures no 'hidden' files or environment variables are being used.
  • check that your Bioconductor installation is OK by running: BiocManager::valid().
ADD REPLY
0
Entering edit mode

Tried everything on my own desktop. Now ran fgsea analysis on another PC without a problem. So I still dont really know where the problem is, but at least it is working by now. Thanks for your help!

ADD REPLY
0
Entering edit mode

Can you run traceback() functions just after the error appears and paste its output here?

ADD REPLY
0
Entering edit mode

Is the error being thrown by the names() function call, which is reflective of a problem independent of fGSEA. Can you share the output of:

str(GSEA_ranks2)
str(GSEA_ranks2$metric)
str(GSEA_ranks2$SYMBOL)
ADD REPLY
0
Entering edit mode

Dear Kevin,

Hereby the output:

> str(GSEA_ranks2$SYMBOL)
 chr [1:11842] "A4GALT" "AAAS" "AACS" "AAGAB" "AAK1" "AAMDC" "AAMP" "AAR2" "AARS1" "AARS2" "AASDH" "AASDHPPT" "AASS" "AATF" "AATK" ...
> str(GSEA_ranks2)
tibble [11,842 x 2] (S3: tbl_df/tbl/data.frame)
 $ SYMBOL: chr [1:11842] "A4GALT" "AAAS" "AACS" "AAGAB" ...
 $ metric: num [1:11842] -0.013 -1.203 -0.542 0.27 -1.364 ...
> str(GSEA_ranks2$metric)
 num [1:11842] -0.013 -1.203 -0.542 0.27 -1.364 ...
ADD REPLY

Login before adding your answer.

Traffic: 488 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6