Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The normalisation in getpcoa() function does not work #96

Open
fernando-aq opened this issue Jul 26, 2023 · 2 comments
Open

The normalisation in getpcoa() function does not work #96

fernando-aq opened this issue Jul 26, 2023 · 2 comments

Comments

@fernando-aq
Copy link

Hi, I tried to use

PCoA_res <-
get_pcoa(obj = ps_object, distmethod = "bray")

It worked well. But when I do

PCoA_res <-
get_pcoa(obj = ps_object, distmethod = "bray", method = "log")

It says:
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'object' in selecting a method for function 'otu_table': (subscript) logical subscript too long

@xiangpin
Copy link
Member

I suggest you use the newest MicrobiotaProcess. Because MicrobiotaProcess has a significant change to work with tidyverse ecosystem better. The newest tutorial is here. You can first use mp_decostand to normalize the Abundance, then perform the pcoa analysis. The following is an example.

> library(MicrobiotaProcess)
> data(mouse.time.mpse)
> mouse.time.mpse
# A MPSE-tibble (MPSE object) abstraction: 4,142 × 11
# OTU=218 | Samples=19 | Assays=Abundance | Taxonomy=Kingdom, Phylum, Class, Order, Family, Genus, Species
   OTU    Sample Abundance time  Kingdom Phylum Class Order Family Genus Species
   <chr>  <chr>      <int> <chr> <chr>   <chr>  <chr> <chr> <chr>  <chr> <chr>
 1 OTU_1  F3D0         579 Early k__Bac… p__Ba… c__B… o__B… f__Mu… g__u… s__un_…
 2 OTU_2  F3D0         345 Early k__Bac… p__Ba… c__B… o__B… f__Mu… g__u… s__un_…
 3 OTU_3  F3D0         449 Early k__Bac… p__Ba… c__B… o__B… f__Mu… g__u… s__un_…
 4 OTU_4  F3D0         430 Early k__Bac… p__Ba… c__B… o__B… f__Mu… g__u… s__un_…
 5 OTU_5  F3D0         154 Early k__Bac… p__Ba… c__B… o__B… f__Ba… g__B… s__un_…
 6 OTU_6  F3D0         470 Early k__Bac… p__Ba… c__B… o__B… f__Mu… g__u… s__un_…
 7 OTU_7  F3D0         282 Early k__Bac… p__Ba… c__B… o__B… f__Mu… g__u… s__un_…
 8 OTU_8  F3D0         184 Early k__Bac… p__Ba… c__B… o__B… f__Ri… g__A… s__un_…
 9 OTU_9  F3D0          45 Early k__Bac… p__Ba… c__B… o__B… f__Mu… g__u… s__un_…
10 OTU_10 F3D0         158 Early k__Bac… p__Ba… c__B… o__B… f__Mu… g__u… s__un_…
# ℹ 4,132 more rows
# ℹ Use `print(n = ...)` to see more rows

This is original Abundance stored in a MPSE object. If you has a phyloseq, you can use as.MPSE to convert it to MPSE.
Then you can use mp_decostand to normalize it. Here, I use the clr method, log, hellinger, total etc can also be
supported. Then the result was added to the MPSE by default.

> mouse.time.mpse %>% mp_decostand(.abundance=Abundance, method='clr', pseudocount=1)
# A MPSE-tibble (MPSE object) abstraction: 4,142 × 12
# OTU=218 | Samples=19 | Assays=Abundance, clr | Taxonomy=Kingdom, Phylum, Class, Order, Family, Genus, Species
   OTU    Sample Abundance   clr time  Kingdom   Phylum Class Order Family Genus
   <chr>  <chr>      <int> <dbl> <chr> <chr>     <chr>  <chr> <chr> <chr>  <chr>
 1 OTU_1  F3D0         579  4.72 Early k__Bacte… p__Ba… c__B… o__B… f__Mu… g__u…
 2 OTU_2  F3D0         345  4.20 Early k__Bacte… p__Ba… c__B… o__B… f__Mu… g__u…
 3 OTU_3  F3D0         449  4.47 Early k__Bacte… p__Ba… c__B… o__B… f__Mu… g__u…
 4 OTU_4  F3D0         430  4.42 Early k__Bacte… p__Ba… c__B… o__B… f__Mu… g__u…
 5 OTU_5  F3D0         154  3.40 Early k__Bacte… p__Ba… c__B… o__B… f__Ba… g__B…
 6 OTU_6  F3D0         470  4.51 Early k__Bacte… p__Ba… c__B… o__B… f__Mu… g__u…
 7 OTU_7  F3D0         282  4.00 Early k__Bacte… p__Ba… c__B… o__B… f__Mu… g__u…
 8 OTU_8  F3D0         184  3.58 Early k__Bacte… p__Ba… c__B… o__B… f__Ri… g__A…
 9 OTU_9  F3D0          45  2.19 Early k__Bacte… p__Ba… c__B… o__B… f__Mu… g__u…
10 OTU_10 F3D0         158  3.43 Early k__Bacte… p__Ba… c__B… o__B… f__Mu… g__u…
# ℹ 4,132 more rows
# ℹ 1 more variable: Species <chr>
# ℹ Use `print(n = ...)` to see more rows

Next, let's use the normalized to perform the pcoa analysis

mouse.time.mpse %>% 
   mp_decostand(.abundance=Abundance, method='clr', pseudocount=1) %>% # normalization
   mp_cal_pcoa(.abundance=clr, distmethod='euclidean') %>%  # perform the pcoa
   mp_adonis(.abundance=clr, .formula=~time, distmethod='euclidean', action='add') %>% # perform adonis
  {.  ->> mpse.clr.pcoa} %>% # Save to a new mpse
   mp_plot_ord(.group=time, show.sample=T, show.adonis=T) # visualization

捕获

@fernando-aq
Copy link
Author

Thank you so very much for your reply. I hope you are keep maintaining this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants