metacoder
metacoder copied to clipboard
Getting NA's for taxon_ranks
I'm getting only NA's in my taxon ranks after running parse_tax_data. I tried a couple of things for the regex, but still could not get it to work. Any ideas? Attached are my files and this is the code I'm using:
meta <-read_csv("metadata_metacode.csv") table<-read_csv("table_metacode.csv")
obj <- parse_tax_data(table, class_cols = "lineage", # 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"))
Thanks for including input data and code!
That is because you need to use tax_rank = "taxon_rank" instead of tax_rank = "info" so that the function knows those are taxon ranks instead of some other type of arbitrary per-taxon info.
library(readr)
library(metacoder)
meta <-read_csv("~/Downloads/metadata_metacode.csv")
table<-read_csv("~/Downloads/table_metacode.csv")
obj <- parse_tax_data(table,
class_cols = "lineage", # 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 = "taxon_rank", # A key describing each regex capture group
tax_name = "taxon_name"))
head(taxon_ranks(obj))
#> ab ac ad ae af ag
#> "r" "p" "p" "p" "p" "p"
Created on 2021-04-13 by the reprex package (v0.3.0)
That example you copied from was written before that was a feature. I will update it.
Many thanks, it worked great! One last question not related to it, but is there a way to make the node's size get bigger as the relative abundance increases instead of the number of OTUs?
Yes, you need to replace n_obs with the name of the column storing per-taxon relative abundance or some other variable storing that information. You can calculate per-taxon relative abundance with calc_taxon_abund. The plots on this page give an example of the idea:
https://grunwaldlab.github.io/metacoder_documentation/example.html
you can plot any per-taxon value for either color or size.