kevinmcgregor / mdine

11 stars 5 forks source link

mdine and phyloseq #3

Open rogarcia1992 opened 4 years ago

rogarcia1992 commented 4 years ago

Hi,

I have a phyloseq object containing otu_table, sam_data, and tax_table. Is there a way I can use this phyloseq object for example in model.matrix? I tried the following:

x <- model.matrix(~Sample_ID, data = myphyloseq_obj@sam_data)

However, it did not work. Any advice on how to do this? In your paper I read you used a phyloseq object.

Thanks!

kevinmcgregor commented 4 years ago

Hi,

Could you share the error you get when you try to run the model.matrix command?

Kevin

rogarcia1992 commented 4 years ago

Hi,

See error below:

x <- model.matrix(~ Sample_ID, data = FT_A_HIDF_DIDF@sam_data) Error in terms.formula(object, data = data) : 'data' argument is of the wrong type

kevinmcgregor commented 4 years ago

You'll have to convertFT_A_HIDF_DIDF@sam_data to a data frame before feeding it into the model.matrix() function.

rogarcia1992 commented 4 years ago

Hi,

Yes, I found a code that allows me to do that from a phyloseq object (see code below). The example data in the package (i.e. - Crohn) has the meta_data with covariates and otu_table merged or contained in the same obj. Is this the only way that it works or can I use a meta_data imported from excel to feed it to model.matrix() and then the otu_table obtained from a phyloseq obj for Y and Z? Thanks!

Extract abundance matrix from the phyloseq object

OTU1 = as(otu_table(physeq1), "matrix")

transpose if necessary

if(taxa_are_rows(physeq1)){OTU1 <- t(OTU1)}

Coerce to data.frame

OTUdf = as.data.frame(OTU1)