pathview error "negative length vectors are not allowed
0
0
Entering edit mode
@130e2703
Last seen 7 months ago
United States

Hi everyone,

I'm new to the pathview R package, and the whole bioinformatics, but have dissent experience with R.
I'm trying to create maps for different pathways using pathview::pathview(), and only in some of pathways (running the same code) I'm getting an error with "negative length vectors are not allowed".
For what I looked around it seems to be a problem with the dimensions of the dataset exceeding R limits. Has anyone found a way around this? As I said I'm new to pathview and I can't think of any loops around this.

Any help would be very appreciated!

Mauricio

##  Fold change matrix with gene ID as row names.
gene.m <- matrix(c(1,1,-1,-1,-1), ncol =1)
gene.IDs <- c("120661193", "120708446", "120705740", "120672880", "120690206")
rownames(gene.m) <- gene.IDs

## Plot metabolic map
pathview(gene.data = gene.m, pathway.id = "01200",
         species = "pvir", out.suffix = "Cmet1", kegg.native = T)

Warning: No annotation package for the species pvir, gene symbols not mapped!
Info: Working in directory C:/Users/mauri/Desktop/pathviewMaps
Info: Writing image file pvir01200.Cmet1.png
Info: some node width is different from others, and hence adjusted!
Error in array(col.rgb[, i], dim(node.rgb)[3:1]) : 
  negative length vectors are not allowed

sessionInfo( )
R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8  LC_CTYPE=English_United States.utf8    LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                           LC_TIME=English_United States.utf8    

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

other attached packages:
[1] ggalluvial_0.12.5   ggVennDiagram_1.2.3 cowplot_1.1.1       ggplot2_3.4.2       dplyr_1.1.2         pathview_1.37.1    

loaded via a namespace (and not attached):
 [1] Biobase_2.58.0         httr_1.4.6             pkgload_1.3.2          bit64_4.0.5            shiny_1.7.4           
 [6] stats4_4.2.2           blob_1.2.4             GenomeInfoDbData_1.2.9 remotes_2.4.2          sessioninfo_1.2.2     
[11] pillar_1.9.0           RSQLite_2.3.1          glue_1.6.2             digest_0.6.31          promises_1.2.0.1      
[16] XVector_0.38.0         RVenn_1.1.0            colorspace_2.0-3       htmltools_0.5.4        httpuv_1.6.7          
[21] XML_3.99-0.14          pkgconfig_2.0.3        devtools_2.4.5         zlibbioc_1.44.0        purrr_1.0.0           
[26] xtable_1.8-4           scales_1.2.1           processx_3.8.0         later_1.3.0            tibble_3.2.1          
[31] KEGGREST_1.38.0        generics_0.1.3         IRanges_2.32.0         usethis_2.1.6          ellipsis_0.3.2        
[36] cachem_1.0.6           withr_2.5.0            BiocGenerics_0.44.0    cli_3.5.0              magrittr_2.0.3        
[41] crayon_1.5.2           mime_0.12              memoise_2.0.1          ps_1.7.2               KEGGgraph_1.58.3      
[46] fs_1.5.2               fansi_1.0.3            pkgbuild_1.4.0         graph_1.76.0           profvis_0.3.7         
[51] tools_4.2.2            prettyunits_1.1.1      org.Hs.eg.db_3.16.0    lifecycle_1.0.3        stringr_1.5.0         
[56] S4Vectors_0.36.2       munsell_0.5.0          AnnotationDbi_1.60.2   callr_3.7.3            Biostrings_2.66.0     
[61] compiler_4.2.2         GenomeInfoDb_1.34.9    rlang_1.1.1            grid_4.2.2             RCurl_1.98-1.12       
[66] rstudioapi_0.14        htmlwidgets_1.6.0      miniUI_0.1.1.1         bitops_1.0-7           gtable_0.3.1          
[71] DBI_1.1.3              curl_4.3.3             R6_2.5.1               fastmap_1.1.0          bit_4.0.5             
[76] utf8_1.2.2             rprojroot_2.0.3        desc_1.4.2             Rgraphviz_2.42.0       stringi_1.7.8         
[81] Rcpp_1.0.9             vctrs_0.6.3            png_0.1-8              tidyselect_1.2.0       urlchecker_1.0.1
pathview kegg KEGG • 1.1k views
ADD COMMENT
0
Entering edit mode

