Comments (4)
Hello,
You can put in the name of any column in any table in you input column in place of n_obs
. This is why log2_median_ratio
works. To use total taxon abundance, you need a column in a per-taxon table that has that. To make that, you can use calc_taxon_abund
with a grouping variable that uses all samples, so that you only get one column back with a total. That column name can then be used like so:
library(metacoder)
#> This is metacoder verison 0.3.5 (stable)
# Get example data
x = parse_tax_data(hmp_otus, class_cols = "lineage", class_sep = ";",
class_key = c(tax_rank = "taxon_rank", tax_name = "taxon_name"),
class_regex = "^(.+)__(.+)$")
# Geting a total for all columns
x$data$tax_abund_total <- calc_taxon_abund(x, "tax_data", cols = hmp_samples$sample_id,
groups = rep("total_count", nrow(hmp_samples)))
#> Summing per-taxon counts from 50 columns in 1 groups for 174 taxa
# Plot total count
heat_tree(x, node_label = taxon_names, node_size = total_count, node_color = total_count)
Created on 2023-10-25 with reprex v2.0.2
from metacoder.
Hello Zachary,
Thanks for your quick answer!
I've tried to adapt the code to my parsed_phyloseq object but I still can't get it to work.
When i run the calc_taxon_abund() function the result is a tible with 183 rows but then the compare_groups() function returns a diff_table with 147 rows. This results in an error message saying there are 36 of 183 taxa have NAs for the "node_color" option when i want to plot the heat_tree.
Simon
library(phyloseq)
library(metacoder)
data(GlobalPatterns)
# Subsetting the dataset to keep only 2 sample types
GP_sub <- subset_samples(GlobalPatterns, (SampleType=='Ocean' | SampleType=='Soil'))
GP_sub <- prune_taxa(taxa_sums(GP_sub)>0, GP_sub)
# Agglomerating the dataset to Class
GP_sub_class_glom <- tax_glom(GP_sub,taxrank="Class",NArm = F)
meta_obj <- parse_phyloseq(GP_sub_class_glom)
meta_obj$data$tax_ab <- calc_taxon_abund(meta_obj, "otu_table", cols = meta_obj$data$sample_data$sample_id,
groups = rep("total_count", nrow(meta_obj$data$sample_data)))
meta_obj$data$diff_table <- compare_groups(meta_obj, data = "otu_table",
cols = meta_obj$data$sample_data$sample_id,
groups = meta_obj$data$sample_data$SampleType)
heat_tree(meta_obj,
node_size = total_count ,
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_axis_label = "Log2 ratio median proportions",
repel_labels = TRUE,
layout = "davidson-harel", # The primary layout algorithm
initial_layout = "reingold-tilford") # The layout algorithm that initializes node locations
from metacoder.
Hard to say for sure without being able to run the code with your data myself, but it looks like you are using the OTU table in compare_groups
instead of the taxon abundance table? This would compare OTU abundance amoung the groups, not the taxa, which causes attempts to plot data for each taxon to fail. Try this instead:
meta_obj$data$diff_table <- compare_groups(meta_obj, data = "tax_ab",
cols = meta_obj$data$sample_data$sample_id,
groups = meta_obj$data$sample_data$SampleType)
from metacoder.
Hi Zachary, sorry for the late answer.
The piece of code you sent did not work. :
meta_obj$data$tax_ab <- calc_taxon_abund(meta_obj, "otu_table",
cols = meta_obj$data$sample_data$sample_id,
groups = rep("total_count", nrow(meta_obj$data$sample_data)))
#Summing per-taxon counts from 6 columns in 1 groups for 183 taxa
meta_obj$data$diff_table <- compare_groups(meta_obj, data = "tax_ab",
cols = meta_obj$data$sample_data$sample_id,
groups = meta_obj$data$sample_data$SampleType)
#Error : The following 6 column(s) are not in "tax_ab":
#CL3, CC1, SV1, NP2, NP3, NP5
You should be able to run the code I provided as GlobalPatterns is a dataset from the phyloseq package.
from metacoder.
Related Issues (20)
- Can we use a uniform color scale in different figs? HOT 2
- italicize node labels? HOT 2
- ggtext compatibility HOT 2
- parse_phyloseq issues HOT 2
- primersearch_raw swaps position of forward and reverse primers. HOT 1
- Creation of different heat trees by treatments definded in sample data file
- calc_diff_abund_deseq2, linear variables and "design"? HOT 3
- Help with metacoder: Displaying a simplified heat tree for four taxonomic levels
- Keep only differentially abundant taxa in heat_tree() HOT 1
- Error in filter_taxa(x, per_taxon_max_change > 2.5, supertaxa = TRUE, : unused arguments HOT 3
- Run heat_tree with result of differential abundance analysis HOT 9
- Getting incorrectly formated results with zero_low_counts HOT 4
- how to get access to the Taxmap dataframe ? HOT 1
- Phyloseq heat tree doesn't see taxon_id or supertaxon_id when trying filter_taxa? HOT 9
- Problem with own dataset HOT 6
- Error: 'filter_taxa' is not an exported object from 'namespace:taxa' HOT 4
- Error in layout$fun(graph = list(1598, TRUE, c(0, 0, 0, 0, 0, 0, 0, 0, : At rinterface_extra.c:82 : The value 10.642051692927977 is not representable as an integer. Invalid value HOT 7
- Another Error in running alpha diversity analysis HOT 1
- Using ANCOM-BC2 for DA analysis
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from metacoder.