Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error pathway_errorbar "$<-.data.frame(*tmp*, "group", value = c(2L, 2L, 2L, 2L, : replacement has 20 rows, data has 1" #111

Open
raqxavier opened this issue Jun 26, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@raqxavier
Copy link

Good morning

I have one differentially abundant pathway between two groups and wish to plot it using the "pathway_errorbar":
p <- pathway_errorbar(abundance = kegg_abundance, daa_results_df = daa_annotated_sub_method_results_df, Group = metadata$state, p_values_threshold = 0.05, order = "pathway_class", select = NULL, ko_to_kegg = TRUE, p_value_bar = TRUE, colors = NULL, x_lab = "pathway_name")

ERROR
Error in $<-.data.frame(*tmp*, "group", value = c(2L, 2L, 2L, 2L, :
replacement has 20 rows, data has 1
In addition: Warning message:
In cbind(sample = colnames(sub_relative_abundance_mat), group = Group, :
number of rows of result is not a multiple of vector length (arg 2)

Environment Information:

  • Operating System: mac
  • R Version: R version 4.3.1
  • Package Version: 1.7.3
@raqxavier raqxavier added the bug Something isn't working label Jun 26, 2024
@Valencia-0302
Copy link

Did you resolve this issue? I am also using R on a Mac, and while it worked last year, I'm encountering this problem now when trying to regenerate the plots this year.

@raqxavier
Copy link
Author

I did solve it, but can't remember how and did not make notes in the script. Sorry!

@Liviacmg
Copy link

I am having the same error.

@cafferychen777
Copy link
Owner

Hi @raqxavier and others experiencing this issue,

Thank you for reporting this. The error occurs when attempting to create an error bar plot with only one significant pathway. This is a known limitation in the current implementation. Here are several solutions:

  1. Adjust p-value threshold to include more pathways:


p <- pathway_errorbar(
  abundance = kegg_abundance,
  daa_results_df = daa_annotated_sub_method_results_df,
  Group = metadata$state,
  p_values_threshold = 0.1,  # Higher threshold to include more pathways
  order = "pathway_class",
  select = NULL,
  ko_to_kegg = TRUE,
  p_value_bar = TRUE,
  colors = NULL,
  x_lab = "pathway_name"
)
  1. Manually select multiple pathways:


# Get significant pathway
sig_pathway <- daa_annotated_sub_method_results_df %>%
  filter(p_adjust < 0.05) %>%
  pull(feature)

# Add pathways with next lowest p-values
additional_pathways <- daa_annotated_sub_method_results_df %>%
  arrange(p_adjust) %>%
  slice(1:3) %>%  # Get top 3 pathways
  pull(feature)

# Plot with selected pathways
p <- pathway_errorbar(
  abundance = kegg_abundance,
  daa_results_df = daa_annotated_sub_method_results_df,
  Group = metadata$state,
  p_values_threshold = 1,  # High threshold to include all selected
  order = "pathway_class",
  select = additional_pathways,
  ko_to_kegg = TRUE,
  p_value_bar = TRUE,
  colors = NULL,
  x_lab = "pathway_name"
)
  1. Custom visualization for single pathway:


# For single pathway visualization
library(ggplot2)

# Get significant pathway data
sig_pathway_id <- daa_annotated_sub_method_results_df %>%
  filter(p_adjust < 0.05) %>%
  pull(feature)

sig_pathway_data <- data.frame(
  Abundance = as.numeric(kegg_abundance[sig_pathway_id,]),
  Group = metadata$state
)

# Create plot
p <- ggplot(sig_pathway_data, aes(x = Group, y = Abundance, fill = Group)) +
  geom_boxplot() +
  theme_bw() +
  ggtitle(sig_pathway_id) +
  theme(legend.position = "none")

Note: This limitation will be addressed in the next release to better handle single significant pathway cases. For now, please use one of these workarounds.

Please let me know if you need any clarification or encounter other issues!

Best regards,
Chen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants