Error "`x` and `y` must share the same src," when trying to include covariates in lm_meta

Dear all,

I already used MMUPHin with MetaPhlAn data but now while including HUMAnN pathways results and after reading a little more about the program I tried to include 2 covariates like “age”, “sex”. These covariates are not present in one study. I also tried MaAsLin2 to explore this results too.

When I try the tutorial with my own data…

pathway <- read_tsv("~/andres/HUMAnN/mmuphin_pathsX.tsv")
MeTa <- read_tsv("~/andres/HUMAnN/mmuphin_metadataX.csv")

pathway <- pathway %>% map_if(is.numeric, ~./sum(.)) %>% as.data.frame() %>% 
  column_to_rownames("ID") %>% as.matrix() # transform the data between 0-1
MeTa <- MeTa %>% column_to_rownames("ID") # with rownames

fit_lm_cov <- lm_meta(feature_abd = pathway,
                      batch = "study",
                      exposure = "response",
                      covariates = c("age", "sex"),
                      data = MeTa,
                      control = list(verbose = FALSE))

I got this error…

Error: `x` and `y` must share the same src, set `copy` = TRUE (may be slow).
Run `rlang::last_error()` to see where the error occurred.
Además: Warning messages:
1: In check_batch(df_batch[[batch]], min_n_batch = 2) :
  Batch variable is not a factor as provided and will be converted to one.
2: In lm_meta(feature_abd = pathway, batch = "study", exposure = "response",  :
  Covariate age is missing or has only one non-missing value in the following batches; will be excluded from model for these batches:
montes
3: In lm_meta(feature_abd = pathway, batch = "study", exposure = "response",  :
  Covariate sex is missing or has only one non-missing value in the following batches; will be excluded from model for these batches:
montes

Omitting the covariates…

fit_lm_cov <- lm_meta(feature_abd = pathway,
                      batch = "study",
                      exposure = "response",
                      data = MeTa,
                      control = list(verbose = FALSE))

This worked fine but with results only considering ‘response’ as a variable.

If I omit ‘montes’ from both files and rerun it and I got the same error

Error: `x` and `y` must share the same src, set `copy` = TRUE (may be slow).

I wonder if I can include these covariates in this step maybe I am missing something with the format. Thank you very much for your help

I am attaching the pathways file here
metadata = mmuphin_metadataX.csv (6.4 KB)

Best,

Andrés

Hi Andrés. This error has to do with how you have age encoded as A,B,C. Right now MMUPHin can’t handle fixed effects for categorical variables with more than two categories.

Tagging @sma to discuss the fix. I think if the control argument to lm_meta can take an entry for reference and then pass that to Maaslin2_wrapper, that should make it work. Will that be feasible Siyuan?

Thanks for your help Andrew, we coded the age as a discrete variable to use LEfSe first, we kept that in MaAsLin… then by inertia it got dragged as discrete into MMUPHin. I went back to the original numbers and the analysis run fine. Thanks for your help.

The package is great, maybe it is planned for future iterations like it was commented for MaAsLin but a follow up question or request would be to ask if there is a way to manually adjust the size of the ‘feature label’ in the forest .pdf plot, with pathways or broadly speaking HUMAnN data the large name is abbreviated since it can’t fit the page.

I don’t think exposing plot options to the user is planned at the moment. Probably the easiest thing for you to do is get your results into R, regenerate the figure using metafor::forest (the same function we use), then tweak it as necessary from there.

I will try that, thanks for the help again.

Hi all - yes, confirmed this appears to be an issue right now. I think Maaslin2 now requires multi-level variables to start with numerics to specify the reference level. In Andrés’ case the internal Maaslin2 runs are failing as a consequence. I might just throw the original error instead of having Maaslin2 fail silently and then report a nondescript one in its place. Thanks for bringing to my attention!

Just wanted to confirm that this has been implemented - MMUPHin will correctly relay Maaslin2’s reference level error message. The implementation should be available starting Bioc3.13.

Hi, I have a similar issue:
out ← MMUPHin::lm_meta(feature_abd = reads,
batch = “Batch”,
exposure = “Category”,
covariates = “X”,
data = metadata,
control = list(reference = c(“X,X1”), verbose = FALSE)

The X is a factor of 12 Categories, but even with the inclusion of the reference level the code is not working and I get the following error:
Error in auto_copy(): ! x and y must share the same src.
Is there a solution for this?

Hi - could you share your input files, please? Feel free to email me at syma.research@gmail.com. Thanks, Siyuan

Dear @sma I am trying this option (passing the reference as as part of the ‘control’ list) now with 2 other variables, both of them have more than 2 levels.

fit_lm_meta_taxSR <- lm_meta(feature_abd = metaphlanSR,
                         batch = "study",
                         exposure = "response",
                         covariates = c("sex", "age", "drug"),
                         data = MeTaSR, 
        control = list(verbose = FALSE, output = "MetaSR.XY", reference='drug,one'))

Inspired by this reply I also tried…

control = list(verbose = FALSE, output = "MetaXXX", 
                       fixed_effects = c("drug"), reference=c("drug,one"))

Here is the version I just re installed

 tools:::.BioC_version_associated_with_R_version()
[1] ‘3.13’
sessionInfo() ... MMUPHin_1.6.2 

My questions are (1) is how is the correct way to pass the reference as part of the control arguments (2) how do I pass multiple variables with their references?

Thanks for your help!

Andrés