Skip to content

Data Import for Phyloseq

otufile     <- "Dummy_OTU_table.txt" # mandatory - count table with annotation
mapfile     <- "Dummy_MapFile.txt"   # mandatory - meta/map file
treefile    <- "Dummy_OTU_tree.tre"  # optional  - tre files
refseqfile  <- "Dummy_OTU_ref.fa"    # optional  - fasta files

d <-
  import_qiime(
    otufilename  = otufile,
    mapfilename  = mapfile,
    treefilename = treefile, 
  )
d

Exploring Phyloseq Object

# Phyloseq object
summary(d)
mode(d)
# Summarize phyloseq object
microbiome::summarize_phyloseq(d)

Accessors

Components of a phyloseq object can be "extracted" using accessors. These accessor functions are available for direct interaction or used by function and/or packages.

ntaxa(d)         # number of OTUs
nsamples(d)      # number of samples

taxa_names(d)    # OTU labels
sample_names(d)  # sample id

taxa_sums(d)     # Count per OTU
sample_sums(d)   # Counts per sample - sequencing depth

rank_names(d) 

sample_variables(d) # Variable defined in mapfile

get_taxa(d)         # Count table
get_sample(d)       # Count table
get_variable(d)     # Meta info

Universal slot accessor function

Returns the component object specified by the argument slot or NULL if slot does not exist.

access(otu_table(d), "otu_table")
access(d, "tax_table")
access(d, "phy_tree")

Access Examples

Library size / sequencing depth sample_sums(d)[c("SB1","SB2")]

Total abundance of OTU(s) taxa_sums(d)[c("OTU1","OTU15")]

Counts per sample for (a) specific OTU(s) get_sample(d, i = "OTU1")

Counts per sample per OTU(s) get_taxa(d, i = c("SB2","SC2"))

Get values for variable get_variable(d, varName = c("pH","Temp")

Modify via Accessor

sample_data(d)$NewVariable <- ifelse(sample_data(d)$Temp >= 21, "High", "Low") sample_data(d) sample_variables(d)

otu_table(d)["OTU15", "SC2"] <- 0

tax_table(d)["OTU7", "Genus"] <- "Clostridiales"

Write phyloseq

write_phyloseq(pseq) 
write_phyloseq(pseq, "OTU")
write_phyloseq(pseq, "TAXONOMY")
write_phyloseq(pseq, "METADATA")