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

Choosing of selective metacyc pathway"ggpicrust2" #123

Open
kesava31 opened this issue Nov 7, 2024 · 1 comment
Open

Choosing of selective metacyc pathway"ggpicrust2" #123

kesava31 opened this issue Nov 7, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@kesava31
Copy link

kesava31 commented Nov 7, 2024

Hello
I am using ggpicrust2 in R from the PICRUST output files. I am interested to look some of the specific pathways from metacyc output. Below, code I used for plotting heatmap showing the pathways that are significant (< 0.05). I am wondering how to choose selective pathway to make heatmap that are interested for example (Aromatic compound degradation, Pathogenecity).
Could you help me in this regard.. How can I do it with the code. Thanks.

metacyc_daa_results_dfnew <- pathway_daa(abundance = metacyc_abundancenew %>% column_to_rownames("pathway"), metadata = metadata, group = "sample", daa_method = "LinDA")

metacyc_daa_annotated_results_dfnew <- pathway_annotation(pathway = "MetaCyc", daa_results_df = metacyc_daa_results_dfnew, ko_to_kegg = FALSE)

feature_with_p_0.05 <- metacyc_daa_results_dfnew %>% filter(p_adjust < 0.05)
pathway_heatmap(
abundance = metacyc_abundancenew %>%
right_join(
metacyc_daa_annotated_results_dfnew %>% select(all_of(c("feature","description"))),
by = c("pathway" = "feature")
) %>%
filter(pathway %in% feature_with_p_0.05$feature) %>%
select(-"pathway") %>%
column_to_rownames("description"),
metadata = metadata,
group = "sample"
)

@kesava31 kesava31 added the bug Something isn't working label Nov 7, 2024
@cafferychen777
Copy link
Owner

Hi there,

Thank you for your question about selecting specific MetaCyc pathways in ggpicrust2. I can help you modify your code to visualize only the pathways you're interested in (like aromatic compound degradation and pathogenicity). Here are several approaches:

  1. Using keyword filtering:
# Filter pathways by keywords
interested_pathways <- metacyc_daa_annotated_results_dfnew %>%
  filter(
    # Use regex to match descriptions you're interested in
    grepl("aromatic|degradation|pathogen", description, ignore.case = TRUE)
  )

# Create heatmap with filtered pathways
pathway_heatmap(
  abundance = metacyc_abundancenew %>%
    right_join(
      metacyc_daa_annotated_results_dfnew %>% 
        select(all_of(c("feature","description"))),
      by = c("pathway" = "feature")
    ) %>%
    # Filter to include only pathways of interest
    filter(pathway %in% interested_pathways$feature) %>%
    select(-"pathway") %>%
    column_to_rownames("description"),
  metadata = metadata,
  group = "sample"
)
  1. For more precise filtering, you can create a vector of specific keywords:
# Define keywords of interest
keywords <- c(
  "aromatic compound degradation",
  "pathogenicity",
  "virulence",
  # Add more keywords as needed...
)

# Filter using keywords
interested_pathways <- metacyc_daa_annotated_results_dfnew %>%
  filter(
    sapply(keywords, function(x) grepl(x, description, ignore.case = TRUE)) %>%
      apply(1, any)
  )
  1. If you know the specific pathway IDs, you can filter directly:
# Use specific pathway IDs
pathway_ids <- c("PWY-6261", "PWY-6126") # Replace with your pathways of interest

interested_pathways <- metacyc_daa_annotated_results_dfnew %>%
  filter(feature %in% pathway_ids)

Tips:

  • You can first view all pathway descriptions using View(metacyc_daa_annotated_results_dfnew) to help identify the ones you're interested in
  • The ignore.case = TRUE parameter ensures case-insensitive matching
  • Adjust the keywords or filtering criteria based on your specific needs
  • You can combine these methods as needed

Let me know if you need any clarification or have additional questions!

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

2 participants