Closed roopender-bioinfo closed 4 months ago
Thanks for you issue. Looking at your code, I notice that you used na_label = 'Unknown'
, however; you need to make sure to add the <tax>
and <rank>
tags (you can omit rank if include_rank = F
). Apologies for not making this clear in the documentation. If that doesn't resolve the issue, could you please provide a reproducible example with GlobalPatterns?
name_na_taxa(
ps_obj,
include_rank = F,
na_label = "Unknown <tax>"
)
I did and it's not working the Unknown taxa is only assigning to NA in species column.
ps_tmp <- name_na_taxa(top_nested$ps_obj,
include_rank = T,
na_label = "Unknown
However when I did this with Globalpatterns data it worked fine.
ps_tmp <- name_na_taxa(GlobalPatterns, include_rank = T, na_label = "Unknown
( )") view(tax_table(ps_tmp))
details of my data
carbom phyloseq-class experiment-level object otu_table() OTU Table: [ 9845 taxa and 22 samples ] sample_data() Sample Data: [ 22 samples by 12 sample variables ] tax_table() Taxonomy Table: [ 9845 taxa by 7 taxonomic ranks ] top_nested <- nested_top_taxa(carbom,
- top_tax_level = "Phylum",
- nested_tax_level = "Genus",
- n_top_taxa = 5,
- n_nested_taxa = 5)
Thanks for checking. If there is no issue with running the function on GlobalPatterns, then it means that the function is working as intended; however, your phyloseq object is not formatted as expected. The fact that you're getting "NA"
and "Unknown NA"
makes me think that there are no true NA
values in your table, but rather that they are strings that say "NA"
- could that be correct? Fantaxtic expects true NAs like in the image below. Can you check your phyloseq object, or provide a reproducible example?
PS When I run your code I get an error (see below), because you haven't added the <tax>
tag in your na_label. Are you sure you are using fantaxtic::name_na_taxa()
?
require("fantaxtic")
#> Loading required package: fantaxtic
require("magrittr")
#> Loading required package: magrittr
data(GlobalPatterns)
name_na_taxa(GlobalPatterns, na_label = "Unknown ()")
#> Error in name_na_taxa(GlobalPatterns, include_rank = F, na_label = "Unknown ()"): Error: include '<tax>' in the na_label
Created on 2024-07-10 by the reprex package (v2.0.1)
It worked! You were right it was "NA" string in my data that was causing the error. I transformed the NA to true NA values and It worked. Thanks buddy. The solution is here to transform you NA string values into real NA values.
install.packages("readxl") install.packages("dplyr") install.packages("writexl")
library(readxl) library(dplyr) library(writexl)
file_path <- "path_to_your_excel_file.xlsx" df <- read_excel(file_path)
df <- df %>% mutate(across(everything(), ~na_if(., "NA")))
head(df)
I used name_na_taxa function to assign all the taxa that are NA to their higher taxonomic rank. However, this function only worked at Species rank. All the NA in species were assigned as "Unknow", while it didn't work on the NA cells in genus, order, family or any other higher level. If a genus was NA than species was assigned unknown NA, while if genus is known than it will assign species as unknown "name of genus".
ps_tmp <- name_na_taxa(top_nested$ps_obj,
include_rank = F,
na_label = "Unknown ")
tax_table(ps_tmp) %>%
kable(format = "markdown")