diff --git a/DESCRIPTION b/DESCRIPTION index 7b05972..8c2398d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: MsIO Title: Serializing and restoring/importing mass spectrometry data objects -Version: 0.0.4 +Version: 0.0.5 Authors@R: c(person(given = "Johannes", family = "Rainer", email = "Johannes.Rainer@eurac.edu", diff --git a/R/MetaboLightsParam.R b/R/MetaboLightsParam.R index 3624357..a26674d 100644 --- a/R/MetaboLightsParam.R +++ b/R/MetaboLightsParam.R @@ -13,9 +13,9 @@ #' MetaboLights database (https://www.ebi.ac.uk/metabolights/index) by #' providing its unique study `mtblsId`. This function is particularly useful #' for importing metabolomics data into an `MsExperiment` object for further -#' analysis in the R environment. It is important to note that this method -#' can *only* be used for importing into an R environment via `readMsObject()`. -#' It cannot be used with the `saveMsObject()` method. +#' analysis in the R environment. +#' It is important to note that at present it is only possible to *read* +#' (import) data from MetaboLights, but not to *save* data to MetaboLights. #' #' If the study contains multiple assays, the user will be prompted to select #' which assay to load. The resulting `MsExperiment` object will include a @@ -23,19 +23,20 @@ #' #' Users can define how to filter this `sampleData` table by specifying a few #' parameters. The `keepOntology` parameter is set to `TRUE` by default, meaning -#' that all columns related to ontology are retained. If set to `FALSE`, they are +#' that all ontology-related columns are retained. If set to `FALSE`, they are #' removed. If ontology columns are kept, some column names may be duplicated and #' therefore numbered. The order of these columns is important, as it reflects the #' assay and sample information available in MetaboLights. #' #' The `keepProtocol` parameter is also set to `TRUE` by default, meaning that #' all columns related to protocols are kept. If set to `FALSE`, they are removed. -#' The `simplify` parameter, defaulted to `TRUE`, means that columns filled with -#' NAs or duplicated content will be removed. In the case of duplicated content, -#' only the first occurring column will be retained. +#' The `simplify` parameter (default `simplify = TRUE`) allows to define +#' whether duplicated columns or columns containing only missing values should +#' be removed. In the case of duplicated content, only the first occurring +#' column will be retained. #' -#' Further filtering can be performed using the `filePattern` slot of the -#' `MetaboLightsParam` object. The default for this slot is +#' Further filtering can be performed using the `filePattern` parameter of the +#' `MetaboLightsParam` object. The default for this parameter is #' `"mzML$|CDF$|cdf$|mzXML$"`, which corresponds to the supported raw data file #' types. #' @@ -53,23 +54,23 @@ #' types. #' #' @param keepOntology `logical(1)` Whether to keep columns related to ontology -#' in the `sampleData` slot. Default is `TRUE`. +#' in the `sampleData` parameter. Default is `TRUE`. #' #' @param keepProtocol `logical(1)` Whether to keep columns related to protocols -#' information in the `sampleData` slot. Default is `TRUE`. +#' information in the `sampleData` parameter. Default is `TRUE`. #' #' @param simplify `logical(1)` Whether to simplify the `sampleData` table by #' removing columns filled with NAs or duplicated content. Default is `TRUE`. #' #' @inheritParams saveMsObject #' -#' @returns An `MsExperiment` object with the `sampleData` slot populated using +#' @returns An `MsExperiment` object with the `sampleData` parameter populated using #' MetaboLights sample and assay information. The spectra data is represented #' as a `MsBackendMetabolights` object, generated from the raw data files #' associated with the selected assay of the specified MetaboLights ID #' (`mtblsId`). #' -#' @author Philippine Louail,Johannes Rainer +#' @author Philippine Louail #' #' @importFrom methods new #' diff --git a/R/MsExperiment.R b/R/MsExperiment.R index ef2e03e..9ecba6c 100644 --- a/R/MsExperiment.R +++ b/R/MsExperiment.R @@ -225,17 +225,21 @@ setMethod("readMsObject", ## Extract and read assay files assays <- all_fls[grepl("^a_", all_fls)] - if (length(param@assayName) > 0) selected_assay <- param@assayName - else if (length(assays) > 1 && length(param@assayName) == 0) { - cat("Multiple assay files found:\n") - selection <- menu(assays, - title = paste("Please choose the assay", - "file you want to use:")) - selected_assay <- assays[selection] - } else if (length(assays) == 1) { - selected_assay <- assays - cat("Only one assay file found:", selected_assay, "\n") + if (length(param@assayName) > 0) + selected_assay <- param@assayName + else { + if (length(assays) == 1) { + selected_assay <- assays + message("Only one assay file found:", selected_assay, "\n") + } else { + message("Multiple assay files found:\n") + selection <- menu(assays, + title = paste("Please choose the assay", + "file you want to use:")) + selected_assay <- assays[selection] + } } + assay_data <- read.table(paste0(pth, selected_assay), header = TRUE, sep = "\t", check.names = FALSE) @@ -267,8 +271,8 @@ setMethod("readMsObject", nme <- colnames(merged_data)[which(merged_data[1, ] == fl)] merged_data <- merged_data[grepl(param@filePattern, merged_data[, nme]), ] - - object@sampleData <- DataFrame(merged_data) + nme <- gsub(" ", "_", nme) #use concatenate instead ? + object@sampleData <- DataFrame(merged_data, check.names = FALSE) object <- MsExperiment::linkSampleData(object, with = paste0("sampleData.", nme, diff --git a/man/MetaboLightsParam.Rd b/man/MetaboLightsParam.Rd index 989d819..9f963b3 100644 --- a/man/MetaboLightsParam.Rd +++ b/man/MetaboLightsParam.Rd @@ -42,10 +42,10 @@ and file name or directory to/from which the data object should be exported/imported.} \item{keepOntology}{\code{logical(1)} Whether to keep columns related to ontology -in the \code{sampleData} slot. Default is \code{TRUE}.} +in the \code{sampleData} parameter. Default is \code{TRUE}.} \item{keepProtocol}{\code{logical(1)} Whether to keep columns related to protocols -information in the \code{sampleData} slot. Default is \code{TRUE}.} +information in the \code{sampleData} parameter. Default is \code{TRUE}.} \item{simplify}{\code{logical(1)} Whether to simplify the \code{sampleData} table by removing columns filled with NAs or duplicated content. Default is \code{TRUE}.} @@ -54,7 +54,7 @@ removing columns filled with NAs or duplicated content. Default is \code{TRUE}.} method for more information.} } \value{ -An \code{MsExperiment} object with the \code{sampleData} slot populated using +An \code{MsExperiment} object with the \code{sampleData} parameter populated using MetaboLights sample and assay information. The spectra data is represented as a \code{MsBackendMetabolights} object, generated from the raw data files associated with the selected assay of the specified MetaboLights ID @@ -66,9 +66,9 @@ allow users to load an \code{MsExperiment} object from a study in the MetaboLights database (https://www.ebi.ac.uk/metabolights/index) by providing its unique study \code{mtblsId}. This function is particularly useful for importing metabolomics data into an \code{MsExperiment} object for further -analysis in the R environment. It is important to note that this method -can \emph{only} be used for importing into an R environment via \code{readMsObject()}. -It cannot be used with the \code{saveMsObject()} method. +analysis in the R environment. +It is important to note that at present it is only possible to \emph{read} +(import) data from MetaboLights, but not to \emph{save} data to MetaboLights. If the study contains multiple assays, the user will be prompted to select which assay to load. The resulting \code{MsExperiment} object will include a @@ -76,19 +76,20 @@ which assay to load. The resulting \code{MsExperiment} object will include a Users can define how to filter this \code{sampleData} table by specifying a few parameters. The \code{keepOntology} parameter is set to \code{TRUE} by default, meaning -that all columns related to ontology are retained. If set to \code{FALSE}, they are +that all ontology-related columns are retained. If set to \code{FALSE}, they are removed. If ontology columns are kept, some column names may be duplicated and therefore numbered. The order of these columns is important, as it reflects the assay and sample information available in MetaboLights. The \code{keepProtocol} parameter is also set to \code{TRUE} by default, meaning that all columns related to protocols are kept. If set to \code{FALSE}, they are removed. -The \code{simplify} parameter, defaulted to \code{TRUE}, means that columns filled with -NAs or duplicated content will be removed. In the case of duplicated content, -only the first occurring column will be retained. +The \code{simplify} parameter (default \code{simplify = TRUE}) allows to define +whether duplicated columns or columns containing only missing values should +be removed. In the case of duplicated content, only the first occurring +column will be retained. -Further filtering can be performed using the \code{filePattern} slot of the -\code{MetaboLightsParam} object. The default for this slot is +Further filtering can be performed using the \code{filePattern} parameter of the +\code{MetaboLightsParam} object. The default for this parameter is \code{"mzML$|CDF$|cdf$|mzXML$"}, which corresponds to the supported raw data file types. } @@ -113,6 +114,6 @@ the MetaboLights database. } } \author{ -Philippine Louail,Johannes Rainer +Philippine Louail } \concept{MS object export and import formats} diff --git a/vignettes/MsIO.Rmd b/vignettes/MsIO.Rmd index 1ae6c76..e74b691 100644 --- a/vignettes/MsIO.Rmd +++ b/vignettes/MsIO.Rmd @@ -250,7 +250,6 @@ annotation information as a `DataFrame` from the *sample_data* subfolder: readObject(path = file.path(d, "sample_data")) ``` -# Loading data from *MetaboLights* # Loading data from *MetaboLights*