cafferychen777 / ggpicrust2

Make Picrust2 Output Analysis and Visualization Easier
https://cafferychen777.github.io/ggpicrust2/
Other
92 stars 11 forks source link

pathway_errorbar(): Error: Index out of bounds #44

Closed UrielEspinoza closed 8 months ago

UrielEspinoza commented 11 months ago

Hello @cafferychen777, I hope you are doing well. I have been trying ggpicrust2, which I find amazing. I started with the provided tutorials, and it worked correctly when plotting the results. However, I encountered a problem when analyzing my own results. Whenever I try to plot using either the suggested mode or step-by-step, it generates the following error: "Error: Index out of bounds," and the plot is not generated. I looked for past publications with the same error, but the solutions provided didn't work for me. I'm attaching the files used for the analysis: https://drive.google.com/drive/folders/1G48A4LPkMy6Vko7zLx3egtDtPVOdBEm-?usp=sharing

/library(readr)
library(ggpicrust2)
library(tibble)
library(tidyverse)
library(ggprism)
library(patchwork)

 data(metadata)
metadata <- read_delim("analisis/metadata4.tsv", delim = "\t", escape_double = FALSE, trim_ws = TRUE) 

kegg_abundance <- ko2kegg_abundance("analisis/pred_metagenome_unstrat.tsv") 

daa_results_df <- pathway_daa(abundance = kegg_abundance, metadata = metadata, group = "Grupos", daa_method = "LinDA", select = NULL, reference = NULL) 

daa_sub_method_results_df <- daa_results_df[daa_results_df$method == "LinDA", ]

daa_annotated_sub_method_results_df <- pathway_annotation(pathway = "KO", daa_results_df = daa_sub_method_results_df, ko_to_kegg = TRUE)
daa_annotated_sub_method_results_df <- daa_annotated_sub_method_results_df[!is.na(daa_annotated_sub_method_results_df$pathway_name),]

daa_annotated_sub_method_results_df$p_adjust <- round(daa_annotated_sub_method_results_df$p_adjust,5)

low_p_feature <- daa_annotated_sub_method_results_df[order(daa_annotated_sub_method_results_df$p_adjust), ]$feature[1:20]

p <- ggpicrust2::pathway_errorbar(
  abundance = kegg_abundance,
  daa_results_df = daa_annotated_sub_method_results_df,
  Group = metadata$Grupos,
  p_values_threshold = 0.05,
  order = "pathway_class",
  select = low_p_feature,
  ko_to_kegg = TRUE,
  p_value_bar = FALSE,
  colors = NULL,
  x_lab = "pathway_name"
)

Error result


> p <- ggpicrust2::pathway_errorbar(
+   abundance = kegg_abundance,
+   daa_results_df = daa_annotated_sub_method_results_df,
+   Group = metadata$Grupos,
+   p_values_threshold = 0.05,
+   order = "pathway_class",
+   select = low_p_feature,
+   ko_to_kegg = TRUE,
+   p_value_bar = FALSE,
+   colors = NULL,
+   x_lab = "pathway_name"
+ )
Error: Index out of bounds
cafferychen777 commented 11 months ago

Hello @UrielEspinoza ,

Thank you for using ggpicrust2, and I appreciate your kind words. I have reviewed the data and code you provided, and it seems that there is no issue with them. I suggest you try the following revised code:

library(tidyverse)
library(patchwork)
library(ggprism)

metadata <- read.delim("/Users/apple/Microbiome/ggpicrust2总/ggpicrust2测试/ggpicrust2_test/UrielEspinoza/metadata4.tsv") %>% as_tibble()

daa_annotated_sub_method_results_df <- read.delim("/Users/apple/Microbiome/ggpicrust2总/ggpicrust2测试/ggpicrust2_test/UrielEspinoza/daa_annotated_sub_method_results_df.tsv")

kegg_abundance <- read.delim("/Users/apple/Microbiome/ggpicrust2总/ggpicrust2测试/ggpicrust2_test/UrielEspinoza/kegg_abundance.tsv") %>% column_to_rownames("X")

low_p_feature <- daa_annotated_sub_method_results_df[order(daa_annotated_sub_method_results_df$p_adjust), ]$feature[1:20]

