Open taekwonleo-yuhao opened 2 years ago
You can use mp_extract_tree
with specific tip.level
what you want.
> library(MicrobiotaProcess)
MicrobiotaProcess v1.7.8 For help:
https://github.com/YuLab-SMU/MicrobiotaProcess/issues
If you use MicrobiotaProcess in published research, please cite the
paper:
S Xu, L Zhan, W Tang, Z Dai, L Zhou, T Feng, M Chen, S Liu, X Fu, T Wu,
E Hu, G Yu. MicrobiotaProcess: A comprehensive R package for managing
and analyzing microbiome and other ecological data within the tidy
framework. 04 February 2022, PREPRINT (Version 1) available at Research
Square [https://doi.org/10.21203/rs.3.rs-1284357/v1]
This message can be suppressed by:
suppressPackageStartupMessages(library(MicrobiotaProcess))
> data(mouse.time.mpse)
> mouse.time.mpse %>% mp_rrarefy() %>% mp_diff_analysis(.abundance=RareAbundance, .group=time) %>% mp_extract_tree(tip.level=Genus)
The otutree is empty in the MPSE object!
'treedata' S4 object'.
...@ phylo:
Phylogenetic tree with 57 tips and 67 internal nodes.
Tip labels:
g__Bifidobacterium, g__Olsenella, g__Enterorhabdus, g__Bacteroides,
g__un_f__Muribaculaceae, g__Alistipes, ...
Node labels:
r__root, k__Bacteria, p__Actinobacteria, p__Bacteroidetes, p__Cyanobacteria,
p__Deinococcus-Thermus, ...
Rooted; no branch lengths.
with the following features available:
'nodeClass', 'nodeDepth', 'RareAbundanceBySample', 'LDAupper', 'LDAmean',
'LDAlower', 'Sign_time', 'pvalue', 'fdr'.
# The associated data tibble abstraction: 124 × 12
# The 'node', 'label' and 'isTip' are from the phylo tree.
node label isTip nodeClass nodeDepth RareAbundanceByS… LDAupper LDAmean
<int> <chr> <lgl> <chr> <dbl> <list> <dbl> <dbl>
1 1 g__Bifido… TRUE Genus 6 <tibble [19 × 4]> 3.39 3.36
2 2 g__Olsene… TRUE Genus 6 <tibble [19 × 4]> NA NA
3 3 g__Entero… TRUE Genus 6 <tibble [19 × 4]> NA NA
4 4 g__Bacter… TRUE Genus 6 <tibble [19 × 4]> NA NA
5 5 g__un_f__… TRUE Genus 6 <tibble [19 × 4]> 4.96 4.93
6 6 g__Alisti… TRUE Genus 6 <tibble [19 × 4]> 4.09 4.07
7 7 g__un_o__… TRUE Genus 6 <tibble [19 × 4]> NA NA
8 8 g__Deinoc… TRUE Genus 6 <tibble [19 × 4]> NA NA
9 9 g__Lactob… TRUE Genus 6 <tibble [19 × 4]> NA NA
10 10 g__Strept… TRUE Genus 6 <tibble [19 × 4]> NA NA
# … with 114 more rows, and 4 more variables: LDAlower <dbl>, Sign_time <chr>,
# pvalue <dbl>, fdr <dbl>
The result of mp_extract_tree
is a treedata
class, which can be processed and visualized by tidytree
, treeio
, ggtree
and ggtreeExtra
.
Thank you very much! Could you please explain what mp_rrarefy()
is used for?
mp_rrarefy
will generate one randomly rarefied community data, which will be added into assays
slot.
Dear Xiangpin,
I have another question about the LDA bar plotting. I tried to modified codes from your example and put the genus name outside of the LDA bar. And it works for most of the cases. But I found that the LDA bar will become so wide in some of my data sets that I can not find the right way to fix it.
Could you please give me some suggestions?
Thanks, Yuhao
Below are the codes I modified `p1 <- taxa.tree %>% ggtree( layout="radial", size = 0.3 ) + geom_point( data = td_filter(!isTip), fill="white", size=1, shape=21 )
p2 <- p1 + geom_hilight(
mapping = aes(subset = nodeClass == "Phylum",
node = node,
fill = label)
)
p3 <- p2 + ggnewscale::new_scale("fill") + geom_fruit( data = td_unnest(RareAbundanceBySample), geom = geom_star, mapping = aes( x = Treatment, size = RelRareAbundanceBySample, fill = Treatment, subset = RelRareAbundanceBySample > 0 ), starshape = 13, starstroke = 0.25, offset = 0.04, pwidth = 0.1, grid.params = list( linetype=2) ) + scale_size_continuous( name="Relative Abundance (%)", range = c(1, 3) ) + scale_fill_manual(values=c("#00A087FF", "#3C5488FF"))
p4 <- p3 + ggnewscale::new_scale("fill") + geom_fruit( geom = geom_col, mapping = aes( x = LDAmean, fill = Sign_Treatment, subset = !is.na(LDAmean) ), orientation = "y", offset = 0.1, pwidth = 0.4, axis.params = list(axis = "x", title = "Log10(LDA)", title.height = 0.01, title.size = 2, text.size = 1.8, vjust = 1), grid.params = list(linetype = 2) )
p5 <- p4 + ggnewscale::new_scale("size") + geom_point( data=td_filter(!is.na(fdr)), mapping = aes(size = -log10(fdr), fill = Sign_Treatment, ), shape = 21, ) + scale_size_continuous(range=c(1, 3)) + scale_fill_manual(values=c("#00A087FF", "#3C5488FF"))
p6 <- p5 + geom_tiplab(size=2, offset=4.2)
p6 <- p6 + theme( legend.key.height = unit(0.3, "cm"), legend.key.width = unit(0.3, "cm"), legend.spacing.y = unit(0.02, "cm"), legend.text = element_text(size = 7), legend.title = element_text(size = 9), plot.margin=margin(60,6,80,6) ) legend <- get_legend(p6) p7 <- p6 + theme(legend.position="none") p7`
Which version is ggtreeExtra
on your platform?
The following is my platfrom.
> packageVersion('ggtreeExtra')
[1] ‘1.4.2’
>
How about updating it via BiocManager::install('ggtreeExtra')
?
I updated ggtreeExtra to 1.4.2 version, but the problem is not fixed. Thanks.
How about removing the subset = !is.na(LDAmean)
in display the LDA of significant OTU
Yes! Problem fixed after I remove subset = !is.na(LDAmean)
. I am so curious 🤨 why it will affect the wide of Bar. This line should only remove the LDAmean = NA samples.
Dear developer,
I have a question about how to display the Taxonomy information in the tip labels of the taxa tree.
In my case, I convert the phyloseq object into MPSE format and try to identify biomarkers.
But I want to modify my tree tip labels as Genus. But I keep failing. Could you please show me how to modify them?
Thanks! Yuhao