Closed tboonf closed 1 year ago
Hello,
I am not sure what is causing that. Can you supply an example of code and data that produces the error? Or is it random (the same data/code sometimes errors and sometimes not)?
+1
Unfortunately, I can't provide the data for this error as it's a client's confidential dataset. However, this error arose when I used a non-standard taxonomy (not a biological taxonomy, but still a taxonomy with 11 taxonomic levels).
The input dataset g2
has three columns: Tax
, containing the semicolon-delimited taxonomy, and two columns, "A"
and "B"
containing non-zero counts of abundances across two different categories, cls=c('A','B')
.
This same taxonomy can be plotted using heat_tree
when only plotting taxon_abund
but can't be plotted when comparing abundances across two categories.
Thanks for any insight into what might be causing this and how it might be fixed! I suspect the stackoverflow link above is a useful hint as that's what I started looking at, too.
obj2 <- parse_tax_data(g2,
class_cols = "Tax", # the column that contains taxonomic information
class_sep = ";", # The character used to separate taxa in the classification
class_regex = "^(.+)__(.+)$", # Regex identifying where the data for each taxon is
class_key = c(tax_rank = "info", # A key describing each regex capture group
tax_name = "taxon_name"))
obj2$data$otu_props <- calc_obs_props(obj2, "tax_data",cols = cls)
obj2$data$taxon_abund <- calc_taxon_abund(obj2,'otu_props',cols=cls)
obj2$data$diff_table <- compare_groups(obj2,'taxon_abund',cols=cls,groups=cls)
to_plot2 <- obj2 %>% filter_taxa(grepl(pattern = "^[a-zA-Z]+$", taxon_names),
reassign_obs = FALSE)
heat_tree_matrix(to_plot2,data='diff_table',
node_label = taxon_names,
node_size = log2_median_ratio,
node_color = log2_median_ratio,
node_color_range = diverging_palette(),
layout = "davidson-harel", initial_layout = 'reingold-tilford')
Sorry for the trouble, but I am not likely to be able to fix the error without reproducing it, especially since it is happening in ggplot2; the root cause could be in any of the code used to create the data that is plotted, which is a lot of code. Or it could be a rare bug in ggplot2. If anyone can come up with example data/code that results in the error, let me know.
Does it always happen for a given data set / code or is it random?
Hi @zachary-foster I think I have found the source of this error - some of my students have been hitting the same problem. The error occurs when trying to run heat_tree_matrix on data where there are only two levels to be compared. The metacoder script cannot set subgraph_width or subgraph_height if there are less than two comparisons. You can reproduce this error on the moving picture dataset by subsetting body.site to just gut and tongue, then attempting to plot body.site as differential heat trees.
Thanks for the report! I will try it out soon.
can confirm I just got the same error in the same situation (with two levels)
Has anyone found a fix or a workaround for this? Thanks!!
It should be working now. Use devtools::install_github
to install the development version to try.
This is what happens now:
library(metacoder)
#> This is metacoder version 0.3.5.3 (development version)
x <- parse_tax_data(hmp_otus, class_cols = "lineage", class_sep = ";",
class_key = c(tax_rank = "taxon_rank", tax_name = "taxon_name"),
class_regex = "^(.+)__(.+)$")
meta <- hmp_samples[hmp_samples$body_site %in% c('Nose', 'Throat'), ]
# Convert counts to proportions
x$data$otu_table <- calc_obs_props(x, data = "tax_data", cols = meta$sample_id)
#> Calculating proportions from counts for 20 columns for 1000 observations.
# Get per-taxon counts
x$data$tax_table <- calc_taxon_abund(x, data = "otu_table", cols = meta$sample_id)
#> Summing per-taxon counts from 20 columns for 174 taxa
# Calculate difference between treatments
x$data$diff_table <- compare_groups(x, data = "tax_table",
cols = meta$sample_id,
groups = meta$body_site)
# Plot results (might take a few minutes)
heat_tree_matrix(x,
data = "diff_table",
node_size = n_obs,
node_label = taxon_names,
node_color = 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")
Created on 2022-12-27 with reprex v2.0.2
Great, that works. Thank you!
@zachary-foster do you know what would cause Inf
for log2_median_ratio
? I think the presence of Inf
is causing colors not to render. or are the colors controlled by p value, so since there is no p < 0.05 no colors are shown?
Also, while a plot is produced, I still get the error message:
Error in grid.Call.graphics(C_setviewport, vp, TRUE) :
non-finite location and/or size for viewport
Reprex (sorry if it's an annoying one --)
remotes::install_github(Arcadia-Science/sourmashconsumr)
library(sourmashconsumr)
# load prelim input data
data(gut_taxonomy_annotate_df)
# create a metadata data frame
run_accessions <- c("SRR5936131", "SRR5947006", "SRR5935765",
"SRR5936197", "SRR5946923", "SRR5946920")
groups <- c("cd", "cd", "cd", "nonibd", "nonibd", "nonibd")
metadata <- data.frame(run_accessions = run_accessions, groups = groups)
# create metacoder object
gut_metacoder <- from_taxonomy_annotate_to_metacoder(taxonomy_annotate_df = gut_taxonomy_annotate_df,
intersect_bp_threshold = 50000,
tax_glom_level = "order",
groups = metadata)
# try new metacoder functionality
gut_metacoder$data$diff_table <- metacoder::compare_groups(gut_metacoder, data = "tax_abund",
cols = metadata$run_accessions,
groups = metadata$groups)
metacoder::heat_tree_matrix(gut_metacoder,
data = "diff_table",
node_size = n_obs,
node_label = taxon_names,
node_color = log2_median_ratio,
node_color_range = metacoder::diverging_palette(),
node_color_trans = "linear",
node_color_interval = c(-3, 3),
edge_color_interval = c(-3, 3),
node_size_axis_label = "Abund of taxonomic lineage",
node_color_axis_label = "Log2 ratio median proportions")
I get these warnings:
Warning: [38;5;232mRemoved 1 rows containing missing values (`geom_text()`).[39m
--
Warning: [38;5;232mRemoved 1 rows containing missing values (`geom_text()`).[39m
Warning: no non-missing arguments to min; returning Inf
Warning: no non-missing arguments to max; returning -Inf
Warning: no non-missing arguments to min; returning Inf
Warning: no non-missing arguments to max; returning -Inf
And this plot:
here's a preview of gut_metacoder$data$diff_table
:
taxon_id treatment_1 treatment_2 log2_median_ratio median_diff mean_diff wilcox_p_value
<chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl>
1 ab cd nonibd -0.0902 -77608 203109. 1
2 ac cd nonibd -0.261 -66 3359. 1
3 ad cd nonibd 0.101 44261 130415 0.7
4 ae cd nonibd 0.740 487 322. 0.7
5 af cd nonibd 0.866 132705 72990 0.7
6 ag cd nonibd -1.26 -4404 -3147. 0.2
7 ah cd nonibd -1.94 -5291 -4648 0.4
8 ai cd nonibd -Inf -218 -182 0.643
9 aj cd nonibd Inf 309 4001. 0.197
10 ak cd nonibd -0.261 -66 2766 1
Never mind, sorry to bother you! I just retried the above with a fresh R session and all works as indicated! Thank you so much for implementing this!
Hello, I have been receiving the following error message while running metacoder: "Error in grid.Call.graphics(C_setviewport, vp, TRUE) : non-finite location and/or size for viewport"
The puzzling part with this is that I am producing hundreds of images with metacoder, and only a dozen of analysis is giving that error message. Could this be due to the plotting aspect of metacoder like what is described for ggplot below?
https://stackoverflow.com/questions/55855545/how-can-i-solve-non-finite-location-and-or-size-for-viewport-error