p <- ggpicrust2::pathway_errorbar(
  abundance = kegg_abundance,
  daa_results_df = daa_annotated_sub_method_results_df,
  Group = metadata$Grupos,
  p_values_threshold = 0.05,
  order = "pathway_class",
  select = low_p_feature,
  ko_to_kegg = TRUE,
  p_value_bar = TRUE,
  colors = NULL,
  x_lab = "pathway_name"
)

If the problem persists, you may try updating ggpicrust2 to the latest version. To do this, you can use the devtools package to install ggpicrust2 from GitHub:

# Install the devtools package if not already installed
# install.packages("devtools")

# Install ggpicrust2 from GitHub
devtools::install_github("cafferychen777/ggpicrust2")

Updating to the latest version may resolve any potential bugs that could be causing the "Index out of bound" error.

Please give this revised code a try, and if you still encounter any issues, feel free to let me know, and we can further investigate the problem. Happy coding!

Screenshot 2023-07-21 at 14 13 47
UrielEspinoza commented 11 months ago

Hello again, I still have the same problem, even after reinstalling everything on Windows since I had been working on Ubuntu. However, the same error persists.

cafferychen777 commented 11 months ago

Hello,

I'm sorry to hear that the issue persists even after trying the revised code and reinstalling everything on Windows. The problem could be related to the Ubuntu system, as it sometimes faces difficulties in updating to the latest version of ggpicrust2, which might cause unexpected issues.

I suggest trying ggpicrust2 on macOS or Windows instead. Alternatively, please verify that you have installed ggpicrust2 version 1.7.2 and all its required dependencies properly.

If you continue to encounter the same error, please double-check the ggpicrust2 version and dependencies and ensure they are all up-to-date and installed correctly. If you have any further questions or need additional assistance, feel free to let me know. I'll be glad to help you troubleshoot the issue further. Happy analyzing!

UrielEspinoza commented 11 months ago

I reinstalled ggpicrust2 (version 1.7.2) and all its updated dependencies. I have R version 4.3.1, and yet I'm still experiencing the same issue.

El vie, 21 jul 2023 a las 2:00, Caffery Yang @.***>) escribió:

Hello,

I'm sorry to hear that the issue persists even after trying the revised code and reinstalling everything on Windows. The problem could be related to the Ubuntu system, as it sometimes faces difficulties in updating to the latest version of ggpicrust2, which might cause unexpected issues.

I suggest trying ggpicrust2 on macOS or Windows instead. Alternatively, please verify that you have installed ggpicrust2 version 1.7.2 and all its required dependencies properly.

If you continue to encounter the same error, please double-check the ggpicrust2 version and dependencies and ensure they are all up-to-date and installed correctly. If you have any further questions or need additional assistance, feel free to let me know. I'll be glad to help you troubleshoot the issue further. Happy analyzing!

— Reply to this email directly, view it on GitHub https://github.com/cafferychen777/ggpicrust2/issues/44#issuecomment-1645246991, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXNQ3E3MULEQKJAWL7HLFTLXRJAJJANCNFSM6AAAAAA2SLPXXY . You are receiving this because you were mentioned.Message ID: @.***>

cafferychen777 commented 11 months ago

Hello @UrielEspinoza,

I have extensively tested the code and even set up a new environment, but I couldn't reproduce the issue you are facing. Therefore, it appears that this might not be an issue with the package itself. To further investigate, I suggest trying the code on a friend's computer or a different machine to see if the problem persists.

As for my sessionInfo, here are the details:

sessionInfo()
R version 4.2.2 (2022-10-31)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS 14.0

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
 [1] ggpicrust2_1.7.2 ggprism_1.0.4    patchwork_1.1.2  lubridate_1.9.2  forcats_1.0.0    stringr_1.5.0   
 [7] dplyr_1.1.2      purrr_1.0.1      readr_2.1.4      tidyr_1.3.0      tibble_3.2.1     ggplot2_3.4.2   
[13] tidyverse_2.0.0 

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.11        prettyunits_1.1.1  ps_1.7.5           rprojroot_2.0.3    digest_0.6.33      utf8_1.2.3        
 [7] mime_0.12          R6_2.5.1           plyr_1.8.8         pillar_1.9.0       rlang_1.1.1        curl_5.0.0        
