Can not use QC_RLSC remove batch effect

i use MetaboAnalyst rmove batch effect,and my command is:
mSet ← PerformBatchCorrection(mSet,“QC_RLSC”,Method=“QC_RLSC”)
.
And issue says : Error in instrument_base_errors(loc ← eval_tidy(enquo(var), set_names(seq_along(vars), :
could not find function “instrument_base_errors”

how to fix it

Hi BaylorLyu,
Thanks for posting your questions. Can you please show me a reproducible example?
Cheers,
Zhiqiang Pang

Thanks for you reply. I use example data to learn how to remove batch effect, here is my code:

library(googledrive)
temp ← tempfile(fileext = “.csv”)
dl1 ← drive_download(
as_id(“1wEh2P81J_xFWJs5y4mq98-FsjxJ5wmBO”), path = temp, overwrite = TRUE)
library(googledrive);
temp ← tempfile(fileext = “.csv”)
dl2 ← drive_download(
as_id(“1KaBnSNRrirVPvpRxIubGCqpjX8asNeVA”), path = temp, overwrite = TRUE)
MetaboAna_Data ← t(read.csv(dl1$local_path,header = T));
colnames(MetaboAna_Data) ← MetaboAna_Data[1,];
MetaboAna_Data ← MetaboAna_Data[-1,];
MetaboAna_Data ← MetaboAna_Data[order(rownames(MetaboAna_Data)),];

meta_data ← read.csv(dl2$local_path);
meta_data ← meta_data[order(meta_data[,1]),c(1,2,4)];

Prepared_Data ← cbind(meta_data,MetaboAna_Data)[,-4];
write.csv(Prepared_Data,file = “IBD_BC_correction.csv”,row.names = F)
datapath ← paste0(getwd(),“/IBD_BC_correction.csv”)
library(“MetaboAnalystR”)
mSet<-InitDataObjects(“pktable”, “stat”, FALSE)
mSet<-Read.TextData(mSet, dl1$local_path, “col”, “disc”)
mSet<-SanityCheckData(mSet)
mSet<-ReplaceMin(mSet);
mSet<-FilterVariable(mSet, “iqr”, “F”, 25)
mSet<-PreparePrenormData(mSet)
mSet<-Normalization(mSet, “MedianNorm”, “LogNorm”, “NULL”, ratio=FALSE, ratioNum=20)
normalized_set ← mSet[[“dataSet”]][[“norm”]]
ordered_normalized_set ← normalized_set[order(row.names(normalized_set)), ]
meta_data ← read.csv(dl2$local_path)
new_normalized_set ← cbind(meta_data[,2:4], ordered_normalized_set)
write.csv(new_normalized_set,file = “new_normalized_set.csv”)
rm(mSet)
mSet ← InitDataObjects(“pktable”, “utils”, FALSE)
mSet ← Read.BatchDataTB(mSet, “new_normalized_set.csv”, “row”,missingEstimate = “rmean”)
mSet ← PerformBatchCorrection(mSet,“QC_RLSC”,Method=“QC_RLSC”)
[1] “Correcting using the QC_RLSC method !”
Error in instrument_base_errors(loc ← eval_tidy(enquo(var), set_names(seq_along(vars), :
could not find function “instrument_base_errors”
[1] “Your data or format is not valid! Please double check!”

This code can show issue again.

Hi BaylorLyu,

Thanks for sharing the code. The issue is related with the dependency on updated version of tidyselect package. I have fixed it. Please try it!

Cheers,
Zhiqiang Pang

Hello Zhiqiang,

Is there any way to remove batch effect through the website based MetaboAnalyst?

Many thanks

Zang

Hi Zhiqiang,

I run into a similar issue as BaylorLyu using the example data provided online.
[1] “Correcting with WaveICA…”
Error in log10(nrow(data), 2) :
2 arguments passed to ‘log10’ which requires 1
[1] “Your data or format is not valid! Please double check!”

Could you please tell me how to fix this issue?

Best,
Lisa

Hi Zang,Please find the Other Utilities Module from the Module select page, and then select “Batch Effect Correction” option from the dialog.
image

Hi Lisa, please give a reproduciable example for further checking. Read this post for troubleshooting.

Zhiqiang

Hi Lisa, I got your example from your email. I just fixed the issue. Now, you can try to reinstall the R pacakge and rerun it.
Here is the example code. I am post them just in case anyone else need it.

# Use Google API for data downloading peak feature data generated by FormatPeakList here.
# Please "install.packages('googledrive')" and "install.packages('httpuv')"first.
library(googledrive);
temp <- tempfile(fileext = ".csv")
# Please authorize your google account to access the data
dl1 <- drive_download(
  as_id("1wEh2P81J_xFWJs5y4mq98-FsjxJ5wmBO"), path = temp, overwrite =
    TRUE)

# Use Google API for data downloading meta data here.
# Please "install.packages('googledrive')" and "install.packages('httpuv')"first.
library(googledrive);
temp <- tempfile(fileext = ".csv")
# Please authorize your google account to access the data
dl2 <- drive_download(
  as_id("1KaBnSNRrirVPvpRxIubGCqpjX8asNeVA"), path = temp, overwrite =
    TRUE)

# Data preparation - read data in & transpose.
# This is a reference example for user to prepare their data.
# Please prepare your data table according to your data format.
MetaboAna_Data <- t(read.csv(dl1$local_path,header = T));
colnames(MetaboAna_Data) <- MetaboAna_Data[1,];
MetaboAna_Data <- MetaboAna_Data[-1,];
MetaboAna_Data <- MetaboAna_Data[order(rownames(MetaboAna_Data)),];

meta_data <- read.csv(dl2$local_path);
meta_data <- meta_data[order(meta_data[,1]),c(1,2,4)];

Prepared_Data <- cbind(meta_data,MetaboAna_Data)[,-4];
write.csv(Prepared_Data,file = "IBD_BC_correction.csv",row.names = F)
datapath <- paste0(getwd(),"/IBD_BC_correction.csv")

# Load the MetaboAnalystR package
library("MetaboAnalystR")

mSet<-InitDataObjects("pktable", "stat", FALSE)

mSet<-Read.TextData(mSet, dl1$local_path, "col", "disc")

mSet<-SanityCheckData(mSet)
mSet<-ReplaceMin(mSet);
mSet<-FilterVariable(mSet, "iqr", "F", 25)
mSet<-PreparePrenormData(mSet)
mSet<-Normalization(mSet, "MedianNorm", "LogNorm", "NULL", ratio=FALSE,
                    ratioNum=20)

### Data Orgnization
normalized_set <- mSet[["dataSet"]][["norm"]]
ordered_normalized_set <-
  normalized_set[order(row.names(normalized_set)), ]
### import metadata
meta_data <- read.csv(dl2$local_path)
new_normalized_set <- cbind(meta_data[,2:4], ordered_normalized_set);
write.csv(new_normalized_set,file =
            "NEW_new_normalized_set.csv") #changed it to my directory and read it in from there

#perform PCA
mSet <- PCA.Anal(mSet)
mSet <- PlotPCAPairSummary(mSet, "pca_pair_0_", "png", 72, width=NA, 5)
mSet <- PlotPCAScree(mSet, "pca_scree_0_", "png", 72, width=NA, 5)
mSet <- PlotPCA2DScore(mSet, "pca_score2d_0_", "png", 72, width=NA,
                       1,2,0.95,0,0)
rm(mSet)

mSet <- InitDataObjects("pktable", "utils", FALSE)

## we set samples in "row" according to the table format. If your samples are in column, set it as "col".
mSet <- Read.BatchDataTB(mSet,
                         "NEW_new_normalized_set.csv", "row",
                         missingEstimate = "lod") #read the file in from my directory and had to place a missingEstimate

mSet <- PerformBatchCorrection(mSet)

Hi Zhiqiang,

thank you for taking care of my problem. I’ve uninstalled and reinstalled MetaboAnalystR but still run into the same issue.
Do I have to reinstall any other packages as well?

Best,
Lisa

How did you re-install MetaboAnalystR? Did you try this command?
devtools::install_github("xia-lab/MetaboAnalystR", build = TRUE, build_vignettes = FALSE)

Hi Zhiqiang,

yes that’s what I did, but it seems like I also needed to reinstall “rlang”. Thank you for your support!

Best,
Lisa

Hi Lisa, Please carefully check if you have re-installed MetaboAnalystR successfully. The lastest commit of MetaboAnalystR has already been made to fix the issue.
image

Hi Zhiqiang,
thank you, the reinstallation worked fine, I just had to update “rlang” as well.
Thank you for your great support!