Skip to content

Commit

Permalink
johannes fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
philouail committed Sep 19, 2024
1 parent d81dda2 commit c2c055c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 40 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
27 changes: 14 additions & 13 deletions R/MetaboLightsParam.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,30 @@
#' 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
#' `sampleData` slot populated with data extracted from the selected assay.
#'
#' 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.
#'
Expand All @@ -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
#'
Expand Down
28 changes: 16 additions & 12 deletions R/MsExperiment.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
27 changes: 14 additions & 13 deletions man/MetaboLightsParam.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion vignettes/MsIO.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down

0 comments on commit c2c055c

Please sign in to comment.