metacoder
metacoder copied to clipboard
heat_tree_matrix Error: Error in apply(layout_matrix, MARGIN = 2, function(x) all(is.na(x))) : dim(X) must have a positive length
Hi,
R-studio version: 1.3.1093 MetacodeR version: 0.3.4
First I want to complement you on this package - it is absolutely beautiful and we have published a paper already using your beautiful heat trees. I am now analyzing a different data-set and I keep running into the same error when trying to run the heat_tree_matrix command.
I have ran the following code in R:
parsed <- parse_tax_data(Genus2_summed, class_cols = c("Root", "Phylum", "Class", "Order", "Family", "Genus"))
parsed$data$otu_props <- calc_obs_props(parsed, data = "tax_data", cols = sample_data$Sample)
parsed_raw$data$tax_abund <- calc_taxon_abund(parsed, data = "otu_props", cols = sample_data$Sample)
Where sample_data is a df with: sample_data$Sample = names of my samples (column names of my Genus2_summed after the Genus column) sample_data$CO2_factor = a blend of words 'Bottom' and Top' - like - rep("Bottom", 34) and rep("Top", 34).
#Making the diff_table
parsed_raw$data$diff_table <- compare_groups(parsed, data = "tax_abund", cols = sample_ids, groups = sample_data$CO2_factor)
Note: This makes diff_table w/out issue and I am able to access it via:
parsed$data$diff_table - and it has column names of: taxon_id, treatment_1, treatment_2, log2_median_ratio, median_diff, mean_diff, and wilcox_p_value
However, when I try to graph it, it wont graph no matter how many times I re-run the code or try different things:
#Graphing
parsed_raw %>% filter_taxa(taxon_names != "NA", supertaxa = TRUE) %>% heat_tree_matrix(data = "diff_table", node_size = n_obs, node_label = taxon_names, node_color = log2_median_ratio)
It gives me the following error:
Error in apply(layout_matrix, MARGIN = 2, function(x) all(is.na(x))) : dim(X) must have a positive length
I have tried to graph this way as well: `parsed_raw %>% filter_taxa(taxon_names != "NA", supertaxa = TRUE) %>% mutate_obs("diff_table", log2_median_ratio = ifelse(wilcox_p_value <= 0.05, log2_median_ratio, 0)) %>% heat_tree_matrix(data = "diff_table",
It still gives me the same error:
Error in apply(layout_matrix, MARGIN = 2, function(x) all(is.na(x))) : dim(X) must have a positive length
Note: If i run this code, it runs w/out issue at all and I get a nice heat tree
parsed %>% filter_taxa(taxon_names != "NA", supertaxa = TRUE) %>% heat_tree(node_size = n_obs, node_color = n_obs, node_label = taxon_names, node_label_max = 500, layout = "da", initial_layout = "re")
I am at a complete loss - any idea what could be causing this error?
Thank you very much for your help.
Hello, I have the exact same error while trying to use heat_tree_matrix `
obj$data$diff_table <- compare_groups(obj, data = "tax_abund",cols = samples$sample_id,groups = samples$type) Warning message: In wilcox.test.default(abund_1, abund_2) : cannot compute exact p-value with ties
heat_tree_matrix(obj, data = "diff_table", node_size = n_obs,node_label = taxon_names,node_color = obj$data$diff_table$log2_median_ratio,node_color_range = diverging_palette(), node_color_trans = "linear",node_color_interval = c(-3, 3),edge_color_interval = c(-3, 3),node_size_axis_label = "Number of OTUs",node_color_axis_label = "Log2 ratio median proportions", layout = "davidson-harel",initial_layout = "reingold-tilford") Error in apply(layout_matrix, MARGIN = 2, function(x) all(is.na(x))) : dim(X) must have a positive length In addition: Warning messages: 1: In FUN(X[[i]], ...) : Could not apply layout 'davidson-harel' to subgraph. Using 'fruchterman-reingold' instead. 2: In FUN(X[[i]], ...) : Could not apply layout 'davidson-harel' to subgraph. Using 'fruchterman-reingold' instead. 3: In FUN(X[[i]], ...) : Could not apply layout 'davidson-harel' to subgraph. Using 'fruchterman-reingold' instead. 4: In FUN(X[[i]], ...) : Could not apply layout 'davidson-harel' to subgraph. Using 'fruchterman-reingold' instead.
` I have metacoder version 0.3.4.9002, taxa version 0.3.4.9001 and running R version 3.6
Please let me know if I need to send any more information to help solve this issue.
Thanks in anticipation,
sincerely, Dhwani Desai
PS:- the "heat_tree" command works without an issue, similar to the poster above.
I thought I would update and say that I have found the source of the error (for my data-set anyway). Seemsheat_tree_matrix will only plot if you have more than 2 groups to analyze (3+ groups) and will spit out this error if you have anything less. In my case, I only had 2 groups I am analyzing: "top" and "bottom". I switched to the function heat_tree instead and had zero issues graphing the heat tree.
@Transmystical, thanks!
@dhwanidesai, @Transmystical, Yes, it seems that heat_tree_matrix gives that error when you try to plot a single comparison. The matrix format does not really make sense for a single comparison, but I should add a descriptive error message. For a single comparison, I would recommend this technique to produce a single tree:
https://grunwaldlab.github.io/metacoder_documentation/example.html#comparing-two-treatmentsgroups
I will look into making this an automatic fallback when only a single comparison is given to heat_tree_matrix or I will add a better error message and let you know.
Thanks Zachary, I should have realized that a matrix with just two groups does not make much sense. My bad.
Thanks again for your response. As I said earlier, the heat_tree command works without a problem, so no worries.
regards, Dhwani
From: Zachary Foster @.> Sent: Tuesday, March 9, 2021 5:05 AM To: grunwaldlab/metacoder @.> Cc: Dhwani Desai [email protected]; Mention @.***> Subject: Re: [grunwaldlab/metacoder] heat_tree_matrix Error: Error in apply(layout_matrix, MARGIN = 2, function(x) all(is.na(x))) : dim(X) must have a positive length (#301)
CAUTION: The Sender of this email is not from within Dalhousie.
@Transmysticalhttps://github.com/Transmystical, thanks!
@dhwanidesaihttps://github.com/dhwanidesai, @Transmysticalhttps://github.com/Transmystical, Yes, it seems that heat_tree_matrix gives that error when you try to plot a single comparison. The matrix format does not really make sense for a single comparison, but I should add a descriptive error message. For a single comparison, I would recommend this technique to produce a single tree:
https://grunwaldlab.github.io/metacoder_documentation/example.html#comparing-two-treatmentsgroups
I will look into making this an automatic fallback when only a single comparison is given to heat_tree_matrix or I will add a better error message and let you know.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/grunwaldlab/metacoder/issues/301#issuecomment-793585393, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABYZBDIEPKWQM66YPPUECCDTCXQEZANCNFSM4YYZCN5A.