grunwaldlab / metacoder

Parsing, Manipulation, and Visualization of Metabarcoding/Taxonomic data
http://grunwaldlab.github.io/metacoder_documentation
Other
134 stars 28 forks source link

How to filter taxa in heat tree matrix? #320

Closed catherineel closed 2 years ago

catherineel commented 2 years ago

I previously used this script to generate a heat tree and it worked great, but there were so many nodes, I wanted to filter the taxa.

_set.seed(1) heat_tree_matrix(obj, data = "diff_table", node_size = n_obs, # n_obs is a function that calculates, in this case, the number of OTUs per taxon node_label = taxon_names, node_color = log2_median_ratio, # A column from obj$data$diff_table node_color_range = diverging_palette(), # The built-in palette for diverging data node_color_trans = "linear", # The default is scaled by circle area node_color_interval = c(-6, 6), # The range of log2_median_ratio to display edge_color_interval = c(-6, 6), # The range of log2_median_ratio to display node_size_axis_label = "Number of OTUs", node_color_axis_label = "Log2 ratio median proportions", layout = "davidson-harel", # The primary layout algorithm initial_layout = "reingold-tilford", # The layout algorithm that initializes node locations output_file = "differential_heattree.pdf") # Saves the plot as a pdf file

I tried to add this line in as I used it previously for the individual heat trees, but I get this error message:

_set.seed(1) obj %>% filter_taxa(grepl(pattern = "^[a-zA-Z]+$", taxon_names)) %>% # remove "odd" taxa filter_taxa(taxon_ranks == "g", supertaxa = TRUE, reassign_obs = FALSE) %>% heat_tree_matrix(obj, data = "diff_table", node_size = n_obs, # n_obs is a function that calculates, in this case, the number of OTUs per taxon node_label = taxon_names, node_color = log2_median_ratio, # A column from obj$data$diff_table node_color_range = diverging_palette(), # The built-in palette for diverging data node_color_trans = "linear", # The default is scaled by circle area node_color_interval = c(-6, 6), # The range of log2_median_ratio to display edge_color_interval = c(-6, 6), # The range of log2_median_ratio to display node_size_axis_label = "Number of OTUs", node_color_axis_label = "Log2 ratio median proportions", layout = "davidson-harel", # The primary layout algorithm initial_layout = "reingold-tilford", # The layout algorithm that initializes node locations output_file = "differential_heattree.pdf") # Saves the plot as a pdf file

Error: All pairs being compared should have one value per taxon (141). The following do not: C vs. N (431), C vs. D (431) ... N vs. DN (431), D vs. DN (431)

catherineel commented 2 years ago

Sorry figured it out in the end!