leffj / mctoolsr

Microbial community analysis tools in R
http://leffj.github.io/mctoolsr/
20 stars 8 forks source link

Error with calc_pairwise_permanovas #33

Closed Gian77 closed 6 months ago

Gian77 commented 4 years ago

Can you help me with this? I am not sure why this is happening. Thanks

> mctoolsr::calc_pairwise_permanovas(t(otu_ITS), metadata_ITS, "Site")

Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : 
  contrasts can be applied only to factors with 2 or more levels

> str(metadata_ITS)
'data.frame':   72 obs. of  8 variables:
 $ barcodenumb: int  417 431 425 388 428 463 415 438 448 429 ...
 $ Site     : Factor w/ 4 levels "Ciba","Longjin",..: 3 3 4 1 4 2 3 4 4 4 ...
 $ Description: Factor w/ 72 levels "T10a-in","T10a-out",..: 63 65 71 35 68 24 50 2 8 67 ...
 $ is.neg     : logi  FALSE FALSE FALSE FALSE FALSE FALSE ...

There is no NA or NaN in the metadata or the otus files.

Gian

hhollandmoritz commented 4 years ago

It's hard to tell from just this output. But it looks like you might be using a metadata file that doesn't match with your otu table. You might want to check that the order of samples and the names of the samples match between the two.

Gian77 commented 4 years ago

Thanks, but rownames of the two objects match.

> identical(rownames(t(otu_ITS)), rownames(metadata_ITS))
[1] TRUE
Gian77 commented 4 years ago

It actually worked using OTUs as rows in the OTU dataset otus_ITS. So, basically you should not transpose the dm object (rows are OTUs, samples are columns) and the metadata_map (rows are samples, columns are variables). That wasn't specified in the function help. This is the opposite way how adonis works. Anyway, I am glad I have the test done. Thanks!

Gian

hhollandmoritz commented 4 years ago

Great! Glad it worked out. :)