mschecht
2/5/2018 - 11:39 AM

phyloseq matrix extractio

#############################################
# Take Phyloseq object and extract abundance
# matrix from it
#############################################

########################
phyloseq:::veganifyOTU()
########################

# make df of saple_ID (label) and Halpern impact (class)
halpern_impact <- TARA_srf_prok %>% 
  dplyr::select(sample_ID, global_cumul_impact_2013_all_layers_2013_5kms_mean) %>%
  rename(label = sample_ID, class = global_cumul_impact_2013_all_layers_2013_5kms_mean)

# extract abundance matrix from phyloseq object
otutable <- t(as(otu_table(unk_physeq_beta_css), "matrix"))

# convert to df
otutable <- base::as.data.frame(otutable)

# grab names 
names_otus <- names(otutable)

# make row names the "label" column
otutable$label <- base::row.names(otutable)

# Join with the class data
otutable <- otutable  %>% left_join(halpern_impact %>% dplyr::select(label, class))

# Select only label and class
class_impact <- otutable %>% dplyr::select(label, class)

# make label rownames
base::row.names(otutable) <- otutable$label

# remove label column
otutable$label <- NULL

# change name to something meaningful
unk_physeq_beta_css_df <- otutable

# Save it
save(unk_physeq_beta_css_df, file = '~/Downloads/unk_physeq_beta_css_df.RData')