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!

2 Likes

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
1 Like

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

Iā€™m also having this issue, the columns for the samples match, but this is my data file (gene families):

The error Iā€™m getting is

Error in FUN(newX[, i], ...) : invalid 'type' (character) of argument

I got the same errors when running my own datasets.I am able to run the demo datasets, but I am not lucky to get my own dataset working. Attached are my inputs. Would you please take a look? Much appreciated.
taxonomy4.tsv (22.4 KB)
meta4.tsv (582 Bytes)

Blockquote
Error in glm.fit(x = structure(numeric(0), dim = c(0L, 10L), 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

Blockquote

Thanks again.

Hi, I found this reply helped.