YuLab-SMU / MicrobiotaProcess

:microbe: A comprehensive R package for deep mining microbiome
https://www.sciencedirect.com/science/article/pii/S2666675823000164
171 stars 36 forks source link

How to make MPSE object? #60

Open paiboon-aut opened 2 years ago

paiboon-aut commented 2 years ago

Hi,

Would you mind to answer me the two questions from me?

  1. After I follow your scripts: how to convert phyloseq object to mpse?

    convert phyloseq object to mpse

    library(phyloseq)

    data(esophagus)

    esophagus

    mpse4 <- esophagus %>% as.MPSE()

The scripts are quite good. However, I still need help, "Do you have the scripts or tutorials to convert the results from USEARCH to phyloseq object?".

  1. After I tried to import my metadata (Abundance_test.txt) via "library(curatedMetagenomicData)" Abundance_test.txt to mpse object, I cannot import it as mpse object. Would you please provide me the scripts to make my data to mpse object?

Best regards, paiboon-aut

xiangpin commented 2 years ago
  1. "Do you have the scripts or tutorials to convert the results from USEARCH to phyloseq object?".

The phyloseq package provide import_usearch_uc function to parse the usearch table format ('.uc'). It will return a otu_table class. Then you can use MPSE to build a MPSE object.

library(phyloseq)
library(MicrobiotaProcess)
usearchfile <- system.file("extdata", "usearch.uc", package="phyloseq")
res %>% class()
mpse <- MPSE(assays=data.frame(res, check.names=FALSE))
mpse
# A MPSE-tibble (MPSE object) abstraction: 1,221 × 3
# OTU=37 | Samples=33 | Assays=Abundance | Taxonomy=NULL
   OTU           Sample Abundance
   <chr>         <chr>      <int>
 1 D1.393095     174337         0
 2 D10.5n.393082 174337         0
 3 D10.a.393084  174337         0
 4 D10.b.393074  174337         0
 5 D11.a.392963  174337         0
 6 D11.b.392956  174337         0
 7 D12.392988    174337         0
 8 D13.5n.393036 174337         0
 9 D13.a.393151  174337         0
10 D13.b.393109  174337         0
# … with 1,211 more rows
  1. After I tried to import my metadata (Abundance_test.txt) via "library(curatedMetagenomicData)"

The Abundance_test.txt provided by you does not seem to be the output of MetaPhlAn3 or MetaPhlAn2. The MicrobiotaProcess provided mp_import_metaphlan to parse the output of MetaPhlAn3 or MetaPhlAn2.

library(MicrobiotaProcess)
file1 <- system.file("extdata/MetaPhlAn", "metaphlan_test.txt", package="MicrobiotaProcess")
sample.file <- system.file("extdata/MetaPhlAn", "sample_test.txt", package="MicrobiotaProcess")
mpse1 <- mp_import_metaphlan(profile=file1, mapfilename=sample.file)
mpse1
# A MPSE-tibble (MPSE object) abstraction: 5,260 × 11
# OTU=263 | Samples=20 | Assays=Abundance | Taxonomy=Kingdom, Phylum, Class, Order, Family, Genus
   OTU      Sample Abundance group taxid Kingdom Phylum Class Order Family Genus
   <chr>    <chr>      <dbl> <chr> <chr> <chr>   <chr>  <chr> <chr> <chr>  <chr>
 1 s__Meth… GupDM…     0.596 testA 2157… k__Arc… p__Eu… c__M… o__M… f__Me… g__M…
 2 s__Acti… GupDM…     0     testA 2|20… k__Bac… p__Ac… c__A… o__A… f__Ac… g__A…
 3 s__Acti… GupDM…     0     testA 2|20… k__Bac… p__Ac… c__A… o__A… f__Ac… g__A…
 4 s__Acti… GupDM…     0     testA 2|20… k__Bac… p__Ac… c__A… o__A… f__Ac… g__A…
 5 s__Bifi… GupDM…     0.948 testA 2|20… k__Bac… p__Ac… c__A… o__B… f__Bi… g__B…
 6 s__Bifi… GupDM…     0     testA 2|20… k__Bac… p__Ac… c__A… o__B… f__Bi… g__B…
 7 s__Bifi… GupDM…     0     testA 2|20… k__Bac… p__Ac… c__A… o__B… f__Bi… g__B…
 8 s__Bifi… GupDM…     0     testA 2|20… k__Bac… p__Ac… c__A… o__B… f__Bi… g__B…
 9 s__Bifi… GupDM…     0     testA 2|20… k__Bac… p__Ac… c__A… o__B… f__Bi… g__B…
10 s__Bifi… GupDM…     0     testA 2|20… k__Bac… p__Ac… c__A… o__B… f__Bi… g__B…
# … with 5,250 more rows