[13] rstudioapi_0.14    miniUI_0.1.1.1     urlchecker_1.0.1   callr_3.7.3        desc_1.4.2         labeling_0.4.2    
[19] devtools_2.4.5     htmlwidgets_1.6.2  munsell_0.5.0      shiny_1.7.4        compiler_4.2.2     httpuv_1.6.9      
[25] pkgconfig_2.0.3    pkgbuild_1.4.0     htmltools_0.5.5    tidyselect_1.2.0   reshape_0.8.9      fansi_1.0.4       
[31] crayon_1.5.2       tzdb_0.4.0         withr_2.5.0        later_1.3.0        grid_4.2.2         xtable_1.8-4      
[37] GGally_2.1.2       gtable_0.3.3       lifecycle_1.0.3    magrittr_2.0.3     scales_1.2.1       cli_3.6.1         
[43] stringi_1.7.12     cachem_1.0.7       farver_2.1.1       renv_0.16.0        fs_1.6.3           promises_1.2.0.1  
[49] remotes_2.4.2      ellipsis_0.3.2     generics_0.1.3     vctrs_0.6.3        RColorBrewer_1.1-3 tools_4.2.2       
[55] glue_1.6.2         hms_1.1.3          processx_3.8.2     pkgload_1.3.2      fastmap_1.1.1      timechange_0.2.0  
[61] colorspace_2.1-0   sessioninfo_1.2.2  memoise_2.0.1      usethis_2.1.6      profvis_0.3.7     

Please ensure that your R version and package versions match the ones I have provided. If you still encounter any issues, please don't hesitate to reach out. I'll be more than happy to assist you further. Thank you for your patience and cooperation.

Best regards,

Screenshot 2023-07-21 at 19 58 59
hugoeira commented 11 months ago

Hi guys,

I have exactly the same problem, anyone manage to fix it?

I managed to produce the plot if I turn off the error bar, but then it keeps only one of the groups

image

Kind regards, Hugo

cafferychen777 commented 11 months ago

Hi @hugoeira ,

Could you share your dataset? That's very important for me to find the bug.

Best regards, Chen Yang

hugoeira commented 11 months ago

Hi,

Did you get my email. I dont seem to be able to upload the files here.

Kind regards

cafferychen777 commented 11 months ago

Hello @hugoeira,

You can upload files to Google drive or send it to cafferychen7850@gmail.com.

Best regards,

cafferychen777 commented 11 months ago

Hello @hugoeira,

I found the problem. The S213 sample column is full of zeros so the code can't operate well.

You can use the following code.

library(ggpicrust2)
library(tibble)
library(patchwork)
library(ggprism)
library(ggh4x)
library(readr)
library(tibble)
library(tidyverse)
library(patchwork)
library(ggforce)
library(ggplotify)
library(grid)

daa_annotated_results_df <- readRDS("/Users/apple/Microbiome/ggpicrust2总/ggpicrust2测试/ggpicrust2_test/Eira Pereira/daa_anotated_filtered_kruskal.rds")
kegg_abundance <- readRDS("/Users/apple/Microbiome/ggpicrust2总/ggpicrust2测试/ggpicrust2_test/Eira Pereira/kegg_abundance.rds")
metadata <- readRDS("/Users/apple/Microbiome/ggpicrust2总/ggpicrust2测试/ggpicrust2_test/Eira Pereira/metadata1.rds")

kegg_abundance <- kegg_abundance[, -which(names(kegg_abundance) == "S213")]

metadata <- metadata %>% filter(sample_id != "S213")

p <- ggpicrust2::pathway_errorbar(
  abundance = kegg_abundance,
  daa_results_df = daa_annotated_results_df,
  Group = metadata$sampling_point,
  p_values_threshold = 0.05,
  order = "pathway_class",
  select = NULL,
  ko_to_kegg = TRUE,
  p_value_bar = TRUE,
  colors = NULL,
  x_lab = "pathway_name"
)

Best regards, Chen Yang

Screenshot 2023-07-25 at 20 29 37
hugoeira commented 11 months ago

Hi @cafferychen777,

You are a super star ;)

Thanks so much for your help.

Kind regards