You have raised an intriguing problem. I believe this is an issue specific for this pathway (i.e. 'Carbon metabolism'), but maybe also for other pathways; AFAIK this is likely caused by the way KEGG show/represent the graphical representation of this pathway in its corresponding KGML file.

If you for example check online the 'TCA Cycle' pathway on the KEGG website, you will see a so-called native KEGG map in which circles are connected by arrows. In this particular map the circles are metabolites, and the (black) arrows represent the genes coding for the enzymes/proteins that catalyze the reaction. For each arrow there is a box that shows the actual EC identifier (or name) of the corresponding gene/protein. Note that not all genes have been annotated for your organism (these are the white boxes). AFAIK, all these information, including the position on the map of the boxes, direction of arrows, etc, is stored in the KGML file. Note that for this pathway switchgrass-specific expression data can be overlaid on the native KEGG representation (see below).

If you then view online the (your) 'Carbon metabolism' pathway, you will see a native KEGG map in which circles are connected by arrows, but the boxes are missing. The EC identifier of the corresponding gene(s) is only visible if you mouse over the green arrows.

Thus, since there are no boxes present in the native KEGG view of the 'Carbon metabolism' pathway, it seems to me that information on their position on the map is absent in the KGML file. As a consequence, pathview isn't able to visualize/overlay the gene expression data on the native KEGG representation. I believe that is the reason you got that rather cryptic error.

But... somehow this isn't the full story, because if you check the 'Biosynthesis of amino acids' pathway, you will see a similar representation as the 'Carbon metabolism' pathway (i.e. no boxes present). When you try to visualize expression data using default settings, you get the same error as for the 'Carbon metabolism' pathway'. Yet, if you set the argument same.layer = FALSE (default: same.layer = TRUE), somehow a native KEGG representation of the map is exported (as png), on which (part of?) the expression data is overlaid. Admittedly, it is not a nice picture.

To make it even more complex: if you would set kegg.native = FALSE (default: kegg.native = TRUE), then a so-called de novo network-representation of the pathway is exported (as PDF) on which the expression data is overlaid. This works for the 'Carbon metabolism' pathway, because it is now a network representation of the map, in which the nodes and edges do not have a fixed spatial position (as they rather have on the native KEGG map). Unfortunately, the layout of the network isn't nice, and AFAIK it can not be improved by e.g. exporting the resulting network to Cytoscape. So in the end, this network-representation may not be of much value...

So, in the end I don't know how to solve your problem...

See post below for some code and pictures.

ADD REPLY
0
Entering edit mode

Post 2; with some example code + graphs to illustrate the points raised above.

> ##  Fold change matrix with gene ID as row names.
> gene.m <- matrix(c(1,1,-1,-1,-1,1,-1,1,-1), ncol =1)
>  
> gene.IDs <- c("120643854", "120664875", "120641311",  ## 3 random gene present in 'Carbon metabolism' (01200)
+               "120652969", "120642702", "120649378",  ## 3 random gene present in 'TCA Cycle' (00020)
+               "120652159", "120673506", "120666371")  ## 3 random gene present in 'Biosynthesis of amino acids' (01230)
> rownames(gene.m) <- gene.IDs




> library(pathview)
> 
> ## visualize TCA cycle as native KEGG map; WORKS!
> pathview(gene.data = gene.m, pathway.id = "00020",
+          species = "pvir", out.suffix = "Cmet1",
+          kegg.native = TRUE, same.layer = TRUE, min.nnodes=2)
Info: Downloading xml files for pvir00020, 1/1 pathways..
Info: Downloading png files for pvir00020, 1/1 pathways..
Warning: No annotation package for the species pvir, gene symbols not mapped!
Info: Working in directory E:/test
Info: Writing image file pvir00020.Cmet1.png
>

enter image description here

> ## visualize Carbon metabolism as native KEGG map; FAILS!
> pathview(gene.data = gene.m, pathway.id = "01200",
+          species = "pvir", out.suffix = "Cmet1",
+          kegg.native = TRUE, same.layer = TRUE, min.nnodes=2)
Info: Downloading xml files for pvir01200, 1/1 pathways..
Info: Downloading png files for pvir01200, 1/1 pathways..
Warning: No annotation package for the species pvir, gene symbols not mapped!
Info: Working in directory E:/test
Info: Writing image file pvir01200.Cmet1.png
Info: some node width is different from others, and hence adjusted!
Error in array(col.rgb[, i], dim(node.rgb)[3:1]) : 
  negative length vectors are not allowed
