The bioBakery help forum

Error running Maaslin2

Hello, I have been trying to run an analysis using Maaslin2, running the program through R Studio. I have no issues calling in the input data file (which is relative metatranscriptomic data per sample) and then the metadata (which includes, discrete, binary, and continuous variables) with NA where there is no data. The program itself starts (and the demo worked), 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 glm.fit(x = structure(numeric(0), .Dim = c(0L, 231L), .Dimnames = list( :
object ‘fit’ not found
In addition: Warning messages:
1: In glm.fit(x = numeric(0), y = numeric(0), weights = NULL, start = NULL, :
no observations informative at iteration 1
2: glm.fit: algorithm did not converge
3: In glm.fit(x = numeric(0), y = numeric(0), weights = NULL, start = NULL, :
no observations informative at iteration 1
4: glm.fit: algorithm did not converge

Edit: On readjusting the data frames, I was able to reduce the errors to:
Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels

And on review of the file, it seems for some reason it is reading the metadata file in, but it is taking the header as the ‘value’, i.e. not looking past the first line. I am unsure why this is the case, given it is a tab-delimitated format…

I presume it is an issue with how it is trying to compare the two input files, but I can’t seem to figure out the issue. Any help is much appreciated!

1 Like

Hi JML, thanks for reaching out! Based on the message you provided, I’d say one of two things is happening:

  1. As you suggested, Maaslin2 might not be reading in the input correctly. I’m guessing you’re providing the input metadata (parameter input_metadata) as a file path? Without looking at the file itself, I won’t be able to tell what’s causing Maaslin2 to treat the first row as values instead of headers. However you might attempt to fix this by reading in the metadata first in R as a data frame, using functions such as read.table. The correctly processed data frame object can then be provided as the input to Maaslin2, (instead of a file path).
  2. It could also be that you have a character column in your metadata has only one value, hence the “contrasts can be applied only to factors with 2 or more levels” error. I’d still say the first issue is more likely, but it might be helpful to eyeball your metadata just to check for this.
    Thanks!
    Siyuan

Thanks Siyuan, I’ve tried both file path and reading in the .tsv as a table, but it produces the same issue either way. I’ve tried to model my metadata to the files from the demo, so I’m still not sure the issue. The metadata and data are all continuous data, would that be the issue? Also I’ve tried to mess around with using fixed_effects, but doesn’t seem to rectify the issue. (Does it matter if the ID is pulled in as factor or num?) This is a sample of the metadata (variable names changed, but otherwise same format). Maybe I’m missing something, thank you!

ID a_b_1 a_b_2 a_b_3 a_b_4 a_b_5 a_b_6 a_b_7 a_b_8 a_b_9
101944 6.33 2.85 0.01 0.02 9.84 4.39 0.01 0.02 7.5
102191 7.68 3.77 0.01 0.01 10.35 5.05 0 0 8.2
102256 7.37 3.61 0.01 0.02 8.56 4.18 0.01 0.02 8.19
102708 NA NA NA NA 8.15 3.88 0.01 0.01 NA
102934 NA NA NA NA 6.39 3.08 0.01 0.02 NA
103088 9.01 4.13 0.03 0.06 10.61 4.85 0.03 0.06 9.17
105720 7.69 3.57 0.01 0.02 6.94 3.23 0.01 0.02 6.65
105722 7.13 3.62 0.03 0.05 10.5 5.29 0.03 0.05 8.31

Hi Jesus -
Thanks for providing the metadata sample - it’s very helpful! I tried using this on a toy abundance table, and was able to run Maaslin2 without errors. The metadata file and R code are attached. Maybe you could compare this versus your code to pin point where things might’ve broke?
If this does not solve the issue, it’d be great if you could provide a minimal reproducible example of the error, including R code and input files (with .txt/.tsv extensions). Feel free to mask away sensitive info or use toy data. For guidelines, refer to for example https://stackoverflow.com/help/minimal-reproducible-example.
Thanks!
Siyuan

library(Maaslin2)
input_metadata <- read.table("meta.txt", sep = "\t", row.names = 1, header = TRUE)
## Toy abundance table
input_data <- matrix(0.5, nrow = 2, ncol = nrow(input_metadata))
colnames(input_data) <- rownames(input_metadata)
## Maaslin2 runs without error
fit_Maaslin2 <- Maaslin2(input_data = input_data, input_metadata = input_metadata, output = "./")

meta.txt (454 Bytes)

I have the same issue. Do you know why? :thinking:

Hi there,
Did you try to run your data following Siyuan’s code? If yes, can you provide a minimal reproducible example of the error, including R code and input files (with .txt/.tsv extensions), so that we can try to recreate the issue on our end?

Best,
Kelsey