The bioBakery help forum

Error running Maaslin2 about input

Hello, I have been trying to run an analysis using Maaslin2, running the program through R Studio.
but no matter how I try to tweak the data I keep getting errors that lead to no viable output. The error code looks like

Error in data.table::fread(input_data, header = TRUE, sep = “\t”) :
Input is empty or only contains BOM or terminal control characters

it same like incorrectness input,maybe i got wrong Data and Matedata File?
my code as follow

library(Maaslin2)

input_data ← system.file(

  • 'extdata','~/Desktop/R_Maaslin_1/otu_taxon_Genus.csv', package="Maaslin2")
    

input_metadata <-system.file(

  • 'extdata','~/Desktop/R_Maaslin_1/Metadata.csv', package="Maaslin2")
    

fit_data ← Maaslin2(

  • input_data, input_metadata, '~/Desktop/R_Maaslin_1', transform = "AST",
    
  • fixed_effects = c(‘Surfacefish’, ‘Cavefish’),
  • random_effects = c(‘site’, ‘subject’),
  • normalization = ‘NONE’,
  • standardize = FALSE)

and the Data and Matedata file as follow
Metadata.txt (745 Bytes) otu_taxon_Genus.txt (5.4 KB)

this is my first time to use Maaslin2,and i am really confuse, give me a hand please

Hi @CHY!

Thanks for your interest in MaAsLin 2. Also thank you for your files so I can replicate your errors. The first issue I had- which I think is what is throwing this error for you is that as the metadata as is attached cannot be opened in R. I tried running the command:

meta = read.delim("Metadata.txt", sep = "\t", row.names = 1) 

which errored because of ERROR: incomplete final line found by readTableHeader to fix this I opened the file with TextEdit and added a return at the end of the data. This allowed me to read the data into R. Another issue you might face is that two of the genera are repeated in your OTU file. If R ever tries to set those as row.names it will error out. I added _2 to the repeated genera to fix this minor bug. Once I was past those two minor fixes, I was able to successfully run MaAsLin with the code you included above, finding significant associations with one of your metadata variables.

Some very minor points were:

  • If you do not have repeated subjects (as it appears in the metadata file you sent) I wouldn’t include that as a random effect.
  • Finally, the sampleID’s between your files did not completely match- which will not throw an error in R but is worth a check. The dimensions of the data suggested they were the same but I lost ~10 samples while running MaAsLin.

I hope this helps!
Best,
Kelsey

Dear Kelsey_Thompson
Very grateful for your help,and i am really sorry as a newcomer for R and MaAsLin,it may be more helpful for me to learn and understand if you can provide all the successfully Code for me. Thanks you very much and sorry for bother you.

Hi @CHY,

No worries, R can be really hard at first!

Here is the code I used to run your data:

#Read in the OTU table - you will need to add the path to the file before the file name if it is not in your working directory 
#To read this one in you will need to change one of the g_Bacillus and one of the g_Serratia inputs to name + _2. That or you can sum those together to account for the total abundance of that genus in your sample. I am not sure how your table was created. Or you can get rid of the row.names =1. 
taxa = read.delim("otu_taxon_Genus.txt", sep = "\t", row.names = 1)
#I transpose the data out of habit
taxa = data.frame(t(taxa), check.names = F)

#Make sure you have fixed this file first so that there is a hard return at the end of the file. 
meta = read.delim("Metadata.txt", sep = "\t", row.names = 1) 
meta = data.frame(t(meta), check.names = F)

#Run MaAsLin- the output will appear in your working directory. 
library(Maaslin2)

fit_data  = Maaslin2(taxa, meta, "test_MaAsLin_forum", transform = "AST", 
                     fixed_effects = c('Surfacefish', 'Cavefish'),
                     random_effects = c('Subject'),
                     normalization = "NONE", 
                     standardize = F)

#This was a separte test using MaAsLin's default settings of a TSS (relative abundance) normalization followed by a LOG transformation. 
fit_data  = Maaslin2(taxa, meta, "test_MaAsLin_forum_default", 
                     fixed_effects = c("Surfacefish", "Cavefish"),
                     standardize = F)

I hope this helps!
Best,
Kelsey