>

>
> ## visualize Biosynthesis of amino acids as native KEGG map; FAILS (with same error)
> pathview(gene.data = gene.m, pathway.id = "01230",
+          species = "pvir", out.suffix = "Cmet1",
+          kegg.native = TRUE, same.layer = TRUE, min.nnodes=2)
Info: Downloading xml files for pvir01230, 1/1 pathways..
Info: Downloading png files for pvir01230, 1/1 pathways..
Warning: No annotation package for the species pvir, gene symbols not mapped!
Info: Working in directory E:/000test
Info: Writing image file pvir01230.Cmet1.png
Info: some node width is different from others, and hence adjusted!
Error in array(col.rgb[, i], dim(node.rgb)[3:1]) : 
  negative length vectors are not allowed

>
>
> ## but WORKS whith same.layer = FALSE
> pathview(gene.data = gene.m, pathway.id = "01230",
+          species = "pvir", out.suffix = "Cmet1",
+          kegg.native = TRUE, same.layer = FALSE, min.nnodes=2)
Warning: No annotation package for the species pvir, gene symbols not mapped!
Info: Working in directory E:/test
Info: Writing image file pvir01230.Cmet1.png
Info: some node width is different from others, and hence adjusted!
> 

enter image description here

> ## same.layer = FALSE also works with Carbon metabolism
> ## but somehow no genes are highlighted... ??
> pathview(gene.data = gene.m, pathway.id = "01200",
+          species = "pvir", out.suffix = "Cmet1",
+          kegg.native = TRUE, same.layer = FALSE, min.nnodes=2)
Warning: No annotation package for the species pvir, gene symbols not mapped!
Info: Working in directory E:/test
Info: Writing image file pvir01200.Cmet1.png
Info: some node width is different from others, and hence adjusted!
Info: some node width is different from others, and hence adjusted!
> 

enter image description here

> ## visualize Carbon metabolism as network; WORKS!
> ## but the layout is crappy and cannot be changed (since it is a PDF)...
> pathview(gene.data = gene.m, pathway.id = "01200",
+          species = "pvir", out.suffix = "Cmet1",
+          kegg.native = FALSE, same.layer = TRUE, min.nnodes=2)
Warning: No annotation package for the species pvir, gene symbols not mapped!
Info: Working in directory E:/test
Info: Writing image file pvir01200.Cmet1.pdf
> 

enter image description here

> sessionInfo()
R version 4.3.0 (2023-04-21 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default


locale:
[1] LC_COLLATE=English_United States.utf8 
[2] LC_CTYPE=English_United States.utf8   
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.utf8    

time zone: Europe/Amsterdam
tzcode source: internal

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

other attached packages:
[1] pathview_1.40.0

loaded via a namespace (and not attached):
 [1] crayon_1.5.2            vctrs_0.6.3             httr_1.4.7             
 [4] cli_3.6.1               rlang_1.1.1             DBI_1.1.3              
 [7] KEGGgraph_1.60.0        png_0.1-8               bit_4.0.5              
[10] S4Vectors_0.38.1        RCurl_1.98-1.12         Biostrings_2.68.1      
[13] XML_3.99-0.14           graph_1.78.0            org.Hs.eg.db_3.17.0    
[16] stats4_4.3.0            KEGGREST_1.40.1         Biobase_2.60.0         
[19] grid_4.3.0              fastmap_1.1.1           bitops_1.0-7           
[22] IRanges_2.34.1          GenomeInfoDb_1.36.3     memoise_2.0.1          
[25] compiler_4.3.0          RSQLite_2.3.1           blob_1.2.4             
[28] pkgconfig_2.0.3         XVector_0.40.0          Rgraphviz_2.44.0       
[31] R6_2.5.1                GenomeInfoDbData_1.2.10 AnnotationDbi_1.62.2   
[34] tools_4.3.0             bit64_4.0.5             zlibbioc_1.46.0        
[37] cachem_1.0.8            BiocGenerics_0.46.0    
> 
ADD REPLY
0
Entering edit mode

Just ran into this same issue with ko01232 (Nucleotide metabolism)

ADD REPLY

Login before adding your answer.

Traffic: 598 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