Amova output in csv format / accesible to R


I am currently developping a Sweave automatic report procedure for analysis of mothur output.
I would very much like to include the amova output into my R code and pass it on to LaTeX with xtable but it is impossible to read in the *.amova files into R.
However, because of the format of the output this is not possible at the moment.
I would propose a csv/tsv like output with the following format:

Group       Calculator    Among     Within   Total
g1-g2-gn   SS                 n            n          n
g1-g2-gn   df                 n           n           n
g1-g2-gn   MS                n           n           n
g1-g2-gn   Fs                                          n
g1-g2-gn   pvalue                                   n
g1-g2-gn   EER                                       n
g1-g2-gn   PwER                                    n

Here g1-g2-gn are the pairwise or experiment wise groups that are included in the design. EER and PwER concern the experiment wise error rate and the pairwise error rate. n refers to the number calculated.

Kind regards,

Frederiek - Maarten Kerckhof


It’s actually rather simple to read amova tables created by mothur to R. I created a small example function that reads just one table, and converts it to a more traditional ANOVA table. Note however that this reads just one table, e.g., the following one I took from mothur manual.

F-M Among Within Total
SS 2.10271 5.51471 7.61742
df 1 22 23
MS 2.10271 0.250669

Fs: 8.3884
p-value: <0.001*

The function is readAmova() (copy and paste the code below to your R console):

readAmova<-function(x) {
   d<-strsplit(readLines(x), "\t")
   m<-matrix(ncol=5, nrow=2, data=NA)
   rownames(m)<-c(gsub(" ", "", d[[1]][1]), "Residuals")
   colnames(m)<-c("Df", "Sum Sq", "Mean Sq", "F Value", "P Value")
   m[,4]<-as.numeric(c(d[[6]][2], " "))
   m[,5]<-as.numeric(c(substr(d[[7]], 11, 15), " "))

The usage is simple. Assuming the aforementioned table is in the file amova.txt, type in R:


The output then looks like this:

Df Sum.Sq Mean.Sq F.Value P.Value
F-M 1 2.10271 2.102710 8.3884 0.001
Residuals 22 5.51471 0.250669 NA NA

Or, if you want to output a Latex code for a similar table, use:


If you know R, you can probably modify the function to cope with several tables in the same file, also.

Best Regards,

Thank you so much for helping me with this.

Kind regards,